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 Oct. 21, 2002, by Dimitrie O. Paun.
29 * Unless otherwise noted, we belive this code to be complete, as per
30 * the specification mentioned above.
31 * If you discover missing features, or bugs, please note them below.
36 * -- Hot item handling, mouse hovering
37 * -- Workareas support
42 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
43 * -- Support CustonDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs.
44 * -- in LISTVIEW_AddGroupSelection, se whould send LVN_ODSTATECHANGED
45 * -- LVA_SNAPTOGRID not implemented
46 * -- LISTVIEW_ApproximateViewRect partially implemented
47 * -- LISTVIEW_[GS]etColumnOrderArray stubs
48 * -- LISTVIEW_GetNextItem is very inefficient
49 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
50 * -- LISTVIEW_SetIconSpacing is incomplete
51 * -- LISTVIEW_SortItems is broken
52 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
55 * -- in sorted mode, LISTVIEW_InsertItemT sorts the array,
56 * instead of inserting in the right spot
57 * -- we should keep an ordered array of coordinates in iconic mode
58 * this would allow to frame items (iterator_frameditems),
59 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
67 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
74 * -- LVS_NOSCROLL (see Q137520)
75 * -- LVS_SORTASCENDING, LVS_SORTDESCENDING
78 * -- LVS_EX_BORDERSELECT
79 * -- LVS_EX_CHECKBOXES
82 * -- LVS_EX_HEADERDRAGDROP
85 * -- LVS_EX_MULTIWORKAREAS
86 * -- LVS_EX_ONECLICKACTIVATE
88 * -- LVS_EX_SIMPLESELECT
89 * -- LVS_EX_SUBITEMIMAGES
90 * -- LVS_EX_TRACKSELECT
91 * -- LVS_EX_TWOCLICKACTIVATE
92 * -- LVS_EX_UNDERLINECOLD
93 * -- LVS_EX_UNDERLINEHOT
96 * -- LVN_BEGINDRAG, LVN_BEGINRDRAG
97 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
100 * -- LVN_MARQUEEBEGIN
102 * -- LVN_ODSTATECHANGED
107 * -- LVM_CANCELEDITLABEL
108 * -- LVM_CREATEDRAGIMAGE
109 * -- LVM_ENABLEGROUPVIEW
110 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
111 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
112 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
113 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
114 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
115 * -- LVM_GETINSERTMARKRECT
116 * -- LVM_GETNUMBEROFWORKAREAS
117 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
118 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
119 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
120 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
121 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
122 * -- LVM_GETTOOLTIPS, LVM_SETTOOLTIPS
123 * -- LVM_GETUNICODEFORMAT, LVM_SETUNICODEFORMAT
124 * -- LVM_GETVIEW, LVM_SETVIEW
125 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
126 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
127 * -- LVM_INSERTGROUPSORTED
128 * -- LVM_INSERTMARKHITTEST
129 * -- LVM_ISGROUPVIEWENABLED
130 * -- LVM_MAPIDTOINDEX, LVM_MAPINDEXTOID
132 * -- LVM_MOVEITEMTOGROUP
134 * -- LVM_SETTILEWIDTH
138 * Known differences in message stream from native control (not known if
139 * these differences cause problems):
140 * LVM_INSERTITEM issues LVM_SETITEMSTATE and LVM_SETITEM in certain cases.
141 * LVM_SETITEM does not always issue LVN_ITEMCHANGING/LVN_ITEMCHANGED.
142 * WM_CREATE does not issue WM_QUERYUISTATE and associated registry
143 * processing for "USEDOUBLECLICKTIME".
147 #include "wine/port.h"
158 #include "commctrl.h"
159 #include "comctl32.h"
161 #include "wine/debug.h"
162 #include "wine/unicode.h"
164 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
166 /* make sure you set this to 0 for production use! */
167 #define DEBUG_RANGES 1
169 typedef struct tagCOLUMN_INFO
171 RECT rcHeader
; /* tracks the header's rectangle */
172 int fmt
; /* same as LVCOLUMN.fmt */
175 typedef struct tagITEMHDR
179 } ITEMHDR
, *LPITEMHDR
;
181 typedef struct tagSUBITEM_INFO
187 typedef struct tagITEM_INFO
195 typedef struct tagRANGE
201 typedef struct tagRANGES
206 typedef struct tagITERATOR
215 typedef struct tagLISTVIEW_INFO
222 COLORREF clrTextBkDefault
;
223 HIMAGELIST himlNormal
;
224 HIMAGELIST himlSmall
;
225 HIMAGELIST himlState
;
230 RANGES selectionRanges
;
234 RECT rcList
; /* This rectangle is really the window
235 * client rectangle possibly reduced by the
236 * horizontal scroll bar and/or header - see
237 * LISTVIEW_UpdateSize. This rectangle offset
238 * by the LISTVIEW_GetOrigin value is in
239 * client coordinates */
248 INT ntmHeight
; /* Some cached metrics of the font used */
249 INT ntmAveCharWidth
; /* by the listview to draw items */
250 BOOL bRedraw
; /* Turns on/off repaints & invalidations */
251 BOOL bFirstPaint
; /* Flags if the control has never painted before */
252 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
256 DWORD dwStyle
; /* the cached window GWL_STYLE */
257 DWORD dwLvExStyle
; /* extended listview style */
258 INT nItemCount
; /* the number of items in the list */
259 HDPA hdpaItems
; /* array ITEM_INFO pointers */
260 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
261 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
262 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
263 POINT currIconPos
; /* this is the position next icon will be placed */
264 PFNLVCOMPARE pfnCompare
;
271 DWORD lastKeyPressTimestamp
;
273 INT nSearchParamLength
;
274 WCHAR szSearchParam
[ MAX_PATH
];
281 /* How many we debug buffer to allocate */
282 #define DEBUG_BUFFERS 20
283 /* The size of a single debug bbuffer */
284 #define DEBUG_BUFFER_SIZE 256
286 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
287 #define SB_INTERNAL -1
289 /* maximum size of a label */
290 #define DISP_TEXT_SIZE 512
292 /* padding for items in list and small icon display modes */
293 #define WIDTH_PADDING 12
295 /* padding for items in list, report and small icon display modes */
296 #define HEIGHT_PADDING 1
298 /* offset of items in report display mode */
299 #define REPORT_MARGINX 2
301 /* padding for icon in large icon display mode
302 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
303 * that HITTEST will see.
304 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
305 * ICON_TOP_PADDING - sum of the two above.
306 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
307 * LABEL_VERT_PADDING - between bottom of text and end of box
309 * ICON_LR_PADDING - additional width above icon size.
310 * ICON_LR_HALF - half of the above value
312 #define ICON_TOP_PADDING_NOTHITABLE 2
313 #define ICON_TOP_PADDING_HITABLE 2
314 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
315 #define ICON_BOTTOM_PADDING 4
316 #define LABEL_VERT_PADDING 7
317 #define ICON_LR_PADDING 16
318 #define ICON_LR_HALF (ICON_LR_PADDING/2)
320 /* default label width for items in list and small icon display modes */
321 #define DEFAULT_LABEL_WIDTH 40
323 /* default column width for items in list display mode */
324 #define DEFAULT_COLUMN_WIDTH 128
326 /* Size of "line" scroll for V & H scrolls */
327 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
329 /* Padding betwen image and label */
330 #define IMAGE_PADDING 2
332 /* Padding behind the label */
333 #define TRAILING_PADDING 5
335 /* Border for the icon caption */
336 #define CAPTION_BORDER 2
338 /* Standard DrawText flags */
339 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
340 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
341 #define LV_SL_DT_FLAGS (DT_TOP | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
343 /* The time in milliseconds to reset the search in the list */
344 #define KEY_DELAY 450
346 /* Dump the LISTVIEW_INFO structure to the debug channel */
347 #define LISTVIEW_DUMP(iP) do { \
348 TRACE("hwndSelf=%p, clrBk=0x%06lx, clrText=0x%06lx, clrTextBk=0x%06lx, ItemHeight=%d, ItemWidth=%d, Style=0x%08lx\n", \
349 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
350 iP->nItemHeight, iP->nItemWidth, infoPtr->dwStyle); \
351 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08lx, Focus=%d\n", \
352 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
353 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
354 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%ld, icSz.cy=%ld, icSp.cx=%ld, icSp.cy=%ld, notifyFmt=%d\n", \
355 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
356 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
357 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, debugrect(&iP->rcList)); \
362 * forward declarations
364 static BOOL
LISTVIEW_GetItemT(LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
365 static void LISTVIEW_GetItemBox(LISTVIEW_INFO
*, INT
, LPRECT
);
366 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO
*, INT
, LPPOINT
);
367 static BOOL
LISTVIEW_GetItemPosition(LISTVIEW_INFO
*, INT
, LPPOINT
);
368 static BOOL
LISTVIEW_GetItemRect(LISTVIEW_INFO
*, INT
, LPRECT
);
369 static INT
LISTVIEW_GetLabelWidth(LISTVIEW_INFO
*, INT
);
370 static void LISTVIEW_GetOrigin(LISTVIEW_INFO
*, LPPOINT
);
371 static BOOL
LISTVIEW_GetViewRect(LISTVIEW_INFO
*, LPRECT
);
372 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*, INT
);
373 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*, const LVITEMW
*, BOOL
);
374 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*);
375 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*, INT
);
376 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
377 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*, INT
, BOOL
);
378 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
379 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*, PFNLVCOMPARE
, LPARAM
);
380 static INT
LISTVIEW_GetStringWidthT(LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
381 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
);
382 static UINT
LISTVIEW_GetItemState(LISTVIEW_INFO
*, INT
, UINT
);
383 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
384 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
385 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
386 static INT
LISTVIEW_GetTopIndex(LISTVIEW_INFO
*);
387 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
388 static HWND
CreateEditLabelT(LISTVIEW_INFO
*, LPCWSTR
, DWORD
, INT
, INT
, INT
, INT
, BOOL
);
390 /******** Text handling functions *************************************/
392 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
393 * text string. The string may be ANSI or Unicode, in which case
394 * the boolean isW tells us the type of the string.
396 * The name of the function tell what type of strings it expects:
397 * W: Unicode, T: ANSI/Unicode - function of isW
400 static inline BOOL
is_textW(LPCWSTR text
)
402 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
405 static inline BOOL
is_textT(LPCWSTR text
, BOOL isW
)
407 /* we can ignore isW since LPSTR_TEXTCALLBACKW == LPSTR_TEXTCALLBACKA */
408 return is_textW(text
);
411 static inline int textlenT(LPCWSTR text
, BOOL isW
)
413 return !is_textT(text
, isW
) ? 0 :
414 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
417 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
420 if (isSrcW
) lstrcpynW(dest
, src
, max
);
421 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
423 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
424 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
427 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
429 LPWSTR wstr
= (LPWSTR
)text
;
431 if (!isW
&& is_textT(text
, isW
))
433 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
434 wstr
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
435 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
437 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
441 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
443 if (!isW
&& is_textT(wstr
, isW
)) HeapFree(GetProcessHeap(), 0, wstr
);
447 * dest is a pointer to a Unicode string
448 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
450 static BOOL
textsetptrT(LPWSTR
*dest
, LPWSTR src
, BOOL isW
)
454 if (src
== LPSTR_TEXTCALLBACKW
)
456 if (is_textW(*dest
)) COMCTL32_Free(*dest
);
457 *dest
= LPSTR_TEXTCALLBACKW
;
461 LPWSTR pszText
= textdupTtoW(src
, isW
);
462 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
463 bResult
= Str_SetPtrW(dest
, pszText
);
464 textfreeT(pszText
, isW
);
470 * compares a Unicode to a Unicode/ANSI text string
472 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
474 if (!aw
) return bt
? -1 : 0;
475 if (!bt
) return aw
? 1 : 0;
476 if (aw
== LPSTR_TEXTCALLBACKW
)
477 return bt
== LPSTR_TEXTCALLBACKW
? 0 : -1;
478 if (bt
!= LPSTR_TEXTCALLBACKW
)
480 LPWSTR bw
= textdupTtoW(bt
, isW
);
481 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
489 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
493 n
= min(min(n
, strlenW(s1
)), strlenW(s2
));
494 res
= CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
);
495 return res
? res
- sizeof(WCHAR
) : res
;
498 /******** Debugging functions *****************************************/
500 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
502 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
503 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
506 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
508 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
509 n
= min(textlenT(text
, isW
), n
);
510 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
513 static char* debug_getbuf()
515 static int index
= 0;
516 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
517 return buffers
[index
++ % DEBUG_BUFFERS
];
520 static inline char* debugrange(const RANGE
*lprng
)
524 char* buf
= debug_getbuf();
525 snprintf(buf
, DEBUG_BUFFER_SIZE
, "[%d, %d)", lprng
->lower
, lprng
->upper
);
527 } else return "(null)";
530 static inline char* debugpoint(const POINT
*lppt
)
534 char* buf
= debug_getbuf();
535 snprintf(buf
, DEBUG_BUFFER_SIZE
, "(%ld, %ld)", lppt
->x
, lppt
->y
);
537 } else return "(null)";
540 static inline char* debugrect(const RECT
*rect
)
544 char* buf
= debug_getbuf();
545 snprintf(buf
, DEBUG_BUFFER_SIZE
, "[(%d, %d);(%d, %d)]",
546 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
548 } else return "(null)";
551 static char * debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
553 char* buf
= debug_getbuf(), *text
= buf
;
554 int len
, size
= DEBUG_BUFFER_SIZE
;
556 if (pScrollInfo
== NULL
) return "(null)";
557 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
558 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
559 if (pScrollInfo
->fMask
& SIF_RANGE
)
560 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
562 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
563 if (pScrollInfo
->fMask
& SIF_PAGE
)
564 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
566 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
567 if (pScrollInfo
->fMask
& SIF_POS
)
568 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
570 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
571 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
572 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
574 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
577 buf
= text
+ strlen(text
);
579 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
583 static char* debugnmlistview(const NMLISTVIEW
*plvnm
)
587 char* buf
= debug_getbuf();
588 snprintf(buf
, DEBUG_BUFFER_SIZE
, "iItem=%d, iSubItem=%d, uNewState=0x%x,"
589 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld\n",
590 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
591 plvnm
->uChanged
, debugpoint(&plvnm
->ptAction
), plvnm
->lParam
);
593 } else return "(null)";
596 static char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
598 char* buf
= debug_getbuf(), *text
= buf
;
599 int len
, size
= DEBUG_BUFFER_SIZE
;
601 if (lpLVItem
== NULL
) return "(null)";
602 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
603 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
604 if (lpLVItem
->mask
& LVIF_STATE
)
605 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
607 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
608 if (lpLVItem
->mask
& LVIF_TEXT
)
609 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
611 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
612 if (lpLVItem
->mask
& LVIF_IMAGE
)
613 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
615 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
616 if (lpLVItem
->mask
& LVIF_PARAM
)
617 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
619 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
620 if (lpLVItem
->mask
& LVIF_INDENT
)
621 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
623 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
626 buf
= text
+ strlen(text
);
628 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
632 static char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
634 char* buf
= debug_getbuf(), *text
= buf
;
635 int len
, size
= DEBUG_BUFFER_SIZE
;
637 if (lpColumn
== NULL
) return "(null)";
638 len
= snprintf(buf
, size
, "{");
639 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
640 if (lpColumn
->mask
& LVCF_SUBITEM
)
641 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
643 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
644 if (lpColumn
->mask
& LVCF_FMT
)
645 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
647 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
648 if (lpColumn
->mask
& LVCF_WIDTH
)
649 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
651 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
652 if (lpColumn
->mask
& LVCF_TEXT
)
653 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
655 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
656 if (lpColumn
->mask
& LVCF_IMAGE
)
657 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
659 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
660 if (lpColumn
->mask
& LVCF_ORDER
)
661 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
663 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
666 buf
= text
+ strlen(text
);
668 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
673 static char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
677 char* buf
= debug_getbuf();
678 snprintf(buf
, DEBUG_BUFFER_SIZE
, "{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
679 debugpoint(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
681 } else return "(null)";
684 /******** Notification functions i************************************/
686 static LRESULT
notify_hdr(LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
690 TRACE("(code=%d)\n", code
);
692 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
693 pnmh
->idFrom
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_ID
);
695 result
= SendMessageW(GetParent(infoPtr
->hwndSelf
), WM_NOTIFY
,
696 (WPARAM
)pnmh
->idFrom
, (LPARAM
)pnmh
);
698 TRACE(" <= %ld\n", result
);
703 static inline LRESULT
notify(LISTVIEW_INFO
*infoPtr
, INT code
)
706 return notify_hdr(infoPtr
, code
, &nmh
);
709 static inline void notify_itemactivate(LISTVIEW_INFO
*infoPtr
)
711 notify(infoPtr
, LVN_ITEMACTIVATE
);
714 static inline LRESULT
notify_listview(LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
716 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
717 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
720 static LRESULT
notify_click(LISTVIEW_INFO
*infoPtr
, INT code
, LVHITTESTINFO
*lvht
)
725 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
726 ZeroMemory(&nmlv
, sizeof(nmlv
));
727 nmlv
.iItem
= lvht
->iItem
;
728 nmlv
.iSubItem
= lvht
->iSubItem
;
729 nmlv
.ptAction
= lvht
->pt
;
730 item
.mask
= LVIF_PARAM
;
731 item
.iItem
= lvht
->iItem
;
733 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
734 return notify_listview(infoPtr
, code
, &nmlv
);
737 static void notify_deleteitem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
742 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
744 item
.mask
= LVIF_PARAM
;
747 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
748 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
751 static int get_ansi_notification(INT unicodeNotificationCode
)
753 switch (unicodeNotificationCode
)
755 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
756 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
757 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
758 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
759 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
760 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
762 ERR("unknown notification %x\n", unicodeNotificationCode
);
767 Send notification. depends on dispinfoW having same
768 structure as dispinfoA.
769 infoPtr : listview struct
770 notificationCode : *Unicode* notification code
771 pdi : dispinfo structure (can be unicode or ansi)
772 isW : TRUE if dispinfo is Unicode
774 static BOOL
notify_dispinfoT(LISTVIEW_INFO
*infoPtr
, INT notificationCode
, LPNMLVDISPINFOW pdi
, BOOL isW
)
776 BOOL bResult
= FALSE
;
777 BOOL convertToAnsi
= FALSE
, convertToUnicode
= FALSE
;
779 INT cchTempBufMax
= 0, savCchTextMax
= 0;
780 LPWSTR pszTempBuf
= NULL
, savPszText
= NULL
;
782 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_textT(pdi
->item
.pszText
, isW
))
784 convertToAnsi
= (isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
785 convertToUnicode
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
788 if (convertToAnsi
|| convertToUnicode
)
790 if (notificationCode
!= LVN_GETDISPINFOW
)
792 cchTempBufMax
= convertToUnicode
?
793 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
794 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
798 cchTempBufMax
= pdi
->item
.cchTextMax
;
799 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
802 pszTempBuf
= HeapAlloc(GetProcessHeap(), 0,
803 (convertToUnicode
? sizeof(WCHAR
) : sizeof(CHAR
)) * cchTempBufMax
);
804 if (!pszTempBuf
) return FALSE
;
805 if (convertToUnicode
)
806 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
807 pszTempBuf
, cchTempBufMax
);
809 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) pszTempBuf
,
810 cchTempBufMax
, NULL
, NULL
);
811 savCchTextMax
= pdi
->item
.cchTextMax
;
812 savPszText
= pdi
->item
.pszText
;
813 pdi
->item
.pszText
= pszTempBuf
;
814 pdi
->item
.cchTextMax
= cchTempBufMax
;
817 if (infoPtr
->notifyFormat
== NFR_ANSI
)
818 realNotifCode
= get_ansi_notification(notificationCode
);
820 realNotifCode
= notificationCode
;
821 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
822 bResult
= notify_hdr(infoPtr
, realNotifCode
, (LPNMHDR
)pdi
);
824 if (convertToUnicode
|| convertToAnsi
)
826 if (convertToUnicode
) /* note : pointer can be changed by app ! */
827 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) savPszText
,
828 savCchTextMax
, NULL
, NULL
);
830 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
831 savPszText
, savCchTextMax
);
832 pdi
->item
.pszText
= savPszText
; /* restores our buffer */
833 pdi
->item
.cchTextMax
= savCchTextMax
;
834 HeapFree(GetProcessHeap(), 0, pszTempBuf
);
839 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rcBounds
)
841 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
842 lpnmlvcd
->nmcd
.hdc
= hdc
;
843 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
844 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
845 lpnmlvcd
->clrText
= infoPtr
->clrText
;
848 static inline DWORD
notify_customdraw (LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
850 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
851 return notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
854 /******** Item iterator functions **********************************/
856 static RANGES
ranges_create(int count
);
857 static void ranges_destroy(RANGES ranges
);
858 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
859 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
860 static void ranges_dump(RANGES ranges
);
862 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
864 RANGE range
= { nItem
, nItem
+ 1 };
866 return ranges_add(ranges
, range
);
869 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
871 RANGE range
= { nItem
, nItem
+ 1 };
873 return ranges_del(ranges
, range
);
877 * ITERATOR DOCUMENTATION
879 * The iterator functions allow for easy, and convenient iteration
880 * over items of iterest in the list. Typically, you create a
881 * iterator, use it, and destroy it, as such:
884 * iterator_xxxitems(&i, ...);
885 * while (iterator_{prev,next}(&i)
887 * //code which uses i.nItem
889 * iterator_destroy(&i);
891 * where xxx is either: framed, or visible.
892 * Note that it is important that the code destroys the iterator
893 * after it's done with it, as the creation of the iterator may
894 * allocate memory, which thus needs to be freed.
896 * You can iterate both forwards, and backwards through the list,
897 * by using iterator_next or iterator_prev respectively.
899 * Lower numbered items are draw on top of higher number items in
900 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
901 * items may overlap). So, to test items, you should use
903 * which lists the items top to bottom (in Z-order).
904 * For drawing items, you should use
906 * which lists the items bottom to top (in Z-order).
907 * If you keep iterating over the items after the end-of-items
908 * marker (-1) is returned, the iterator will start from the
909 * beginning. Typically, you don't need to test for -1,
910 * because iterator_{next,prev} will return TRUE if more items
911 * are to be iterated over, or FALSE otherwise.
913 * Note: the iterator is defined to be bidirectional. That is,
914 * any number of prev followed by any number of next, or
915 * five versa, should leave the iterator at the same item:
916 * prev * n, next * n = next * n, prev * n
918 * The iterator has a notion of a out-of-order, special item,
919 * which sits at the start of the list. This is used in
920 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
921 * which needs to be first, as it may overlap other items.
923 * The code is a bit messy because we have:
924 * - a special item to deal with
925 * - simple range, or composite range
927 * If find bugs, or want to add features, please make sure you
928 * always check/modify *both* iterator_prev, and iterator_next.
932 * This function iterates through the items in increasing order,
933 * but prefixed by the special item, then -1. That is:
934 * special, 1, 2, 3, ..., n, -1.
935 * Each item is listed only once.
937 static inline BOOL
iterator_next(ITERATOR
* i
)
941 i
->nItem
= i
->nSpecial
;
942 if (i
->nItem
!= -1) return TRUE
;
944 if (i
->nItem
== i
->nSpecial
)
946 if (i
->ranges
) i
->index
= 0;
952 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
953 if (i
->nItem
< i
->range
.upper
) return TRUE
;
958 if (i
->index
< i
->ranges
->hdpa
->nItemCount
)
959 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
962 else if (i
->nItem
>= i
->range
.upper
) goto end
;
964 i
->nItem
= i
->range
.lower
;
965 if (i
->nItem
>= 0) goto testitem
;
972 * This function iterates through the items in decreasing order,
973 * followed by the special item, then -1. That is:
974 * n, n-1, ..., 3, 2, 1, special, -1.
975 * Each item is listed only once.
977 static inline BOOL
iterator_prev(ITERATOR
* i
)
984 if (i
->ranges
) i
->index
= i
->ranges
->hdpa
->nItemCount
;
987 if (i
->nItem
== i
->nSpecial
)
995 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
996 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1002 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1005 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1007 i
->nItem
= i
->range
.upper
;
1008 if (i
->nItem
> 0) goto testitem
;
1010 return (i
->nItem
= i
->nSpecial
) != -1;
1013 static RANGE
iterator_range(ITERATOR
* i
)
1017 if (!i
->ranges
) return i
->range
;
1019 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1020 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->ranges
->hdpa
->nItemCount
- 1)).upper
;
1025 * Releases resources associated with this ierator.
1027 static inline void iterator_destroy(ITERATOR
* i
)
1029 if (i
->ranges
) ranges_destroy(i
->ranges
);
1033 * Create an empty iterator.
1035 static inline BOOL
iterator_empty(ITERATOR
* i
)
1037 ZeroMemory(i
, sizeof(*i
));
1038 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1043 * Create an iterator over a range.
1045 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1053 * Create an iterator over a bunch of ranges.
1054 * Please note that the iterator will take ownership of the ranges,
1055 * and will free them upon destruction.
1057 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1065 * Creates an iterator over the items which intersect lprc.
1067 static BOOL
iterator_frameditems(ITERATOR
* i
, LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1069 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1070 RECT frame
= *lprc
, rcItem
, rcTemp
;
1073 /* in case we fail, we want to return an empty iterator */
1074 if (!iterator_empty(i
)) return FALSE
;
1076 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1078 TRACE("(lprc=%s)\n", debugrect(lprc
));
1079 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1081 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)
1085 if (uView
== LVS_ICON
&& infoPtr
->nFocusedItem
!= -1)
1087 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1088 if (IntersectRect(&rcTemp
, &rcItem
, lprc
))
1089 i
->nSpecial
= infoPtr
->nFocusedItem
;
1091 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1092 /* to do better here, we need to have PosX, and PosY sorted */
1093 TRACE("building icon ranges:\n");
1094 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1096 rcItem
.left
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1097 rcItem
.top
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1098 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1099 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1100 if (IntersectRect(&rcTemp
, &rcItem
, &frame
))
1101 ranges_additem(i
->ranges
, nItem
);
1105 else if (uView
== LVS_REPORT
)
1109 if (frame
.left
>= infoPtr
->nItemWidth
) return TRUE
;
1110 if (frame
.top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1112 range
.lower
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1113 range
.upper
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1114 if (range
.upper
<= range
.lower
) return TRUE
;
1115 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1116 TRACE(" report=%s\n", debugrange(&i
->range
));
1120 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1121 INT nFirstRow
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1122 INT nLastRow
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1123 INT nFirstCol
= max(frame
.left
/ infoPtr
->nItemWidth
, 0);
1124 INT nLastCol
= min((frame
.right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1125 INT lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1129 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1130 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1132 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1134 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1135 TRACE("building list ranges:\n");
1136 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1138 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1139 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1140 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1141 TRACE(" list=%s\n", debugrange(&item_range
));
1142 ranges_add(i
->ranges
, item_range
);
1150 * Creates an iterator over the items which intersect the visible region of hdc.
1152 static BOOL
iterator_visibleitems(ITERATOR
*i
, LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1154 POINT Origin
, Position
;
1155 RECT rcItem
, rcClip
;
1158 rgntype
= GetClipBox(hdc
, &rcClip
);
1159 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1160 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1161 if (rgntype
== SIMPLEREGION
) return TRUE
;
1163 /* first deal with the special item */
1164 if (i
->nSpecial
!= -1)
1166 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1167 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1170 /* if we can't deal with the region, we'll just go with the simple range */
1171 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1172 TRACE("building visible range:\n");
1173 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1175 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1176 if (!ranges_add(i
->ranges
, i
->range
))
1178 ranges_destroy(i
->ranges
);
1184 /* now delete the invisible items from the list */
1185 while(iterator_next(i
))
1187 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1188 rcItem
.left
= Position
.x
+ Origin
.x
;
1189 rcItem
.top
= Position
.y
+ Origin
.y
;
1190 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1191 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1192 if (!RectVisible(hdc
, &rcItem
))
1193 ranges_delitem(i
->ranges
, i
->nItem
);
1195 /* the iterator should restart on the next iterator_next */
1201 /******** Misc helper functions ************************************/
1203 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1204 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1206 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1207 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1210 static inline BOOL
is_autoarrange(LISTVIEW_INFO
*infoPtr
)
1212 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1214 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1215 (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
);
1218 /******** Internal API functions ************************************/
1220 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1222 static COLUMN_INFO mainItem
;
1224 if (nSubItem
== 0 && infoPtr
->hdpaColumns
->nItemCount
== 0) return &mainItem
;
1225 assert (nSubItem
>= 0 && nSubItem
< infoPtr
->hdpaColumns
->nItemCount
);
1226 return (COLUMN_INFO
*)DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1229 static inline void LISTVIEW_GetHeaderRect(LISTVIEW_INFO
*infoPtr
, INT nSubItem
, RECT
*lprc
)
1231 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1234 static inline BOOL
LISTVIEW_GetItemW(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1236 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1239 /* Listview invlaidation functions: use _only_ these function to invalidate */
1241 static inline BOOL
is_redrawing(LISTVIEW_INFO
*infoPtr
)
1243 return infoPtr
->bRedraw
&& !infoPtr
->bFirstPaint
;
1246 static inline void LISTVIEW_InvalidateRect(LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1248 if(!is_redrawing(infoPtr
)) return;
1249 TRACE(" invalidating rect=%s\n", debugrect(rect
));
1250 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1253 static inline void LISTVIEW_InvalidateItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1257 if(!is_redrawing(infoPtr
)) return;
1258 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1259 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1262 static inline void LISTVIEW_InvalidateSubItem(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1264 POINT Origin
, Position
;
1267 if(!is_redrawing(infoPtr
)) return;
1268 assert ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_REPORT
);
1269 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1270 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1271 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1273 rcBox
.bottom
= infoPtr
->nItemHeight
;
1274 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1275 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1278 static inline void LISTVIEW_InvalidateList(LISTVIEW_INFO
*infoPtr
)
1280 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1283 static inline void LISTVIEW_InvalidateColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1287 if(!is_redrawing(infoPtr
)) return;
1288 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1289 rcCol
.top
= infoPtr
->rcList
.top
;
1290 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1291 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1296 * Retrieves the number of items that can fit vertically in the client area.
1299 * [I] infoPtr : valid pointer to the listview structure
1302 * Number of items per row.
1304 static inline INT
LISTVIEW_GetCountPerRow(LISTVIEW_INFO
*infoPtr
)
1306 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1308 return max(nListWidth
/infoPtr
->nItemWidth
, 1);
1313 * Retrieves the number of items that can fit horizontally in the client
1317 * [I] infoPtr : valid pointer to the listview structure
1320 * Number of items per column.
1322 static inline INT
LISTVIEW_GetCountPerColumn(LISTVIEW_INFO
*infoPtr
)
1324 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1326 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1330 /*************************************************************************
1331 * LISTVIEW_ProcessLetterKeys
1333 * Processes keyboard messages generated by pressing the letter keys
1335 * What this does is perform a case insensitive search from the
1336 * current position with the following quirks:
1337 * - If two chars or more are pressed in quick succession we search
1338 * for the corresponding string (e.g. 'abc').
1339 * - If there is a delay we wipe away the current search string and
1340 * restart with just that char.
1341 * - If the user keeps pressing the same character, whether slowly or
1342 * fast, so that the search string is entirely composed of this
1343 * character ('aaaaa' for instance), then we search for first item
1344 * that starting with that character.
1345 * - If the user types the above character in quick succession, then
1346 * we must also search for the corresponding string ('aaaaa'), and
1347 * go to that string if there is a match.
1350 * [I] hwnd : handle to the window
1351 * [I] charCode : the character code, the actual character
1352 * [I] keyData : key data
1360 * - The current implementation has a list of characters it will
1361 * accept and it ignores averything else. In particular it will
1362 * ignore accentuated characters which seems to match what
1363 * Windows does. But I'm not sure it makes sense to follow
1365 * - We don't sound a beep when the search fails.
1369 * TREEVIEW_ProcessLetterKeys
1371 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1376 WCHAR buffer
[MAX_PATH
];
1377 DWORD lastKeyPressTimestamp
= infoPtr
->lastKeyPressTimestamp
;
1379 /* simple parameter checking */
1380 if (!charCode
|| !keyData
) return 0;
1382 /* only allow the valid WM_CHARs through */
1383 if (!isalnum(charCode
) &&
1384 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1385 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1386 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1387 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1388 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1389 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1390 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1391 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1392 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1395 /* if there's one item or less, there is no where to go */
1396 if (infoPtr
->nItemCount
<= 1) return 0;
1398 /* update the search parameters */
1399 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1400 if (infoPtr
->lastKeyPressTimestamp
- lastKeyPressTimestamp
< KEY_DELAY
) {
1401 if (infoPtr
->nSearchParamLength
< MAX_PATH
)
1402 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
1403 if (infoPtr
->charCode
!= charCode
)
1404 infoPtr
->charCode
= charCode
= 0;
1406 infoPtr
->charCode
=charCode
;
1407 infoPtr
->szSearchParam
[0]=charCode
;
1408 infoPtr
->nSearchParamLength
=1;
1409 /* Redundant with the 1 char string */
1413 /* and search from the current position */
1415 if (infoPtr
->nFocusedItem
>= 0) {
1416 endidx
=infoPtr
->nFocusedItem
;
1418 /* if looking for single character match,
1419 * then we must always move forward
1421 if (infoPtr
->nSearchParamLength
== 1)
1424 endidx
=infoPtr
->nItemCount
;
1428 if (idx
== infoPtr
->nItemCount
) {
1429 if (endidx
== infoPtr
->nItemCount
|| endidx
== 0)
1435 item
.mask
= LVIF_TEXT
;
1438 item
.pszText
= buffer
;
1439 item
.cchTextMax
= MAX_PATH
;
1440 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1442 /* check for a match */
1443 if (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
1446 } else if ( (charCode
!= 0) && (nItem
== -1) && (nItem
!= infoPtr
->nFocusedItem
) &&
1447 (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
1448 /* This would work but we must keep looking for a longer match */
1452 } while (idx
!= endidx
);
1455 LISTVIEW_KeySelection(infoPtr
, nItem
);
1460 /*************************************************************************
1461 * LISTVIEW_UpdateHeaderSize [Internal]
1463 * Function to resize the header control
1466 * [I] hwnd : handle to a window
1467 * [I] nNewScrollPos : scroll pos to set
1472 static void LISTVIEW_UpdateHeaderSize(LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1477 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1479 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1480 point
[0].x
= winRect
.left
;
1481 point
[0].y
= winRect
.top
;
1482 point
[1].x
= winRect
.right
;
1483 point
[1].y
= winRect
.bottom
;
1485 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1486 point
[0].x
= -nNewScrollPos
;
1487 point
[1].x
+= nNewScrollPos
;
1489 SetWindowPos(infoPtr
->hwndHeader
,0,
1490 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1491 SWP_NOZORDER
| SWP_NOACTIVATE
);
1496 * Update the scrollbars. This functions should be called whenever
1497 * the content, size or view changes.
1500 * [I] infoPtr : valid pointer to the listview structure
1505 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*infoPtr
)
1507 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1508 SCROLLINFO horzInfo
, vertInfo
;
1510 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
1512 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
1513 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
1514 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1516 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
1517 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
1518 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1520 /* for now, we'll set info.nMax to the _count_, and adjust it later */
1521 if (uView
== LVS_LIST
)
1523 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
1524 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
1525 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
1527 else if (uView
== LVS_REPORT
)
1529 horzInfo
.nMax
= infoPtr
->nItemWidth
;
1530 vertInfo
.nMax
= infoPtr
->nItemCount
;
1531 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
1533 else /* LVS_ICON, or LVS_SMALLICON */
1537 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
))
1539 horzInfo
.nMax
= rcView
.right
- rcView
.left
;
1540 vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
1544 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1545 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
1546 SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
1547 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
1549 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1550 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
1551 SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
1552 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
1554 /* Update the Header Control */
1555 if (uView
== LVS_REPORT
)
1557 horzInfo
.fMask
= SIF_POS
;
1558 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
1559 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
1566 * Shows/hides the focus rectangle.
1569 * [I] infoPtr : valid pointer to the listview structure
1570 * [I] fShow : TRUE to show the focus, FALSE to hide it.
1575 static void LISTVIEW_ShowFocusRect(LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
1577 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1580 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
1582 if (infoPtr
->nFocusedItem
< 0) return;
1584 /* we need some gymnastics in ICON mode to handle large items */
1585 if ( (infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_ICON
)
1589 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
1590 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
1592 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1597 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
1599 /* for some reason, owner draw should work only in report mode */
1600 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (uView
== LVS_REPORT
))
1605 item
.iItem
= infoPtr
->nFocusedItem
;
1607 item
.mask
= LVIF_PARAM
;
1608 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
1610 ZeroMemory(&dis
, sizeof(dis
));
1611 dis
.CtlType
= ODT_LISTVIEW
;
1612 dis
.CtlID
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_ID
);
1613 dis
.itemID
= item
.iItem
;
1614 dis
.itemAction
= ODA_FOCUS
;
1615 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
1616 dis
.hwndItem
= infoPtr
->hwndSelf
;
1618 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
1619 dis
.itemData
= item
.lParam
;
1621 SendMessageW(GetParent(infoPtr
->hwndSelf
), WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
1625 DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1628 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1632 * Invalidates all visible selected items.
1634 static void LISTVIEW_InvalidateSelectedItems(LISTVIEW_INFO
*infoPtr
)
1638 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
1639 while(iterator_next(&i
))
1641 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
1642 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
1644 iterator_destroy(&i
);
1649 * DESCRIPTION: [INTERNAL]
1650 * Computes an item's (left,top) corner, relative to rcView.
1651 * That is, the position has NOT been made relative to the Origin.
1652 * This is deliberate, to avoid computing the Origin over, and
1653 * over again, when this function is call in a loop. Instead,
1654 * one ca factor the computation of the Origin before the loop,
1655 * and offset the value retured by this function, on every iteration.
1658 * [I] infoPtr : valid pointer to the listview structure
1659 * [I] nItem : item number
1660 * [O] lpptOrig : item top, left corner
1665 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
1667 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1669 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
1671 if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
1673 lpptPosition
->x
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1674 lpptPosition
->y
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1676 else if (uView
== LVS_LIST
)
1678 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
1679 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
1680 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
1682 else /* LVS_REPORT */
1684 lpptPosition
->x
= REPORT_MARGINX
;
1685 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
1690 * DESCRIPTION: [INTERNAL]
1691 * Compute the rectangles of an item. This is to localize all
1692 * the computations in one place. If you are not interested in some
1693 * of these values, simply pass in a NULL -- the fucntion is smart
1694 * enough to compute only what's necessary. The function computes
1695 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
1696 * one, the BOX rectangle. This rectangle is very cheap to compute,
1697 * and is guaranteed to contain all the other rectangles. Computing
1698 * the ICON rect is also cheap, but all the others are potentaily
1699 * expensive. This gives an easy and effective optimization when
1700 * searching (like point inclusion, or rectangle intersection):
1701 * first test against the BOX, and if TRUE, test agains the desired
1703 * If the function does not have all the necessary information
1704 * to computed the requested rectangles, will crash with a
1705 * failed assertion. This is done so we catch all programming
1706 * errors, given that the function is called only from our code.
1708 * We have the following 'special' meanings for a few fields:
1709 * * If LVIS_FOCUSED is set, we assume the item has the focus
1710 * This is important in ICON mode, where it might get a larger
1711 * then usual rectange
1713 * Please note that subitem support works only in REPORT mode.
1716 * [I] infoPtr : valid pointer to the listview structure
1717 * [I] lpLVItem : item to compute the measures for
1718 * [O] lprcBox : ptr to Box rectangle
1719 * The internal LVIR_BOX rectangle
1720 * [0] lprcState : ptr to State icon rectangle
1721 * The internal LVIR_STATE rectangle
1722 * [O] lprcIcon : ptr to Icon rectangle
1723 * Same as LVM_GETITEMRECT with LVIR_ICON
1724 * [O] lprcLabel : ptr to Label rectangle
1725 * Same as LVM_GETITEMRECT with LVIR_LABEL
1730 static void LISTVIEW_GetItemMetrics(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
1731 LPRECT lprcBox
, LPRECT lprcState
,
1732 LPRECT lprcIcon
, LPRECT lprcLabel
)
1734 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1735 BOOL doState
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
1736 RECT Box
, State
, Icon
, Label
;
1737 COLUMN_INFO
*lpColumnInfo
= NULL
;
1739 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
1741 /* Be smart and try to figure out the minimum we have to do */
1742 if (lpLVItem
->iSubItem
) assert(uView
== LVS_REPORT
);
1743 if (uView
== LVS_ICON
&& (lprcBox
|| lprcLabel
))
1745 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
1746 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
1748 if (lprcLabel
) doLabel
= TRUE
;
1749 if (doLabel
|| lprcIcon
) doIcon
= TRUE
;
1750 if (doIcon
|| lprcState
) doState
= TRUE
;
1752 /************************************************************/
1753 /* compute the box rectangle (it should be cheap to do) */
1754 /************************************************************/
1755 if (lpLVItem
->iSubItem
|| uView
== LVS_REPORT
)
1756 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
1758 if (lpLVItem
->iSubItem
)
1760 Box
= lpColumnInfo
->rcHeader
;
1765 Box
.right
= infoPtr
->nItemWidth
;
1768 Box
.bottom
= infoPtr
->nItemHeight
;
1770 /************************************************************/
1771 /* compute STATEICON bounding box */
1772 /************************************************************/
1775 if (uView
== LVS_ICON
)
1777 State
.left
= Box
.left
- infoPtr
->iconStateSize
.cx
- 2;
1778 if (infoPtr
->himlNormal
)
1779 State
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
1780 State
.top
= Box
.top
+ infoPtr
->iconSize
.cy
- infoPtr
->iconStateSize
.cy
+ 4;
1784 /* we need the ident in report mode, if we don't have it, we fail */
1785 State
.left
= Box
.left
;
1786 if (uView
== LVS_REPORT
)
1788 State
.left
+= REPORT_MARGINX
;
1789 if (lpLVItem
->iSubItem
== 0)
1791 assert(lpLVItem
->mask
& LVIF_INDENT
);
1792 State
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
;
1795 State
.top
= Box
.top
;
1797 State
.right
= State
.left
;
1798 State
.bottom
= State
.top
;
1799 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
1801 State
.right
+= infoPtr
->iconStateSize
.cx
;
1802 State
.bottom
+= infoPtr
->iconStateSize
.cy
;
1804 if (lprcState
) *lprcState
= State
;
1805 TRACE(" - state=%s\n", debugrect(&State
));
1808 /************************************************************/
1809 /* compute ICON bounding box (ala LVM_GETITEMRECT) */
1810 /************************************************************/
1813 if (uView
== LVS_ICON
)
1815 Icon
.left
= Box
.left
;
1816 if (infoPtr
->himlNormal
)
1817 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
1818 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
1819 Icon
.right
= Icon
.left
;
1820 Icon
.bottom
= Icon
.top
;
1821 if (infoPtr
->himlNormal
)
1823 Icon
.right
+= infoPtr
->iconSize
.cx
;
1824 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
1827 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
1829 Icon
.left
= State
.right
;
1830 if (!IsRectEmpty(&State
)) Icon
.left
+= IMAGE_PADDING
;
1832 Icon
.right
= Icon
.left
;
1833 if (infoPtr
->himlSmall
&& (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 || (lpColumnInfo
->fmt
& LVCFMT_IMAGE
)))
1834 Icon
.right
+= infoPtr
->iconSize
.cx
;
1835 Icon
.bottom
= Icon
.top
+ infoPtr
->nItemHeight
;
1837 if(lprcIcon
) *lprcIcon
= Icon
;
1838 TRACE(" - icon=%s\n", debugrect(&Icon
));
1841 /************************************************************/
1842 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
1843 /************************************************************/
1846 SIZE labelSize
= { 0, 0 };
1848 /* calculate how far to the right can the label strech */
1849 Label
.right
= Box
.right
;
1850 if (uView
== LVS_REPORT
)
1852 if (lpLVItem
->iSubItem
== 0) Label
= lpColumnInfo
->rcHeader
;
1853 Label
.right
-= REPORT_MARGINX
;
1856 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && uView
== LVS_REPORT
))
1858 labelSize
.cx
= infoPtr
->nItemWidth
;
1859 labelSize
.cy
= infoPtr
->nItemHeight
;
1863 /* we need the text in non owner draw mode */
1864 assert(lpLVItem
->mask
& LVIF_TEXT
);
1865 if (is_textT(lpLVItem
->pszText
, TRUE
))
1867 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
1868 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
1869 HFONT hOldFont
= SelectObject(hdc
, hFont
);
1873 /* compute rough rectangle where the label will go */
1874 SetRectEmpty(&rcText
);
1875 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_PADDING
;
1876 rcText
.bottom
= infoPtr
->nItemHeight
;
1877 if (uView
== LVS_ICON
)
1878 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
1880 /* now figure out the flags */
1881 if (uView
== LVS_ICON
)
1882 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
1884 uFormat
= LV_SL_DT_FLAGS
;
1886 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
1888 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_PADDING
, infoPtr
->nItemWidth
);
1889 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
1891 SelectObject(hdc
, hOldFont
);
1892 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1896 if (uView
== LVS_ICON
)
1898 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
1899 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
1900 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
1901 Label
.right
= Label
.left
+ labelSize
.cx
;
1902 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
1903 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
1905 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
1906 labelSize
.cy
/= infoPtr
->ntmHeight
;
1907 labelSize
.cy
= max(labelSize
.cy
, 1);
1908 labelSize
.cy
*= infoPtr
->ntmHeight
;
1910 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
1912 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
1914 Label
.left
= Icon
.right
;
1915 if (!IsRectEmpty(&Icon
) || !IsRectEmpty(&State
)) Label
.left
+= IMAGE_PADDING
;
1916 Label
.top
= Box
.top
;
1917 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
1918 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
1921 if (lprcLabel
) *lprcLabel
= Label
;
1922 TRACE(" - label=%s\n", debugrect(&Label
));
1925 /* Fix the Box if necessary */
1928 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
1929 else *lprcBox
= Box
;
1931 TRACE(" - box=%s\n", debugrect(&Box
));
1935 * DESCRIPTION: [INTERNAL]
1938 * [I] infoPtr : valid pointer to the listview structure
1939 * [I] nItem : item number
1940 * [O] lprcBox : ptr to Box rectangle
1945 static void LISTVIEW_GetItemBox(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
1947 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1948 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
1949 POINT Position
, Origin
;
1952 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1953 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1955 /* Be smart and try to figure out the minimum we have to do */
1957 if (uView
== LVS_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
1958 lvItem
.mask
|= LVIF_TEXT
;
1959 lvItem
.iItem
= nItem
;
1960 lvItem
.iSubItem
= 0;
1961 lvItem
.pszText
= szDispText
;
1962 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
1963 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
1964 if (uView
== LVS_ICON
)
1966 lvItem
.mask
|= LVIF_STATE
;
1967 lvItem
.stateMask
= LVIS_FOCUSED
;
1968 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
1970 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0);
1972 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
1978 * Returns the current icon position, and advances it along the top.
1979 * The returned position is not offset by Origin.
1982 * [I] infoPtr : valid pointer to the listview structure
1983 * [O] lpPos : will get the current icon position
1988 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
1990 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1992 *lpPos
= infoPtr
->currIconPos
;
1994 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
1995 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
1997 infoPtr
->currIconPos
.x
= 0;
1998 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2004 * Returns the current icon position, and advances it down the left edge.
2005 * The returned position is not offset by Origin.
2008 * [I] infoPtr : valid pointer to the listview structure
2009 * [O] lpPos : will get the current icon position
2014 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2016 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2018 *lpPos
= infoPtr
->currIconPos
;
2020 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2021 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2023 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2024 infoPtr
->currIconPos
.y
= 0;
2030 * Moves an icon to the specified position.
2031 * It takes care of invalidating the item, etc.
2034 * [I] infoPtr : valid pointer to the listview structure
2035 * [I] nItem : the item to move
2036 * [I] lpPos : the new icon position
2037 * [I] isNew : flags the item as being new
2043 static BOOL
LISTVIEW_MoveIconTo(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2049 old
.x
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2050 old
.y
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2052 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2053 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2056 /* Allocating a POINTER for every item is too resource intensive,
2057 * so we'll keep the (x,y) in different arrays */
2058 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)lppt
->x
)) return FALSE
;
2059 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)lppt
->y
)) return FALSE
;
2061 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2068 * Arranges listview items in icon display mode.
2071 * [I] infoPtr : valid pointer to the listview structure
2072 * [I] nAlignCode : alignment code
2078 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2080 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2081 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2085 if (uView
!= LVS_ICON
&& uView
!= LVS_SMALLICON
) return FALSE
;
2087 TRACE("nAlignCode=%d\n", nAlignCode
);
2089 if (nAlignCode
== LVA_DEFAULT
)
2091 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2092 else nAlignCode
= LVA_ALIGNTOP
;
2097 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2098 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2099 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2100 default: return FALSE
;
2103 infoPtr
->bAutoarrange
= TRUE
;
2104 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2105 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2107 next_pos(infoPtr
, &pos
);
2108 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2116 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2119 * [I] infoPtr : valid pointer to the listview structure
2120 * [O] lprcView : bounding rectangle
2126 static void LISTVIEW_GetAreaRect(LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2130 SetRectEmpty(lprcView
);
2132 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
2136 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2138 x
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2139 y
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2140 lprcView
->right
= max(lprcView
->right
, x
);
2141 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2143 if (infoPtr
->nItemCount
> 0)
2145 lprcView
->right
+= infoPtr
->nItemWidth
;
2146 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2151 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2152 x
= infoPtr
->nItemCount
/ y
;
2153 if (infoPtr
->nItemCount
% y
) x
++;
2154 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2155 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2159 lprcView
->right
= infoPtr
->nItemWidth
;
2160 lprcView
->bottom
= infoPtr
->nItemCount
* infoPtr
->nItemHeight
;
2167 * Retrieves the bounding rectangle of all the items.
2170 * [I] infoPtr : valid pointer to the listview structure
2171 * [O] lprcView : bounding rectangle
2177 static BOOL
LISTVIEW_GetViewRect(LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2181 TRACE("(lprcView=%p)\n", lprcView
);
2183 if (!lprcView
) return FALSE
;
2185 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2186 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2187 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2189 TRACE("lprcView=%s\n", debugrect(lprcView
));
2196 * Retrieves the subitem pointer associated with the subitem index.
2199 * [I] hdpaSubItems : DPA handle for a specific item
2200 * [I] nSubItem : index of subitem
2203 * SUCCESS : subitem pointer
2206 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2208 SUBITEM_INFO
*lpSubItem
;
2211 /* we should binary search here if need be */
2212 for (i
= 1; i
< hdpaSubItems
->nItemCount
; i
++)
2214 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
2215 if (lpSubItem
->iSubItem
== nSubItem
)
2225 * Caclulates the desired item width.
2228 * [I] infoPtr : valid pointer to the listview structure
2231 * The desired item width.
2233 static INT
LISTVIEW_CalculateItemWidth(LISTVIEW_INFO
*infoPtr
)
2235 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2238 TRACE("uView=%d\n", uView
);
2240 if (uView
== LVS_ICON
)
2241 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2242 else if (uView
== LVS_REPORT
)
2246 if (infoPtr
->hdpaColumns
->nItemCount
> 0)
2248 LISTVIEW_GetHeaderRect(infoPtr
, infoPtr
->hdpaColumns
->nItemCount
- 1, &rcHeader
);
2249 nItemWidth
= rcHeader
.right
;
2252 else /* LVS_SMALLICON, or LVS_LIST */
2256 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2257 nItemWidth
= max(LISTVIEW_GetLabelWidth(infoPtr
, i
), nItemWidth
);
2259 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
+ IMAGE_PADDING
;
2260 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
+ IMAGE_PADDING
;
2262 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2265 return max(nItemWidth
, 1);
2270 * Caclulates the desired item height.
2273 * [I] infoPtr : valid pointer to the listview structure
2276 * The desired item height.
2278 static INT
LISTVIEW_CalculateItemHeight(LISTVIEW_INFO
*infoPtr
)
2280 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2283 TRACE("uView=%d\n", uView
);
2285 if (uView
== LVS_ICON
)
2286 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2289 nItemHeight
= infoPtr
->ntmHeight
;
2290 if (infoPtr
->himlState
)
2291 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2292 if (infoPtr
->himlSmall
)
2293 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2294 if (infoPtr
->himlState
|| infoPtr
->himlSmall
)
2295 nItemHeight
+= HEIGHT_PADDING
;
2298 return max(nItemHeight
, 1);
2303 * Updates the width, and height of an item.
2306 * [I] infoPtr : valid pointer to the listview structure
2311 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2313 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2314 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2320 * Retrieves and saves important text metrics info for the current
2324 * [I] infoPtr : valid pointer to the listview structure
2327 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2329 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2330 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2331 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2334 if (GetTextMetricsW(hdc
, &tm
))
2336 infoPtr
->ntmHeight
= tm
.tmHeight
;
2337 infoPtr
->ntmAveCharWidth
= tm
.tmAveCharWidth
;
2339 SelectObject(hdc
, hOldFont
);
2340 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2342 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
2347 * A compare function for ranges
2350 * [I] range1 : pointer to range 1;
2351 * [I] range2 : pointer to range 2;
2355 * > 0 : if range 1 > range 2
2356 * < 0 : if range 2 > range 1
2357 * = 0 : if range intersects range 2
2359 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
2363 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
2365 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
2370 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange((RANGE
*)range1
), debugrange((RANGE
*)range2
), cmp
);
2376 #define ranges_check(ranges, desc) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
2378 #define ranges_check(ranges, desc) do { } while(0)
2381 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *func
, int line
)
2386 TRACE("*** Checking %s:%d:%s ***\n", func
, line
, desc
);
2388 assert (ranges
->hdpa
->nItemCount
>= 0);
2389 ranges_dump(ranges
);
2390 prev
= (RANGE
*)DPA_GetPtr(ranges
->hdpa
, 0);
2391 if (ranges
->hdpa
->nItemCount
> 0)
2392 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
2393 for (i
= 1; i
< ranges
->hdpa
->nItemCount
; i
++)
2395 curr
= (RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
);
2396 assert (prev
->upper
<= curr
->lower
);
2397 assert (curr
->lower
< curr
->upper
);
2400 TRACE("--- Done checking---\n");
2403 static RANGES
ranges_create(int count
)
2405 RANGES ranges
= (RANGES
)COMCTL32_Alloc(sizeof(struct tagRANGES
));
2406 if (!ranges
) return NULL
;
2407 ranges
->hdpa
= DPA_Create(count
);
2408 if (ranges
->hdpa
) return ranges
;
2409 COMCTL32_Free(ranges
);
2413 static void ranges_clear(RANGES ranges
)
2417 for(i
= 0; i
< ranges
->hdpa
->nItemCount
; i
++)
2418 COMCTL32_Free(DPA_GetPtr(ranges
->hdpa
, i
));
2419 DPA_DeleteAllPtrs(ranges
->hdpa
);
2423 static void ranges_destroy(RANGES ranges
)
2425 ranges_clear(ranges
);
2426 DPA_Destroy(ranges
->hdpa
);
2427 COMCTL32_Free(ranges
);
2430 static RANGES
ranges_clone(RANGES ranges
)
2435 if (!(clone
= ranges_create(ranges
->hdpa
->nItemCount
))) goto fail
;
2437 for (i
= 0; i
< ranges
->hdpa
->nItemCount
; i
++)
2439 RANGE
*newrng
= (RANGE
*)COMCTL32_Alloc(sizeof(RANGE
));
2440 if (!newrng
) goto fail
;
2441 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
2442 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
2447 TRACE ("clone failed\n");
2448 if (clone
) ranges_destroy(clone
);
2452 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
2456 for (i
= 0; i
< sub
->hdpa
->nItemCount
; i
++)
2457 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
2462 static void ranges_dump(RANGES ranges
)
2466 for (i
= 0; i
< ranges
->hdpa
->nItemCount
; i
++)
2467 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
2470 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
2472 RANGE srchrng
= { nItem
, nItem
+ 1 };
2474 TRACE("(nItem=%d)\n", nItem
);
2475 ranges_check(ranges
, "before contain");
2476 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
2479 static INT
ranges_itemcount(RANGES ranges
)
2483 for (i
= 0; i
< ranges
->hdpa
->nItemCount
; i
++)
2485 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
2486 count
+= sel
->upper
- sel
->lower
;
2492 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
2494 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
2497 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2498 if (index
== -1) return TRUE
;
2500 for (; index
< ranges
->hdpa
->nItemCount
; index
++)
2502 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
2503 if (chkrng
->lower
>= nItem
)
2504 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
2505 if (chkrng
->upper
> nItem
)
2506 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
2511 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
2516 TRACE("(%s)\n", debugrange(&range
));
2517 ranges_check(ranges
, "before add");
2519 /* try find overlapping regions first */
2520 srchrgn
.lower
= range
.lower
- 1;
2521 srchrgn
.upper
= range
.upper
+ 1;
2522 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
2528 TRACE("Adding new range\n");
2530 /* create the brand new range to insert */
2531 newrgn
= (RANGE
*)COMCTL32_Alloc(sizeof(RANGE
));
2532 if(!newrgn
) goto fail
;
2535 /* figure out where to insert it */
2536 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2537 TRACE("index=%d\n", index
);
2538 if (index
== -1) index
= 0;
2540 /* and get it over with */
2541 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
2543 COMCTL32_Free(newrgn
);
2549 RANGE
*chkrgn
, *mrgrgn
;
2550 INT fromindex
, mergeindex
;
2552 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
2553 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
2555 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
2556 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
2558 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
2560 /* merge now common anges */
2562 srchrgn
.lower
= chkrgn
->lower
- 1;
2563 srchrgn
.upper
= chkrgn
->upper
+ 1;
2567 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
2568 if (mergeindex
== -1) break;
2569 if (mergeindex
== index
)
2571 fromindex
= index
+ 1;
2575 TRACE("Merge with index %i\n", mergeindex
);
2577 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
2578 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
2579 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
2580 COMCTL32_Free(mrgrgn
);
2581 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
2582 if (mergeindex
< index
) index
--;
2586 ranges_check(ranges
, "after add");
2590 ranges_check(ranges
, "failed add");
2594 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
2599 TRACE("(%s)\n", debugrange(&range
));
2600 ranges_check(ranges
, "before del");
2602 /* we don't use DPAS_SORTED here, since we need *
2603 * to find the first overlapping range */
2604 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
2607 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
2609 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
2611 /* case 1: Same range */
2612 if ( (chkrgn
->upper
== range
.upper
) &&
2613 (chkrgn
->lower
== range
.lower
) )
2615 DPA_DeletePtr(ranges
->hdpa
, index
);
2618 /* case 2: engulf */
2619 else if ( (chkrgn
->upper
<= range
.upper
) &&
2620 (chkrgn
->lower
>= range
.lower
) )
2622 DPA_DeletePtr(ranges
->hdpa
, index
);
2624 /* case 3: overlap upper */
2625 else if ( (chkrgn
->upper
<= range
.upper
) &&
2626 (chkrgn
->lower
< range
.lower
) )
2628 chkrgn
->upper
= range
.lower
;
2630 /* case 4: overlap lower */
2631 else if ( (chkrgn
->upper
> range
.upper
) &&
2632 (chkrgn
->lower
>= range
.lower
) )
2634 chkrgn
->lower
= range
.upper
;
2637 /* case 5: fully internal */
2640 RANGE tmprgn
= *chkrgn
, *newrgn
;
2642 if (!(newrgn
= (RANGE
*)COMCTL32_Alloc(sizeof(RANGE
)))) goto fail
;
2643 newrgn
->lower
= chkrgn
->lower
;
2644 newrgn
->upper
= range
.lower
;
2645 chkrgn
->lower
= range
.upper
;
2646 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
2648 COMCTL32_Free(newrgn
);
2655 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
2658 ranges_check(ranges
, "after del");
2662 ranges_check(ranges
, "failed del");
2668 * Removes all selection ranges
2671 * [I] infoPtr : valid pointer to the listview structure
2672 * [I] toSkip : item range to skip removing the selection
2678 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
2687 lvItem
.stateMask
= LVIS_SELECTED
;
2689 /* need to clone the DPA because callbacks can change it */
2690 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
2691 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
2692 while(iterator_next(&i
))
2693 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
2694 /* note that the iterator destructor will free the cloned range */
2695 iterator_destroy(&i
);
2700 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2704 if (!(toSkip
= ranges_create(1))) return FALSE
;
2705 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
2706 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
2707 ranges_destroy(toSkip
);
2711 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
2713 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
2718 * Retrieves the number of items that are marked as selected.
2721 * [I] infoPtr : valid pointer to the listview structure
2724 * Number of items selected.
2726 static INT
LISTVIEW_GetSelectedCount(LISTVIEW_INFO
*infoPtr
)
2728 INT nSelectedCount
= 0;
2730 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
2733 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2735 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
2740 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
2742 TRACE("nSelectedCount=%d\n", nSelectedCount
);
2743 return nSelectedCount
;
2748 * Manages the item focus.
2751 * [I] infoPtr : valid pointer to the listview structure
2752 * [I] nItem : item index
2755 * TRUE : focused item changed
2756 * FALSE : focused item has NOT changed
2758 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2760 INT oldFocus
= infoPtr
->nFocusedItem
;
2763 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
2765 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
2766 lvItem
.stateMask
= LVIS_FOCUSED
;
2767 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
2769 return oldFocus
!= infoPtr
->nFocusedItem
;
2772 /* Helper function for LISTVIEW_ShiftIndices *only* */
2773 static INT
shift_item(LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
2775 if (nShiftItem
< nItem
) return nShiftItem
;
2777 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
2779 if (direction
> 0) return nShiftItem
+ direction
;
2781 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
2786 * Updates the various indices after an item has been inserted or deleted.
2789 * [I] infoPtr : valid pointer to the listview structure
2790 * [I] nItem : item index
2791 * [I] direction : Direction of shift, +1 or -1.
2796 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
2800 TRACE("Shifting %iu, %i steps\n", nItem
, direction
);
2802 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
2804 assert(abs(direction
) == 1);
2806 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
2808 nNewFocus
= shift_item(infoPtr
, infoPtr
->nFocusedItem
, nItem
, direction
);
2809 if (nNewFocus
!= infoPtr
->nFocusedItem
)
2810 LISTVIEW_SetItemFocus(infoPtr
, nNewFocus
);
2812 /* But we are not supposed to modify nHotItem! */
2818 * Adds a block of selections.
2821 * [I] infoPtr : valid pointer to the listview structure
2822 * [I] nItem : item index
2827 static void LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2829 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
2830 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
2834 if (nFirst
== -1) nFirst
= nItem
;
2836 item
.state
= LVIS_SELECTED
;
2837 item
.stateMask
= LVIS_SELECTED
;
2839 /* FIXME: this is not correct LVS_OWNERDATA
2840 * setting the item states individually will generate
2841 * a LVN_ITEMCHANGED notification for each one. Instead,
2842 * we have to send a LVN_ODSTATECHANGED notification.
2843 * See MSDN documentation for LVN_ITEMCHANGED.
2845 for (i
= nFirst
; i
<= nLast
; i
++)
2846 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
2852 * Sets a single group selection.
2855 * [I] infoPtr : valid pointer to the listview structure
2856 * [I] nItem : item index
2861 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2863 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2868 if (!(selection
= ranges_create(100))) return;
2870 item
.state
= LVIS_SELECTED
;
2871 item
.stateMask
= LVIS_SELECTED
;
2873 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
2875 if (infoPtr
->nSelectionMark
== -1)
2877 infoPtr
->nSelectionMark
= nItem
;
2878 ranges_additem(selection
, nItem
);
2884 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
2885 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
2886 ranges_add(selection
, sel
);
2891 RECT rcItem
, rcSel
, rcSelMark
;
2894 rcItem
.left
= LVIR_BOUNDS
;
2895 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return;
2896 rcSelMark
.left
= LVIR_BOUNDS
;
2897 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) return;
2898 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
2899 iterator_frameditems(&i
, infoPtr
, &rcSel
);
2900 while(iterator_next(&i
))
2902 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
2903 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
2905 iterator_destroy(&i
);
2908 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
2909 iterator_rangesitems(&i
, selection
);
2910 while(iterator_next(&i
))
2911 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
2912 /* this will also destroy the selection */
2913 iterator_destroy(&i
);
2915 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
2920 * Sets a single selection.
2923 * [I] infoPtr : valid pointer to the listview structure
2924 * [I] nItem : item index
2929 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2933 TRACE("nItem=%d\n", nItem
);
2935 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
2937 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
2938 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
2939 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
2941 infoPtr
->nSelectionMark
= nItem
;
2946 * Set selection(s) with keyboard.
2949 * [I] infoPtr : valid pointer to the listview structure
2950 * [I] nItem : item index
2953 * SUCCESS : TRUE (needs to be repainted)
2954 * FAILURE : FALSE (nothing has changed)
2956 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2958 /* FIXME: pass in the state */
2959 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
2960 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
2961 BOOL bResult
= FALSE
;
2963 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
2965 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
2968 LISTVIEW_SetSelection(infoPtr
, nItem
);
2975 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
2979 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
2984 LISTVIEW_SetSelection(infoPtr
, nItem
);
2987 ListView_EnsureVisible(infoPtr
->hwndSelf
, nItem
, FALSE
);
2990 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
2997 * Called when the mouse is being actively tracked and has hovered for a specified
3001 * [I] infoPtr : valid pointer to the listview structure
3002 * [I] fwKeys : key indicator
3003 * [I] pts : mouse position
3006 * 0 if the message was processed, non-zero if there was an error
3009 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3010 * over the item for a certain period of time.
3013 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, WORD fwKyes
, POINTS pts
)
3015 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
3016 /* FIXME: select the item!!! */
3017 /*LISTVIEW_GetItemAtPt(infoPtr, pt)*/;
3024 * Called whenever WM_MOUSEMOVE is received.
3027 * [I] infoPtr : valid pointer to the listview structure
3028 * [I] fwKeys : key indicator
3029 * [I] pts : mouse position
3032 * 0 if the message is processed, non-zero if there was an error
3034 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, POINTS pts
)
3036 TRACKMOUSEEVENT trackinfo
;
3038 /* see if we are supposed to be tracking mouse hovering */
3039 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) {
3040 /* fill in the trackinfo struct */
3041 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
3042 trackinfo
.dwFlags
= TME_QUERY
;
3043 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
3044 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
3046 /* see if we are already tracking this hwnd */
3047 _TrackMouseEvent(&trackinfo
);
3049 if(!(trackinfo
.dwFlags
& TME_HOVER
)) {
3050 trackinfo
.dwFlags
= TME_HOVER
;
3052 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
3053 _TrackMouseEvent(&trackinfo
);
3062 * Tests wheather the item is assignable to a list with style lStyle
3064 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
3066 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
3067 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
3068 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
3076 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
3079 * [I] infoPtr : valid pointer to the listview structure
3080 * [I] lpLVItem : valid pointer to new item atttributes
3081 * [I] isNew : the item being set is being inserted
3082 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3083 * [O] bChanged : will be set to TRUE if the item really changed
3089 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
3098 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
3100 if (lpLVItem
->mask
== 0) return TRUE
;
3102 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3104 /* a virtual listview we stores only selection and focus */
3105 if ((lpLVItem
->mask
& ~LVIF_STATE
) || (lpLVItem
->stateMask
& ~(LVIS_FOCUSED
| LVIS_SELECTED
)))
3111 HDPA hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3112 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
3116 /* we need to get the lParam and state of the item */
3117 item
.iItem
= lpLVItem
->iItem
;
3118 item
.iSubItem
= lpLVItem
->iSubItem
;
3119 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
3120 item
.stateMask
= ~0;
3123 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
3125 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
3126 /* determine what fields will change */
3127 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
))
3128 uChanged
|= LVIF_STATE
;
3130 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
3131 uChanged
|= LVIF_IMAGE
;
3133 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
3134 uChanged
|= LVIF_PARAM
;
3136 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
3137 uChanged
|= LVIF_INDENT
;
3139 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
3140 uChanged
|= LVIF_TEXT
;
3142 TRACE("uChanged=0x%x\n", uChanged
);
3143 if (!uChanged
) return TRUE
;
3146 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
3147 nmlv
.iItem
= lpLVItem
->iItem
;
3148 nmlv
.uNewState
= (item
.state
& ~lpLVItem
->stateMask
) | (lpLVItem
->state
& lpLVItem
->stateMask
);
3149 nmlv
.uOldState
= item
.state
;
3150 nmlv
.uChanged
= uChanged
;
3151 nmlv
.lParam
= item
.lParam
;
3153 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
3154 /* and we are _NOT_ virtual (LVS_OWERNDATA) */
3155 if(lpItem
&& !isNew
&& notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
3158 /* copy information */
3159 if (lpLVItem
->mask
& LVIF_TEXT
)
3160 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3162 if (lpLVItem
->mask
& LVIF_IMAGE
)
3163 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
3165 if (lpLVItem
->mask
& LVIF_PARAM
)
3166 lpItem
->lParam
= lpLVItem
->lParam
;
3168 if (lpLVItem
->mask
& LVIF_INDENT
)
3169 lpItem
->iIndent
= lpLVItem
->iIndent
;
3171 if (uChanged
& LVIF_STATE
)
3173 if (lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& ~(LVIS_FOCUSED
| LVIS_SELECTED
))
3175 lpItem
->state
&= ~lpLVItem
->stateMask
;
3176 lpItem
->state
|= (lpLVItem
->state
& lpLVItem
->stateMask
);
3178 if (lpLVItem
->state
& lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3180 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
3181 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3183 else if (lpLVItem
->stateMask
& LVIS_SELECTED
)
3184 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3186 /* if we are asked to change focus, and we manage it, do it */
3187 if (lpLVItem
->state
& lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
3189 if (lpLVItem
->state
& LVIS_FOCUSED
)
3191 LISTVIEW_SetItemFocus(infoPtr
, -1);
3192 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
3193 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, FALSE
);
3195 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
3196 infoPtr
->nFocusedItem
= -1;
3200 /* if we're inserting the item, we're done */
3201 if (isNew
) return TRUE
;
3203 /* send LVN_ITEMCHANGED notification */
3204 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
3205 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
3212 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
3215 * [I] infoPtr : valid pointer to the listview structure
3216 * [I] lpLVItem : valid pointer to new subitem atttributes
3217 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3218 * [O] bChanged : will be set to TRUE if the item really changed
3224 static BOOL
set_sub_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
3227 SUBITEM_INFO
*lpSubItem
;
3229 /* we do not support subitems for virtual listviews */
3230 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
3232 /* set subitem only if column is present */
3233 if (lpLVItem
->iSubItem
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
3235 /* First do some sanity checks */
3236 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
)) return FALSE
;
3237 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
))) return TRUE
;
3239 /* get the subitem structure, and create it if not there */
3240 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3241 assert (hdpaSubItems
);
3243 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
3246 SUBITEM_INFO
*tmpSubItem
;
3249 lpSubItem
= (SUBITEM_INFO
*)COMCTL32_Alloc(sizeof(SUBITEM_INFO
));
3250 if (!lpSubItem
) return FALSE
;
3251 /* we could binary search here, if need be...*/
3252 for (i
= 1; i
< hdpaSubItems
->nItemCount
; i
++)
3254 tmpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
3255 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
3257 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
3259 COMCTL32_Free(lpSubItem
);
3262 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
3266 if (lpLVItem
->mask
& LVIF_IMAGE
)
3267 if (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
)
3269 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
3273 if (lpLVItem
->mask
& LVIF_TEXT
)
3274 if (lpSubItem
->hdr
.pszText
!= lpLVItem
->pszText
)
3276 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3285 * Sets item attributes.
3288 * [I] infoPtr : valid pointer to the listview structure
3289 * [I] lpLVItem : new item atttributes
3290 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3296 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
3298 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3299 LPWSTR pszText
= NULL
;
3300 BOOL bResult
, bChanged
= FALSE
;
3302 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
3304 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
3307 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
3308 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_textW(lpLVItem
->pszText
))
3310 pszText
= lpLVItem
->pszText
;
3311 ((LVITEMW
*)lpLVItem
)->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
3314 /* actually set the fields */
3315 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
3317 if (lpLVItem
->iSubItem
)
3318 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
3320 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
3322 /* redraw item, if necessary */
3323 if (bChanged
&& !infoPtr
->bIsDrawing
)
3325 /* this little optimization eliminates some nasty flicker */
3326 if ( uView
== LVS_REPORT
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
3327 (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || lpLVItem
->iSubItem
) )
3328 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
3330 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
3335 textfreeT(lpLVItem
->pszText
, isW
);
3336 ((LVITEMW
*)lpLVItem
)->pszText
= pszText
;
3344 * Retrieves the index of the item at coordinate (0, 0) of the client area.
3347 * [I] infoPtr : valid pointer to the listview structure
3352 static INT
LISTVIEW_GetTopIndex(LISTVIEW_INFO
*infoPtr
)
3354 LONG lStyle
= infoPtr
->dwStyle
;
3355 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3357 SCROLLINFO scrollInfo
;
3359 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3360 scrollInfo
.fMask
= SIF_POS
;
3362 if (uView
== LVS_LIST
)
3364 if ((lStyle
& WS_HSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3365 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
3367 else if (uView
== LVS_REPORT
)
3369 if ((lStyle
& WS_VSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3370 nItem
= scrollInfo
.nPos
;
3374 if ((lStyle
& WS_VSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3375 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
3378 TRACE("nItem=%d\n", nItem
);
3386 * Erases the background of the given rectangle
3389 * [I] infoPtr : valid pointer to the listview structure
3390 * [I] hdc : device context handle
3391 * [I] lprcBox : clipping rectangle
3397 static inline BOOL
LISTVIEW_FillBkgnd(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
3399 if (!infoPtr
->hBkBrush
) return FALSE
;
3401 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, debugrect(lprcBox
), infoPtr
->hBkBrush
);
3403 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
3411 * [I] infoPtr : valid pointer to the listview structure
3412 * [I] hdc : device context handle
3413 * [I] nItem : item index
3414 * [I] nSubItem : subitem index
3415 * [I] pos : item position in client coordinates
3416 * [I] cdmode : custom draw mode
3422 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
3424 UINT uFormat
, uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3425 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
3426 WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
3427 DWORD cditemmode
= CDRF_DODEFAULT
;
3428 RECT
* lprcFocus
, rcSelect
, rcBox
, rcState
, rcIcon
, rcLabel
;
3429 NMLVCUSTOMDRAW nmlvcd
;
3433 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, debugpoint(&pos
));
3435 /* get information needed for drawing the item */
3436 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
3437 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
| LVIF_PARAM
;
3438 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
3439 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
;
3440 lvItem
.iItem
= nItem
;
3441 lvItem
.iSubItem
= nSubItem
;
3444 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
3445 lvItem
.pszText
= szDispText
;
3446 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
3447 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3448 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3449 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
3450 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
3452 /* now check if we need to update the focus rectangle */
3453 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
3455 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
3456 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcState
, &rcIcon
, &rcLabel
);
3457 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
3458 OffsetRect(&rcState
, pos
.x
, pos
.y
);
3459 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
3460 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
3461 TRACE(" rcBox=%s, rcState=%s, rcIcon=%s. rcLabel=%s\n",
3462 debugrect(&rcBox
), debugrect(&rcState
), debugrect(&rcIcon
), debugrect(&rcLabel
));
3464 /* fill in the custom draw structure */
3465 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
);
3466 nmlvcd
.nmcd
.dwItemSpec
= lvItem
.iItem
;
3467 nmlvcd
.iSubItem
= lvItem
.iSubItem
;
3468 if (lvItem
.state
& LVIS_SELECTED
) nmlvcd
.nmcd
.uItemState
|= CDIS_SELECTED
;
3469 if (lvItem
.state
& LVIS_FOCUSED
) nmlvcd
.nmcd
.uItemState
|= CDIS_FOCUS
;
3470 if (lvItem
.iItem
== infoPtr
->nHotItem
) nmlvcd
.nmcd
.uItemState
|= CDIS_HOT
;
3471 nmlvcd
.nmcd
.lItemlParam
= lvItem
.lParam
;
3473 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
3474 cditemmode
= notify_customdraw (infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
3475 if (cditemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
3477 /* apprently, for selected items, we have to override the returned values */
3478 if (lvItem
.state
& LVIS_SELECTED
)
3480 if (infoPtr
->bFocus
)
3482 nmlvcd
.clrTextBk
= comctl32_color
.clrHighlight
;
3483 nmlvcd
.clrText
= comctl32_color
.clrHighlightText
;
3485 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
3487 nmlvcd
.clrTextBk
= comctl32_color
.clr3dFace
;
3488 nmlvcd
.clrText
= comctl32_color
.clrBtnText
;
3492 /* in full row select, subitems, will just use main item's colors */
3493 if (nSubItem
&& uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3494 nmlvcd
.clrTextBk
= CLR_NONE
;
3497 if (infoPtr
->himlState
&& !IsRectEmpty(&rcState
))
3499 UINT uStateImage
= (lvItem
.state
& LVIS_STATEIMAGEMASK
) >> 12;
3502 TRACE("uStateImage=%d\n", uStateImage
);
3503 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
, rcState
.left
, rcState
.top
, ILD_NORMAL
);
3508 himl
= (uView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
3509 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
3511 TRACE("iImage=%d\n", lvItem
.iImage
);
3512 ImageList_Draw(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
3513 (lvItem
.state
& LVIS_SELECTED
) && (infoPtr
->bFocus
) ? ILD_SELECTED
: ILD_NORMAL
);
3516 /* Don't bother painting item being edited */
3517 if (infoPtr
->hwndEdit
&& lprcFocus
&& nSubItem
== 0) goto postpaint
;
3519 /* Set the text attributes */
3520 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
3522 SetBkMode(hdc
, OPAQUE
);
3523 SetBkColor(hdc
, nmlvcd
.clrTextBk
== CLR_DEFAULT
? infoPtr
->clrTextBkDefault
: nmlvcd
.clrTextBk
);
3526 SetBkMode(hdc
, TRANSPARENT
);
3527 SetTextColor(hdc
, nmlvcd
.clrText
);
3529 /* draw the selection background, if we're drawing the main item */
3533 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3534 rcSelect
.right
= rcBox
.right
;
3536 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
3537 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, 0, 0, 0);
3538 if(lprcFocus
) *lprcFocus
= rcSelect
;
3541 /* figure out the text drawing flags */
3542 uFormat
= (uView
== LVS_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
3543 if (uView
== LVS_ICON
)
3544 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
3547 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
3549 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
3550 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
3551 default: uFormat
|= DT_LEFT
;
3554 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
))) rcLabel
.left
+= 2;
3555 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
3558 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
3559 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
3565 * Draws listview items when in owner draw mode.
3568 * [I] infoPtr : valid pointer to the listview structure
3569 * [I] hdc : device context handle
3574 static void LISTVIEW_RefreshOwnerDraw(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
3576 UINT uID
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_ID
);
3577 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
3578 POINT Origin
, Position
;
3585 ZeroMemory(&dis
, sizeof(dis
));
3587 /* Get scroll info once before loop */
3588 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3590 /* figure out what we need to draw */
3591 iterator_visibleitems(&i
, infoPtr
, hdc
);
3593 /* send cache hint notification */
3594 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3596 RANGE range
= iterator_range(&i
);
3599 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
3600 nmlv
.iFrom
= range
.lower
;
3601 nmlv
.iTo
= range
.upper
- 1;
3602 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
3605 /* iterate through the invalidated rows */
3606 while(iterator_next(&i
))
3608 item
.iItem
= i
.nItem
;
3610 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
3611 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
3612 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
3614 dis
.CtlType
= ODT_LISTVIEW
;
3616 dis
.itemID
= item
.iItem
;
3617 dis
.itemAction
= ODA_DRAWENTIRE
;
3619 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
3620 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
3621 dis
.hwndItem
= infoPtr
->hwndSelf
;
3623 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
3624 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
3625 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
3626 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
3627 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
3628 dis
.itemData
= item
.lParam
;
3630 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), debugrect(&dis
.rcItem
));
3631 SendMessageW(hwndParent
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
3633 iterator_destroy(&i
);
3638 * Draws listview items when in report display mode.
3641 * [I] infoPtr : valid pointer to the listview structure
3642 * [I] hdc : device context handle
3643 * [I] cdmode : custom draw mode
3648 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD cdmode
)
3651 RECT rcClip
, rcItem
;
3652 POINT Origin
, Position
;
3658 /* figure out what to draw */
3659 rgntype
= GetClipBox(hdc
, &rcClip
);
3660 if (rgntype
== NULLREGION
) return;
3662 /* Get scroll info once before loop */
3663 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3665 /* narrow down the columns we need to paint */
3666 for(colRange
.lower
= 0; colRange
.lower
< infoPtr
->hdpaColumns
->nItemCount
; colRange
.lower
++)
3668 LISTVIEW_GetHeaderRect(infoPtr
, colRange
.lower
, &rcItem
);
3669 if (rcItem
.right
+ Origin
.x
>= rcClip
.left
) break;
3671 for(colRange
.upper
= infoPtr
->hdpaColumns
->nItemCount
; colRange
.upper
> 0; colRange
.upper
--)
3673 LISTVIEW_GetHeaderRect(infoPtr
, colRange
.upper
- 1, &rcItem
);
3674 if (rcItem
.left
+ Origin
.x
< rcClip
.right
) break;
3676 iterator_rangeitems(&j
, colRange
);
3678 /* in full row select, we _have_ to draw the main item */
3679 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
3682 /* figure out what we need to draw */
3683 iterator_visibleitems(&i
, infoPtr
, hdc
);
3685 /* iterate through the invalidated rows */
3686 while(iterator_next(&i
))
3688 /* iterate through the invalidated columns */
3689 while(iterator_next(&j
))
3691 LISTVIEW_GetItemOrigin(infoPtr
, i
.nItem
, &Position
);
3692 Position
.x
+= Origin
.x
;
3693 Position
.y
+= Origin
.y
;
3695 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
3697 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
3699 rcItem
.bottom
= infoPtr
->nItemHeight
;
3700 OffsetRect(&rcItem
, Position
.x
, Position
.y
);
3701 if (!RectVisible(hdc
, &rcItem
)) continue;
3704 LISTVIEW_DrawItem(infoPtr
, hdc
, i
.nItem
, j
.nItem
, Position
, cdmode
);
3707 iterator_destroy(&i
);
3712 * Draws listview items when in list display mode.
3715 * [I] infoPtr : valid pointer to the listview structure
3716 * [I] hdc : device context handle
3717 * [I] cdmode : custom draw mode
3722 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD cdmode
)
3724 POINT Origin
, Position
;
3727 /* Get scroll info once before loop */
3728 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3730 /* figure out what we need to draw */
3731 iterator_visibleitems(&i
, infoPtr
, hdc
);
3733 while(iterator_prev(&i
))
3735 LISTVIEW_GetItemOrigin(infoPtr
, i
.nItem
, &Position
);
3736 Position
.x
+= Origin
.x
;
3737 Position
.y
+= Origin
.y
;
3739 LISTVIEW_DrawItem(infoPtr
, hdc
, i
.nItem
, 0, Position
, cdmode
);
3741 iterator_destroy(&i
);
3747 * Draws listview items.
3750 * [I] infoPtr : valid pointer to the listview structure
3751 * [I] hdc : device context handle
3756 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
3758 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3759 COLORREF oldTextColor
, oldClrTextBk
, oldClrText
;
3760 NMLVCUSTOMDRAW nmlvcd
;
3766 LISTVIEW_DUMP(infoPtr
);
3768 infoPtr
->bIsDrawing
= TRUE
;
3770 /* save dc values we're gonna trash while drawing */
3771 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3772 oldBkMode
= GetBkMode(hdc
);
3773 infoPtr
->clrTextBkDefault
= GetBkColor(hdc
);
3774 oldTextColor
= GetTextColor(hdc
);
3776 oldClrTextBk
= infoPtr
->clrTextBk
;
3777 oldClrText
= infoPtr
->clrText
;
3779 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
3780 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
);
3781 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
3782 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
3784 /* Use these colors to draw the items */
3785 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
3786 infoPtr
->clrText
= nmlvcd
.clrText
;
3788 /* nothing to draw */
3789 if(infoPtr
->nItemCount
== 0) goto enddraw
;
3791 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (uView
== LVS_REPORT
))
3792 LISTVIEW_RefreshOwnerDraw(infoPtr
, hdc
);
3795 if (uView
== LVS_REPORT
)
3796 LISTVIEW_RefreshReport(infoPtr
, hdc
, cdmode
);
3797 else /* LVS_LIST, LVS_ICON or LVS_SMALLICON */
3798 LISTVIEW_RefreshList(infoPtr
, hdc
, cdmode
);
3800 /* if we have a focus rect, draw it */
3801 if (infoPtr
->bFocus
)
3802 DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
3806 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
3807 notify_customdraw(infoPtr
, CDDS_POSTPAINT
, &nmlvcd
);
3809 infoPtr
->clrTextBk
= oldClrTextBk
;
3810 infoPtr
->clrText
= oldClrText
;
3812 SelectObject(hdc
, hOldFont
);
3813 SetBkMode(hdc
, oldBkMode
);
3814 SetBkColor(hdc
, infoPtr
->clrTextBkDefault
);
3815 SetTextColor(hdc
, oldTextColor
);
3816 infoPtr
->bIsDrawing
= FALSE
;
3822 * Calculates the approximate width and height of a given number of items.
3825 * [I] infoPtr : valid pointer to the listview structure
3826 * [I] nItemCount : number of items
3827 * [I] wWidth : width
3828 * [I] wHeight : height
3831 * Returns a DWORD. The width in the low word and the height in high word.
3833 static DWORD
LISTVIEW_ApproximateViewRect(LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
3834 WORD wWidth
, WORD wHeight
)
3836 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3837 INT nItemCountPerColumn
= 1;
3838 INT nColumnCount
= 0;
3839 DWORD dwViewRect
= 0;
3841 if (nItemCount
== -1)
3842 nItemCount
= infoPtr
->nItemCount
;
3844 if (uView
== LVS_LIST
)
3846 if (wHeight
== 0xFFFF)
3848 /* use current height */
3849 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
3852 if (wHeight
< infoPtr
->nItemHeight
)
3853 wHeight
= infoPtr
->nItemHeight
;
3857 if (infoPtr
->nItemHeight
> 0)
3859 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
3860 if (nItemCountPerColumn
== 0)
3861 nItemCountPerColumn
= 1;
3863 if (nItemCount
% nItemCountPerColumn
!= 0)
3864 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
3866 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
3870 /* Microsoft padding magic */
3871 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
3872 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
3874 dwViewRect
= MAKELONG(wWidth
, wHeight
);
3876 else if (uView
== LVS_REPORT
)
3877 FIXME("uView == LVS_REPORT: not implemented\n");
3878 else if (uView
== LVS_SMALLICON
)
3879 FIXME("uView == LVS_SMALLICON: not implemented\n");
3880 else if (uView
== LVS_ICON
)
3881 FIXME("uView == LVS_ICON: not implemented\n");
3886 /* << LISTVIEW_CreateDragImage >> */
3891 * Removes all listview items and subitems.
3894 * [I] infoPtr : valid pointer to the listview structure
3900 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
)
3903 HDPA hdpaSubItems
= NULL
;
3910 /* we do it directly, to avoid notifications */
3911 ranges_clear(infoPtr
->selectionRanges
);
3912 infoPtr
->nSelectionMark
= -1;
3913 infoPtr
->nFocusedItem
= -1;
3914 SetRectEmpty(&infoPtr
->rcFocus
);
3915 /* But we are supposed to leave nHotItem as is! */
3918 /* send LVN_DELETEALLITEMS notification */
3919 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
3921 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
3923 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
3925 /* send LVN_DELETEITEM notification, if not supressed */
3926 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
3927 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
3929 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, i
);
3930 for (j
= 0; j
< hdpaSubItems
->nItemCount
; j
++)
3932 hdrItem
= (ITEMHDR
*)DPA_GetPtr(hdpaSubItems
, j
);
3933 if (is_textW(hdrItem
->pszText
)) COMCTL32_Free(hdrItem
->pszText
);
3934 COMCTL32_Free(hdrItem
);
3936 DPA_Destroy(hdpaSubItems
);
3937 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
3939 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
3940 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
3941 infoPtr
->nItemCount
--;
3944 LISTVIEW_UpdateScroll(infoPtr
);
3946 LISTVIEW_InvalidateList(infoPtr
);
3953 * Scrolls, and updates the columns, when a column is changing width.
3956 * [I] infoPtr : valid pointer to the listview structure
3957 * [I] nColumn : column to scroll
3958 * [I] dx : amount of scroll, in pixels
3963 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
3965 COLUMN_INFO
*lpColumnInfo
;
3969 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, infoPtr
->hdpaColumns
->nItemCount
- 1));
3970 rcCol
= lpColumnInfo
->rcHeader
;
3971 if (nColumn
>= infoPtr
->hdpaColumns
->nItemCount
)
3972 rcCol
.left
= rcCol
.right
;
3974 /* ajust the other columns */
3975 for (nCol
= nColumn
; nCol
< infoPtr
->hdpaColumns
->nItemCount
; nCol
++)
3977 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
3978 lpColumnInfo
->rcHeader
.left
+= dx
;
3979 lpColumnInfo
->rcHeader
.right
+= dx
;
3982 /* do not update screen if not in report mode */
3983 if (!is_redrawing(infoPtr
) || (infoPtr
->dwStyle
& LVS_TYPEMASK
) != LVS_REPORT
) return;
3985 /* if we have a focus, must first erase the focus rect */
3986 if (infoPtr
->bFocus
) LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
3988 /* Need to reset the item width when inserting a new column */
3989 infoPtr
->nItemWidth
+= dx
;
3991 LISTVIEW_UpdateScroll(infoPtr
);
3993 /* scroll to cover the deleted column, and invalidate for redraw */
3994 rcOld
= infoPtr
->rcList
;
3995 rcOld
.left
= rcCol
.left
;
3996 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
3998 /* we can restore focus now */
3999 if (infoPtr
->bFocus
) LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
4004 * Removes a column from the listview control.
4007 * [I] infoPtr : valid pointer to the listview structure
4008 * [I] nColumn : column index
4014 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
4018 TRACE("nColumn=%d\n", nColumn
);
4020 if (nColumn
<= 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
4022 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
4024 if (!Header_DeleteItem(infoPtr
->hwndHeader
, nColumn
))
4027 COMCTL32_Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
4028 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
4030 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4032 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
4034 INT nItem
, nSubItem
, i
;
4036 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
4038 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
4041 for (i
= 1; i
< hdpaSubItems
->nItemCount
; i
++)
4043 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
4044 if (lpSubItem
->iSubItem
== nColumn
)
4047 lpDelItem
= lpSubItem
;
4049 else if (lpSubItem
->iSubItem
> nColumn
)
4051 lpSubItem
->iSubItem
--;
4055 /* if we found our subitem, zapp it */
4059 if (is_textW(lpDelItem
->hdr
.pszText
))
4060 COMCTL32_Free(lpDelItem
->hdr
.pszText
);
4063 COMCTL32_Free(lpDelItem
);
4065 /* free dpa memory */
4066 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
4071 /* update the other column info */
4072 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
4079 * Invalidates the listview after an item's insertion or deletion.
4082 * [I] infoPtr : valid pointer to the listview structure
4083 * [I] nItem : item index
4084 * [I] dir : -1 if deleting, 1 if inserting
4089 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
4091 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4092 INT nPerCol
, nItemCol
, nItemRow
;
4096 /* if we don't refresh, what's the point of scrolling? */
4097 if (!is_redrawing(infoPtr
)) return;
4099 assert (abs(dir
) == 1);
4101 /* arrange icons if autoarrange is on */
4102 if (is_autoarrange(infoPtr
))
4104 BOOL arrange
= TRUE
;
4105 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
4106 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
4107 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
4110 /* scrollbars need updating */
4111 LISTVIEW_UpdateScroll(infoPtr
);
4113 /* figure out the item's position */
4114 if (uView
== LVS_REPORT
)
4115 nPerCol
= infoPtr
->nItemCount
+ 1;
4116 else if (uView
== LVS_LIST
)
4117 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
4118 else /* LVS_ICON, or LVS_SMALLICON */
4121 nItemCol
= nItem
/ nPerCol
;
4122 nItemRow
= nItem
% nPerCol
;
4123 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4125 /* move the items below up a slot */
4126 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
4127 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
4128 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
4129 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
4130 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
4131 TRACE("rcScroll=%s, dx=%d\n", debugrect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
4132 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
4134 TRACE("Scrolling rcScroll=%s, rcList=%s\n", debugrect(&rcScroll
), debugrect(&infoPtr
->rcList
));
4135 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
4136 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4139 /* report has only that column, so we're done */
4140 if (uView
== LVS_REPORT
) return;
4142 /* now for LISTs, we have to deal with the columns to the right */
4143 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
4145 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
4146 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
4147 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
4148 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
4149 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
4150 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4155 * Removes an item from the listview control.
4158 * [I] infoPtr : valid pointer to the listview structure
4159 * [I] nItem : item index
4165 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
4167 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4170 TRACE("(nItem=%d)\n", nItem
);
4172 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
4174 /* remove selection, and focus */
4176 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4177 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
4179 /* send LVN_DELETEITEM notification. */
4180 notify_deleteitem(infoPtr
, nItem
);
4182 /* we need to do this here, because we'll be deleting stuff */
4183 if (uView
== LVS_SMALLICON
|| uView
== LVS_ICON
)
4184 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
4186 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4192 hdpaSubItems
= (HDPA
)DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
4193 for (i
= 0; i
< hdpaSubItems
->nItemCount
; i
++)
4195 hdrItem
= (ITEMHDR
*)DPA_GetPtr(hdpaSubItems
, i
);
4196 if (is_textW(hdrItem
->pszText
)) COMCTL32_Free(hdrItem
->pszText
);
4197 COMCTL32_Free(hdrItem
);
4199 DPA_Destroy(hdpaSubItems
);
4202 if (uView
== LVS_SMALLICON
|| uView
== LVS_ICON
)
4204 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
4205 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
4208 infoPtr
->nItemCount
--;
4209 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
4211 /* now is the invalidation fun */
4212 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
4219 * Callback implementation for editlabel control
4222 * [I] infoPtr : valid pointer to the listview structure
4223 * [I] pszText : modified text
4224 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
4230 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, LPWSTR pszText
, BOOL isW
)
4232 NMLVDISPINFOW dispInfo
;
4234 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
4236 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4237 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4238 dispInfo
.item
.iItem
= infoPtr
->nEditLabelItem
;
4239 dispInfo
.item
.iSubItem
= 0;
4240 dispInfo
.item
.stateMask
= ~0;
4241 if (!LISTVIEW_GetItemW(infoPtr
, &dispInfo
.item
)) return FALSE
;
4242 /* add the text from the edit in */
4243 dispInfo
.item
.mask
|= LVIF_TEXT
;
4244 dispInfo
.item
.pszText
= pszText
;
4245 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
4247 /* Do we need to update the Item Text */
4248 if (!notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
)) return FALSE
;
4249 if (!pszText
) return TRUE
;
4251 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4252 dispInfo
.item
.mask
= LVIF_TEXT
;
4253 dispInfo
.item
.iItem
= infoPtr
->nEditLabelItem
;
4254 dispInfo
.item
.iSubItem
= 0;
4255 dispInfo
.item
.pszText
= pszText
;
4256 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
4257 return LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
4262 * Begin in place editing of specified list view item
4265 * [I] infoPtr : valid pointer to the listview structure
4266 * [I] nItem : item index
4267 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
4273 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
4275 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
4276 NMLVDISPINFOW dispInfo
;
4279 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
4281 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
4282 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
4284 infoPtr
->nEditLabelItem
= nItem
;
4286 /* Is the EditBox still there, if so remove it */
4287 if(infoPtr
->hwndEdit
!= 0)
4289 SetFocus(infoPtr
->hwndSelf
);
4290 infoPtr
->hwndEdit
= 0;
4293 LISTVIEW_SetSelection(infoPtr
, nItem
);
4294 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
4296 rect
.left
= LVIR_LABEL
;
4297 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
4299 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4300 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
4301 dispInfo
.item
.iItem
= nItem
;
4302 dispInfo
.item
.iSubItem
= 0;
4303 dispInfo
.item
.stateMask
= ~0;
4304 dispInfo
.item
.pszText
= szDispText
;
4305 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
4306 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
4308 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, WS_VISIBLE
,
4309 rect
.left
-2, rect
.top
-1, 0, rect
.bottom
- rect
.top
+2, isW
);
4310 if (!infoPtr
->hwndEdit
) return 0;
4312 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
4314 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
4315 infoPtr
->hwndEdit
= 0;
4319 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
4320 SetFocus(infoPtr
->hwndEdit
);
4321 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
4322 return infoPtr
->hwndEdit
;
4328 * Ensures the specified item is visible, scrolling into view if necessary.
4331 * [I] infoPtr : valid pointer to the listview structure
4332 * [I] nItem : item index
4333 * [I] bPartial : partially or entirely visible
4339 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
4341 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4342 INT nScrollPosHeight
= 0;
4343 INT nScrollPosWidth
= 0;
4344 INT nHorzAdjust
= 0;
4345 INT nVertAdjust
= 0;
4348 RECT rcItem
, rcTemp
;
4350 rcItem
.left
= LVIR_BOUNDS
;
4351 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
4353 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
4355 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
4357 /* scroll left/right, but in LVS_REPORT mode */
4358 if (uView
== LVS_LIST
)
4359 nScrollPosWidth
= infoPtr
->nItemWidth
;
4360 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
4361 nScrollPosWidth
= 1;
4363 if (rcItem
.left
< infoPtr
->rcList
.left
)
4366 if (uView
!= LVS_REPORT
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
4371 if (uView
!= LVS_REPORT
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
4375 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
4377 /* scroll up/down, but not in LVS_LIST mode */
4378 if (uView
== LVS_REPORT
)
4379 nScrollPosHeight
= infoPtr
->nItemHeight
;
4380 else if ((uView
== LVS_ICON
) || (uView
== LVS_SMALLICON
))
4381 nScrollPosHeight
= 1;
4383 if (rcItem
.top
< infoPtr
->rcList
.top
)
4386 if (uView
!= LVS_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
4391 if (uView
!= LVS_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
4395 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
4397 if (nScrollPosWidth
)
4399 INT diff
= nHorzDiff
/ nScrollPosWidth
;
4400 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
4401 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
4404 if (nScrollPosHeight
)
4406 INT diff
= nVertDiff
/ nScrollPosHeight
;
4407 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
4408 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
4416 * Searches for an item with specific characteristics.
4419 * [I] hwnd : window handle
4420 * [I] nStart : base item index
4421 * [I] lpFindInfo : item information to look for
4424 * SUCCESS : index of item
4427 static INT
LISTVIEW_FindItemW(LISTVIEW_INFO
*infoPtr
, INT nStart
,
4428 const LVFINDINFOW
*lpFindInfo
)
4430 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4431 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4432 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
4433 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
4434 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
4435 POINT Position
, Destination
;
4438 if (!lpFindInfo
|| nItem
< 0) return -1;
4441 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
))
4443 lvItem
.mask
|= LVIF_TEXT
;
4444 lvItem
.pszText
= szDispText
;
4445 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4448 if (lpFindInfo
->flags
& LVFI_WRAP
)
4451 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
4452 (uView
== LVS_ICON
|| uView
==LVS_SMALLICON
))
4457 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4458 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
4459 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
4460 switch(lpFindInfo
->vkDirection
)
4462 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
4463 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
4464 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
4465 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
4466 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
4467 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
4468 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
4470 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
4471 Destination
.x
= rcArea
.right
;
4472 Destination
.y
= rcArea
.bottom
;
4474 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
4479 /* if LVFI_PARAM is specified, all other flags are ignored */
4480 if (lpFindInfo
->flags
& LVFI_PARAM
)
4482 lvItem
.mask
|= LVIF_PARAM
;
4484 lvItem
.mask
&= ~LVIF_TEXT
;
4488 for (; nItem
< nLast
; nItem
++)
4490 lvItem
.iItem
= nItem
;
4491 lvItem
.iSubItem
= 0;
4492 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
4494 if (lvItem
.mask
& LVIF_PARAM
)
4496 if (lpFindInfo
->lParam
== lvItem
.lParam
)
4502 if (lvItem
.mask
& LVIF_TEXT
)
4504 if (lpFindInfo
->flags
& LVFI_PARTIAL
)
4506 if (strstrW(lvItem
.pszText
, lpFindInfo
->psz
) == NULL
) continue;
4510 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
4514 if (!bNearest
) return nItem
;
4516 /* This is very inefficient. To do a good job here,
4517 * we need a sorted array of (x,y) item positions */
4518 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
4520 /* compute the distance^2 to the destination */
4521 xdist
= Destination
.x
- Position
.x
;
4522 ydist
= Destination
.y
- Position
.y
;
4523 dist
= xdist
* xdist
+ ydist
* ydist
;
4525 /* remember the distance, and item if it's closer */
4529 nNearestItem
= nItem
;
4536 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
4541 return nNearestItem
;
4546 * Searches for an item with specific characteristics.
4549 * [I] hwnd : window handle
4550 * [I] nStart : base item index
4551 * [I] lpFindInfo : item information to look for
4554 * SUCCESS : index of item
4557 static INT
LISTVIEW_FindItemA(LISTVIEW_INFO
*infoPtr
, INT nStart
,
4558 const LVFINDINFOA
*lpFindInfo
)
4560 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
);
4564 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
4565 if (hasText
) fiw
.psz
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
4566 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
4567 if (hasText
) textfreeT((LPWSTR
)fiw
.psz
, FALSE
);
4573 * Retrieves the background image of the listview control.
4576 * [I] infoPtr : valid pointer to the listview structure
4577 * [O] lpBkImage : background image attributes
4583 /* static BOOL LISTVIEW_GetBkImage(LISTVIEW_INFO *infoPtr, LPLVBKIMAGE lpBkImage) */
4585 /* FIXME (listview, "empty stub!\n"); */
4591 * Retrieves column attributes.
4594 * [I] infoPtr : valid pointer to the listview structure
4595 * [I] nColumn : column index
4596 * [IO] lpColumn : column information
4597 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
4598 * otherwise it is in fact a LPLVCOLUMNA
4604 static BOOL
LISTVIEW_GetColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
4606 COLUMN_INFO
*lpColumnInfo
;
4609 if (!lpColumn
|| nColumn
< 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
4610 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
4612 /* initialize memory */
4613 ZeroMemory(&hdi
, sizeof(hdi
));
4615 if (lpColumn
->mask
& LVCF_TEXT
)
4617 hdi
.mask
|= HDI_TEXT
;
4618 hdi
.pszText
= lpColumn
->pszText
;
4619 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
4622 if (lpColumn
->mask
& LVCF_IMAGE
)
4623 hdi
.mask
|= HDI_IMAGE
;
4625 if (lpColumn
->mask
& LVCF_ORDER
)
4626 hdi
.mask
|= HDI_ORDER
;
4628 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
4630 if (lpColumn
->mask
& LVCF_FMT
)
4631 lpColumn
->fmt
= lpColumnInfo
->fmt
;
4633 if (lpColumn
->mask
& LVCF_WIDTH
)
4634 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
4636 if (lpColumn
->mask
& LVCF_IMAGE
)
4637 lpColumn
->iImage
= hdi
.iImage
;
4639 if (lpColumn
->mask
& LVCF_ORDER
)
4640 lpColumn
->iOrder
= hdi
.iOrder
;
4646 static BOOL
LISTVIEW_GetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
4653 /* FIXME: little hack */
4654 for (i
= 0; i
< iCount
; i
++)
4662 * Retrieves the column width.
4665 * [I] infoPtr : valid pointer to the listview structure
4666 * [I] int : column index
4669 * SUCCESS : column width
4672 static INT
LISTVIEW_GetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
4674 INT nColumnWidth
= 0;
4677 TRACE("nColumn=%d\n", nColumn
);
4679 /* we have a 'column' in LIST and REPORT mode only */
4680 switch(infoPtr
->dwStyle
& LVS_TYPEMASK
)
4683 nColumnWidth
= infoPtr
->nItemWidth
;
4686 if (nColumn
< 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return 0;
4687 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
4688 nColumnWidth
= rcHeader
.right
- rcHeader
.left
;
4692 TRACE("nColumnWidth=%d\n", nColumnWidth
);
4693 return nColumnWidth
;
4698 * In list or report display mode, retrieves the number of items that can fit
4699 * vertically in the visible area. In icon or small icon display mode,
4700 * retrieves the total number of visible items.
4703 * [I] infoPtr : valid pointer to the listview structure
4706 * Number of fully visible items.
4708 static INT
LISTVIEW_GetCountPerPage(LISTVIEW_INFO
*infoPtr
)
4710 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
4714 return infoPtr
->nItemCount
;
4716 return LISTVIEW_GetCountPerColumn(infoPtr
);
4718 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
4725 * Retrieves an image list handle.
4728 * [I] infoPtr : valid pointer to the listview structure
4729 * [I] nImageList : image list identifier
4732 * SUCCESS : image list handle
4735 static HIMAGELIST
LISTVIEW_GetImageList(LISTVIEW_INFO
*infoPtr
, INT nImageList
)
4739 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
4740 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
4741 case LVSIL_STATE
: return infoPtr
->himlState
;
4746 /* LISTVIEW_GetISearchString */
4750 * Retrieves item attributes.
4753 * [I] hwnd : window handle
4754 * [IO] lpLVItem : item info
4755 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
4756 * if FALSE, the lpLVItem is a LPLVITEMA.
4759 * This is the internal 'GetItem' interface -- it tries to
4760 * be smart, and avoids text copies, if possible, by modifing
4761 * lpLVItem->pszText to point to the text string. Please note
4762 * that this is not always possible (e.g. OWNERDATA), so on
4763 * entry you *must* supply valid values for pszText, and cchTextMax.
4764 * The only difference to the documented interface is that upon
4765 * return, you should use *only* the lpLVItem->pszText, rather than
4766 * the buffer pointer you provided on input. Most code already does
4767 * that, so it's not a problem.
4768 * For the two cases when the text must be copied (that is,
4769 * for LVM_GETITEM, and LVMGETITEMTEXT), use LISTVIEW_GetItemExtT.
4775 static BOOL
LISTVIEW_GetItemT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
4777 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
4778 NMLVDISPINFOW dispInfo
;
4783 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4785 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4788 if (lpLVItem
->mask
== 0) return TRUE
;
4790 /* a quick optimization if all we're asked is the focus state
4791 * these queries are worth optimising since they are common,
4792 * and can be answered in constant time, without the heavy accesses */
4793 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
4794 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
4796 lpLVItem
->state
= 0;
4797 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4798 lpLVItem
->state
|= LVIS_FOCUSED
;
4802 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4804 /* if the app stores all the data, handle it separately */
4805 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4807 dispInfo
.item
.state
= 0;
4809 /* apprently, we should not callback for lParam in LVS_OWNERDATA */
4810 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) || infoPtr
->uCallbackMask
)
4812 /* NOTE: copy only fields which we _know_ are initialized, some apps
4813 * depend on the uninitialized fields being 0 */
4814 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
4815 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
4816 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
4817 if (lpLVItem
->mask
& LVIF_TEXT
)
4819 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
4820 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
4822 if (lpLVItem
->mask
& LVIF_STATE
)
4823 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
4824 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
4825 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
4826 *lpLVItem
= dispInfo
.item
;
4827 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
4830 /* make sure lParam is zeroed out */
4831 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
4833 /* we store only a little state, so if we're not asked, we're done */
4834 if (!(lpLVItem
->mask
& LVIF_STATE
) || lpLVItem
->iSubItem
) return TRUE
;
4836 /* if focus is handled by us, report it */
4837 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4839 lpLVItem
->state
&= ~LVIS_FOCUSED
;
4840 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4841 lpLVItem
->state
|= LVIS_FOCUSED
;
4844 /* and do the same for selection, if we handle it */
4845 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4847 lpLVItem
->state
&= ~LVIS_SELECTED
;
4848 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
4849 lpLVItem
->state
|= LVIS_SELECTED
;
4855 /* find the item and subitem structures before we proceed */
4856 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4857 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
4860 if (lpLVItem
->iSubItem
)
4862 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4863 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
4866 pItemHdr
= &lpItem
->hdr
;
4868 /* Do we need to query the state from the app? */
4869 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& lpLVItem
->iSubItem
== 0)
4871 dispInfo
.item
.mask
|= LVIF_STATE
;
4872 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
4875 /* Do we need to enquire about the image? */
4876 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
4877 dispInfo
.item
.mask
|= LVIF_IMAGE
;
4879 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
4880 if ((lpLVItem
->mask
& LVIF_TEXT
) && !is_textW(pItemHdr
->pszText
))
4882 dispInfo
.item
.mask
|= LVIF_TEXT
;
4883 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
4884 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
4885 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
4886 *dispInfo
.item
.pszText
= '\0';
4889 /* If we don't have all the requested info, query the application */
4890 if (dispInfo
.item
.mask
!= 0)
4892 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
4893 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
4894 dispInfo
.item
.lParam
= lpItem
->lParam
;
4895 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
4896 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
4899 /* we should not store values for subitems */
4900 if (lpLVItem
->iSubItem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
4902 /* Now, handle the iImage field */
4903 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
4905 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
4906 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
4907 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
4909 else if (lpLVItem
->mask
& LVIF_IMAGE
)
4910 lpLVItem
->iImage
= pItemHdr
->iImage
;
4912 /* The pszText field */
4913 if (dispInfo
.item
.mask
& LVIF_TEXT
)
4915 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
4916 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
4918 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
4920 else if (lpLVItem
->mask
& LVIF_TEXT
)
4922 if (isW
) lpLVItem
->pszText
= pItemHdr
->pszText
;
4923 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
4926 /* if this is a subitem, we're done */
4927 if (lpLVItem
->iSubItem
) return TRUE
;
4929 /* Next is the lParam field */
4930 if (dispInfo
.item
.mask
& LVIF_PARAM
)
4932 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
4933 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
4934 lpItem
->lParam
= dispInfo
.item
.lParam
;
4936 else if (lpLVItem
->mask
& LVIF_PARAM
)
4937 lpLVItem
->lParam
= lpItem
->lParam
;
4939 /* ... the state field (this one is different due to uCallbackmask) */
4940 if (lpLVItem
->mask
& LVIF_STATE
)
4942 lpLVItem
->state
= lpItem
->state
;
4943 if (dispInfo
.item
.mask
& LVIF_STATE
)
4945 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
4946 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
4948 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4950 lpLVItem
->state
&= ~LVIS_FOCUSED
;
4951 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4952 lpLVItem
->state
|= LVIS_FOCUSED
;
4954 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4956 lpLVItem
->state
&= ~LVIS_SELECTED
;
4957 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
4958 lpLVItem
->state
|= LVIS_SELECTED
;
4962 /* and last, but not least, the indent field */
4963 if (lpLVItem
->mask
& LVIF_INDENT
)
4964 lpLVItem
->iIndent
= lpItem
->iIndent
;
4971 * Retrieves item attributes.
4974 * [I] hwnd : window handle
4975 * [IO] lpLVItem : item info
4976 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
4977 * if FALSE, the lpLVItem is a LPLVITEMA.
4980 * This is the external 'GetItem' interface -- it properly copies
4981 * the text in the provided buffer.
4987 static BOOL
LISTVIEW_GetItemExtT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
4992 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4995 pszText
= lpLVItem
->pszText
;
4996 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
4997 if (bResult
&& lpLVItem
->pszText
!= pszText
)
4998 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
4999 lpLVItem
->pszText
= pszText
;
5007 * Retrieves the position (upper-left) of the listview control item.
5008 * Note that for LVS_ICON style, the upper-left is that of the icon
5009 * and not the bounding box.
5012 * [I] infoPtr : valid pointer to the listview structure
5013 * [I] nItem : item index
5014 * [O] lpptPosition : coordinate information
5020 static BOOL
LISTVIEW_GetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
5022 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5025 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
5027 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5029 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5030 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
5032 if (uView
== LVS_ICON
)
5034 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
5035 lpptPosition
->y
+= ICON_TOP_PADDING
;
5037 lpptPosition
->x
+= Origin
.x
;
5038 lpptPosition
->y
+= Origin
.y
;
5040 TRACE (" lpptPosition=%s\n", debugpoint(lpptPosition
));
5047 * Retrieves the bounding rectangle for a listview control item.
5050 * [I] infoPtr : valid pointer to the listview structure
5051 * [I] nItem : item index
5052 * [IO] lprc : bounding rectangle coordinates
5053 * lprc->left specifies the portion of the item for which the bounding
5054 * rectangle will be retrieved.
5056 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
5057 * including the icon and label.
5060 * * Experiment shows that native control returns:
5061 * * width = min (48, length of text line)
5062 * * .left = position.x - (width - iconsize.cx)/2
5063 * * .right = .left + width
5064 * * height = #lines of text * ntmHeight + icon height + 8
5065 * * .top = position.y - 2
5066 * * .bottom = .top + height
5067 * * separation between items .y = itemSpacing.cy - height
5068 * * .x = itemSpacing.cx - width
5069 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
5072 * * Experiment shows that native control returns:
5073 * * width = iconSize.cx + 16
5074 * * .left = position.x - (width - iconsize.cx)/2
5075 * * .right = .left + width
5076 * * height = iconSize.cy + 4
5077 * * .top = position.y - 2
5078 * * .bottom = .top + height
5079 * * separation between items .y = itemSpacing.cy - height
5080 * * .x = itemSpacing.cx - width
5081 * LVIR_LABEL Returns the bounding rectangle of the item text.
5084 * * Experiment shows that native control returns:
5085 * * width = text length
5086 * * .left = position.x - width/2
5087 * * .right = .left + width
5088 * * height = ntmH * linecount + 2
5089 * * .top = position.y + iconSize.cy + 6
5090 * * .bottom = .top + height
5091 * * separation between items .y = itemSpacing.cy - height
5092 * * .x = itemSpacing.cx - width
5093 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
5094 * rectangles, but excludes columns in report view.
5101 * Note that the bounding rectangle of the label in the LVS_ICON view depends
5102 * upon whether the window has the focus currently and on whether the item
5103 * is the one with the focus. Ensure that the control's record of which
5104 * item has the focus agrees with the items' records.
5106 static BOOL
LISTVIEW_GetItemRect(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
5108 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5109 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5110 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
5111 POINT Position
, Origin
;
5115 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
5117 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5119 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5120 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
5122 /* Be smart and try to figure out the minimum we have to do */
5123 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
5124 if (uView
== LVS_REPORT
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
5125 if (uView
== LVS_ICON
&& lprc
->left
!= LVIR_ICON
&&
5126 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
5127 oversizedBox
= TRUE
;
5129 /* get what we need from the item before hand, so we make
5130 * only one request. This can speed up things, if data
5131 * is stored on the app side */
5133 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
5134 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
5135 lvItem
.iItem
= nItem
;
5136 lvItem
.iSubItem
= 0;
5137 lvItem
.pszText
= szDispText
;
5138 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5139 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
5140 /* we got the state already up, simulate it here, to avoid a reget */
5141 if (uView
== LVS_ICON
&& (lprc
->left
!= LVIR_ICON
))
5143 lvItem
.mask
|= LVIF_STATE
;
5144 lvItem
.stateMask
= LVIS_FOCUSED
;
5145 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
5148 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
5149 lprc
->left
= LVIR_BOUNDS
;
5153 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
);
5157 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, lprc
);
5161 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
);
5164 case LVIR_SELECTBOUNDS
:
5165 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, &label_rect
);
5166 UnionRect(lprc
, lprc
, &label_rect
);
5170 WARN("Unknown value: %d\n", lprc
->left
);
5174 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
5176 TRACE(" rect=%s\n", debugrect(lprc
));
5183 * Retrieves the spacing between listview control items.
5186 * [I] infoPtr : valid pointer to the listview structure
5187 * [IO] lprc : rectangle to receive the output
5188 * on input, lprc->top = nSubItem
5189 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
5191 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
5192 * not only those of the first column.
5193 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
5199 static BOOL
LISTVIEW_GetSubItemRect(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
5201 POINT Position
, Origin
;
5204 if (!lprc
|| (infoPtr
->dwStyle
& LVS_TYPEMASK
) != LVS_REPORT
) return FALSE
;
5206 TRACE("(nItem=%d, nSubItem=%d)\n", nItem
, lprc
->top
);
5208 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5209 if (!LISTVIEW_GetItemPosition(infoPtr
, nItem
, &Position
)) return FALSE
;
5211 lvItem
.mask
= lprc
->top
== 0 ? LVIF_INDENT
: 0;
5212 lvItem
.iItem
= nItem
;
5213 lvItem
.iSubItem
= lprc
->top
;
5215 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
5219 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
);
5224 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
);
5228 ERR("Unknown bounds=%d\n", lprc
->left
);
5232 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
5239 * Retrieves the width of a label.
5242 * [I] infoPtr : valid pointer to the listview structure
5245 * SUCCESS : string width (in pixels)
5248 static INT
LISTVIEW_GetLabelWidth(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5250 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5253 TRACE("(nItem=%d)\n", nItem
);
5255 lvItem
.mask
= LVIF_TEXT
;
5256 lvItem
.iItem
= nItem
;
5257 lvItem
.iSubItem
= 0;
5258 lvItem
.pszText
= szDispText
;
5259 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5260 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
5262 return LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
5267 * Retrieves the spacing between listview control items.
5270 * [I] infoPtr : valid pointer to the listview structure
5271 * [I] bSmall : flag for small or large icon
5274 * Horizontal + vertical spacing
5276 static LONG
LISTVIEW_GetItemSpacing(LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
5282 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
5286 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_ICON
)
5287 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
5289 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
5296 * Retrieves the state of a listview control item.
5299 * [I] infoPtr : valid pointer to the listview structure
5300 * [I] nItem : item index
5301 * [I] uMask : state mask
5304 * State specified by the mask.
5306 static UINT
LISTVIEW_GetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
5310 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5312 lvItem
.iItem
= nItem
;
5313 lvItem
.iSubItem
= 0;
5314 lvItem
.mask
= LVIF_STATE
;
5315 lvItem
.stateMask
= uMask
;
5316 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
5318 return lvItem
.state
& uMask
;
5323 * Retrieves the text of a listview control item or subitem.
5326 * [I] hwnd : window handle
5327 * [I] nItem : item index
5328 * [IO] lpLVItem : item information
5329 * [I] isW : TRUE if lpLVItem is Unicode
5332 * SUCCESS : string length
5335 static INT
LISTVIEW_GetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
5337 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5339 lpLVItem
->mask
= LVIF_TEXT
;
5340 lpLVItem
->iItem
= nItem
;
5341 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
5343 return textlenT(lpLVItem
->pszText
, isW
);
5348 * Searches for an item based on properties + relationships.
5351 * [I] infoPtr : valid pointer to the listview structure
5352 * [I] nItem : item index
5353 * [I] uFlags : relationship flag
5356 * SUCCESS : item index
5359 static INT
LISTVIEW_GetNextItem(LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
5361 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5363 LVFINDINFOW lvFindInfo
;
5364 INT nCountPerColumn
;
5367 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
5368 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
5370 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
5372 if (uFlags
& LVNI_CUT
)
5375 if (uFlags
& LVNI_DROPHILITED
)
5376 uMask
|= LVIS_DROPHILITED
;
5378 if (uFlags
& LVNI_FOCUSED
)
5379 uMask
|= LVIS_FOCUSED
;
5381 if (uFlags
& LVNI_SELECTED
)
5382 uMask
|= LVIS_SELECTED
;
5384 /* if we're asked for the focused item, that's only one,
5385 * so it's worth optimizing */
5386 if (uFlags
& LVNI_FOCUSED
)
5388 if (!(LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) == uMask
) return -1;
5389 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
5392 if (uFlags
& LVNI_ABOVE
)
5394 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
5399 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5405 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5406 lvFindInfo
.vkDirection
= VK_UP
;
5407 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5408 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5410 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5415 else if (uFlags
& LVNI_BELOW
)
5417 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
5419 while (nItem
< infoPtr
->nItemCount
)
5422 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5428 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5429 lvFindInfo
.vkDirection
= VK_DOWN
;
5430 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5431 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5433 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5438 else if (uFlags
& LVNI_TOLEFT
)
5440 if (uView
== LVS_LIST
)
5442 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
5443 while (nItem
- nCountPerColumn
>= 0)
5445 nItem
-= nCountPerColumn
;
5446 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5450 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5452 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5453 lvFindInfo
.vkDirection
= VK_LEFT
;
5454 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5455 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5457 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5462 else if (uFlags
& LVNI_TORIGHT
)
5464 if (uView
== LVS_LIST
)
5466 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
5467 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
5469 nItem
+= nCountPerColumn
;
5470 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5474 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5476 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5477 lvFindInfo
.vkDirection
= VK_RIGHT
;
5478 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5479 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5481 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5490 /* search by index */
5491 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
5493 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
5501 /* LISTVIEW_GetNumberOfWorkAreas */
5505 * Retrieves the origin coordinates when in icon or small icon display mode.
5508 * [I] infoPtr : valid pointer to the listview structure
5509 * [O] lpptOrigin : coordinate information
5514 static void LISTVIEW_GetOrigin(LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
5516 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5517 INT nHorzPos
= 0, nVertPos
= 0;
5518 SCROLLINFO scrollInfo
;
5520 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
5521 scrollInfo
.fMask
= SIF_POS
;
5523 if ((infoPtr
->dwStyle
& WS_HSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
5524 nHorzPos
= scrollInfo
.nPos
;
5525 if ((infoPtr
->dwStyle
& WS_VSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
5526 nVertPos
= scrollInfo
.nPos
;
5528 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
5530 lpptOrigin
->x
= infoPtr
->rcList
.left
;
5531 lpptOrigin
->y
= infoPtr
->rcList
.top
;
5532 if (uView
== LVS_LIST
)
5533 nHorzPos
*= infoPtr
->nItemWidth
;
5534 else if (uView
== LVS_REPORT
)
5535 nVertPos
*= infoPtr
->nItemHeight
;
5537 lpptOrigin
->x
-= nHorzPos
;
5538 lpptOrigin
->y
-= nVertPos
;
5540 TRACE(" origin=%s\n", debugpoint(lpptOrigin
));
5545 * Retrieves the width of a string.
5548 * [I] hwnd : window handle
5549 * [I] lpszText : text string to process
5550 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
5553 * SUCCESS : string width (in pixels)
5556 static INT
LISTVIEW_GetStringWidthT(LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
5561 if (is_textT(lpszText
, isW
))
5563 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
5564 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
5565 HFONT hOldFont
= SelectObject(hdc
, hFont
);
5568 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
5570 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
5571 SelectObject(hdc
, hOldFont
);
5572 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
5574 return stringSize
.cx
;
5579 * Determines which listview item is located at the specified position.
5582 * [I] infoPtr : valid pointer to the listview structure
5583 * [IO] lpht : hit test information
5584 * [I] subitem : fill out iSubItem.
5585 * [I] select : return the index only if the hit selects the item
5588 * (mm 20001022): We must not allow iSubItem to be touched, for
5589 * an app might pass only a structure with space up to iItem!
5590 * (MS Office 97 does that for instance in the file open dialog)
5593 * SUCCESS : item index
5596 static INT
LISTVIEW_HitTest(LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
5598 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5599 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5600 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
5601 POINT Origin
, Position
, opt
;
5605 TRACE("(pt=%s, subitem=%d, select=%d)\n", debugpoint(&lpht
->pt
), subitem
, select
);
5609 if (subitem
) lpht
->iSubItem
= 0;
5611 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
5612 lpht
->flags
|= LVHT_TOLEFT
;
5613 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
5614 lpht
->flags
|= LVHT_TORIGHT
;
5616 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
5617 lpht
->flags
|= LVHT_ABOVE
;
5618 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
5619 lpht
->flags
|= LVHT_BELOW
;
5621 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
5622 if (lpht
->flags
) return -1;
5624 lpht
->flags
|= LVHT_NOWHERE
;
5626 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5628 /* first deal with the large items */
5629 rcSearch
.left
= lpht
->pt
.x
;
5630 rcSearch
.top
= lpht
->pt
.y
;
5631 rcSearch
.right
= rcSearch
.left
+ 1;
5632 rcSearch
.bottom
= rcSearch
.top
+ 1;
5634 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
5635 iterator_next(&i
); /* go to first item in the sequence */
5636 lpht
->iItem
= i
.nItem
;
5637 iterator_destroy(&i
);
5639 TRACE("lpht->iItem=%d\n", lpht
->iItem
);
5640 if (lpht
->iItem
== -1) return -1;
5642 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
5643 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
5644 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
5645 if (uView
== LVS_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
5646 lvItem
.iItem
= lpht
->iItem
;
5647 lvItem
.iSubItem
= 0;
5648 lvItem
.pszText
= szDispText
;
5649 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5650 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
5651 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
5653 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcState
, &rcIcon
, &rcLabel
);
5654 LISTVIEW_GetItemOrigin(infoPtr
, lpht
->iItem
, &Position
);
5655 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
5656 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
5658 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
5661 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
5662 TRACE("rcBounds=%s\n", debugrect(&rcBounds
));
5663 if (!PtInRect(&rcBounds
, opt
)) return -1;
5665 if (PtInRect(&rcIcon
, opt
))
5666 lpht
->flags
|= LVHT_ONITEMICON
;
5667 else if (PtInRect(&rcLabel
, opt
))
5668 lpht
->flags
|= LVHT_ONITEMLABEL
;
5669 else if (infoPtr
->himlState
&& ((lvItem
.state
& LVIS_STATEIMAGEMASK
) >> 12) && PtInRect(&rcState
, opt
))
5670 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
5671 if (lpht
->flags
& LVHT_ONITEM
)
5672 lpht
->flags
&= ~LVHT_NOWHERE
;
5674 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
5675 if (uView
== LVS_REPORT
&& lpht
->iItem
!= -1 && subitem
)
5679 rcBounds
.right
= rcBounds
.left
;
5680 for (j
= 0; j
< infoPtr
->hdpaColumns
->nItemCount
; j
++)
5682 rcBounds
.left
= rcBounds
.right
;
5683 rcBounds
.right
+= LISTVIEW_GetColumnWidth(infoPtr
, j
);
5684 if (PtInRect(&rcBounds
, opt
))
5692 if (!select
|| lpht
->iItem
== -1) return lpht
->iItem
;
5694 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)) return lpht
->iItem
;
5696 if (uView
== LVS_REPORT
) UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
5697 return PtInRect(&rcBounds
, opt
) ? lpht
->iItem
: -1;
5701 /* LISTVIEW_InsertCompare: callback routine for comparing pszText members of the LV_ITEMS
5702 in a LISTVIEW on insert. Passed to DPA_Sort in LISTVIEW_InsertItem.
5703 This function should only be used for inserting items into a sorted list (LVM_INSERTITEM)
5704 and not during the processing of a LVM_SORTITEMS message. Applications should provide
5705 their own sort proc. when sending LVM_SORTITEMS.
5708 (remarks on LVITEM: LVM_INSERTITEM will insert the new item in the proper sort postion...
5710 LVS_SORTXXX must be specified,
5711 LVS_OWNERDRAW is not set,
5712 <item>.pszText is not LPSTR_TEXTCALLBACK.
5714 (LVS_SORT* flags): "For the LVS_SORTASCENDING... styles, item indices
5715 are sorted based on item text..."
5717 static INT WINAPI
LISTVIEW_InsertCompare( LPVOID first
, LPVOID second
, LPARAM lParam
)
5719 ITEM_INFO
* lv_first
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)first
, 0 );
5720 ITEM_INFO
* lv_second
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)second
, 0 );
5721 INT cmpv
= textcmpWT(lv_first
->hdr
.pszText
, lv_second
->hdr
.pszText
, TRUE
);
5723 /* if we're sorting descending, negate the return value */
5724 return (((LISTVIEW_INFO
*)lParam
)->dwStyle
& LVS_SORTDESCENDING
) ? -cmpv
: cmpv
;
5729 * Inserts a new item in the listview control.
5732 * [I] infoPtr : valid pointer to the listview structure
5733 * [I] lpLVItem : item information
5734 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
5737 * SUCCESS : new item index
5740 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
5742 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5747 BOOL is_sorted
, has_changed
;
5750 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
5752 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
5754 /* make sure it's an item, and not a subitem; cannot insert a subitem */
5755 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iSubItem
) return -1;
5757 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
5759 if ( !(lpItem
= (ITEM_INFO
*)COMCTL32_Alloc(sizeof(ITEM_INFO
))) )
5762 /* insert item in listview control data structure */
5763 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
5764 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
5766 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
5767 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
5769 nItem
= is_sorted
? infoPtr
->nItemCount
: min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
5770 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
5771 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
5772 if (nItem
== -1) goto fail
;
5773 infoPtr
->nItemCount
++;
5775 /* set the item attributes */
5778 item
.state
&= ~LVIS_STATEIMAGEMASK
;
5779 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
5781 /* if we're sorted, sort the list, and update the index */
5784 DPA_Sort( infoPtr
->hdpaItems
, LISTVIEW_InsertCompare
, (LPARAM
)infoPtr
);
5785 nItem
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, hdpaSubItems
);
5786 assert(nItem
!= -1);
5789 /* make room for the position, if we are in the right mode */
5790 if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5792 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
5794 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
5796 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5801 /* Add the subitem list to the items array. Do this last in case we go to
5802 * fail during the above.
5804 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
5806 /* send LVN_INSERTITEM notification */
5807 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
5809 nmlv
.lParam
= lpItem
->lParam
;
5810 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
5812 /* align items (set position of each item) */
5813 if ((uView
== LVS_SMALLICON
|| uView
== LVS_ICON
))
5817 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
5818 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
5820 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
5822 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
5825 /* now is the invalidation fun */
5826 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
5830 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5831 infoPtr
->nItemCount
--;
5833 DPA_DeletePtr(hdpaSubItems
, 0);
5834 DPA_Destroy (hdpaSubItems
);
5835 COMCTL32_Free (lpItem
);
5841 * Redraws a range of items.
5844 * [I] infoPtr : valid pointer to the listview structure
5845 * [I] nFirst : first item
5846 * [I] nLast : last item
5852 static BOOL
LISTVIEW_RedrawItems(LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
5856 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
5857 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
5860 for (i
= nFirst
; i
<= nLast
; i
++)
5861 LISTVIEW_InvalidateItem(infoPtr
, i
);
5868 * Scroll the content of a listview.
5871 * [I] infoPtr : valid pointer to the listview structure
5872 * [I] dx : horizontal scroll amount in pixels
5873 * [I] dy : vertical scroll amount in pixels
5880 * If the control is in report mode (LVS_REPORT) the control can
5881 * be scrolled only in line increments. "dy" will be rounded to the
5882 * nearest number of pixels that are a whole line. Ex: if line height
5883 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
5884 * is passed the the scroll will be 0. (per MSDN 7/2002)
5886 * For: (per experimentaion with native control and CSpy ListView)
5887 * LVS_ICON dy=1 = 1 pixel (vertical only)
5889 * LVS_SMALLICON dy=1 = 1 pixel (vertical only)
5891 * LVS_LIST dx=1 = 1 column (horizontal only)
5892 * but will only scroll 1 column per message
5893 * no matter what the value.
5894 * dy must be 0 or FALSE returned.
5895 * LVS_REPORT dx=1 = 1 pixel
5899 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
5901 switch(infoPtr
->dwStyle
& LVS_TYPEMASK
) {
5903 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
5904 dy
/= infoPtr
->nItemHeight
;
5907 if (dy
!= 0) return FALSE
;
5914 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
, 0);
5915 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
, 0);
5922 * Sets the background color.
5925 * [I] infoPtr : valid pointer to the listview structure
5926 * [I] clrBk : background color
5932 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrBk
)
5934 TRACE("(clrBk=%lx)\n", clrBk
);
5936 if(infoPtr
->clrBk
!= clrBk
) {
5937 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
5938 infoPtr
->clrBk
= clrBk
;
5939 if (clrBk
== CLR_NONE
)
5940 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongW(infoPtr
->hwndSelf
, GCL_HBRBACKGROUND
);
5942 infoPtr
->hBkBrush
= CreateSolidBrush(clrBk
);
5943 LISTVIEW_InvalidateList(infoPtr
);
5949 /* LISTVIEW_SetBkImage */
5951 /*** Helper for {Insert,Set}ColumnT *only* */
5952 static void column_fill_hditem(LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
, const LVCOLUMNW
*lpColumn
, BOOL isW
)
5954 if (lpColumn
->mask
& LVCF_FMT
)
5956 /* format member is valid */
5957 lphdi
->mask
|= HDI_FORMAT
;
5959 /* set text alignment (leftmost column must be left-aligned) */
5960 if (nColumn
== 0 || lpColumn
->fmt
& LVCFMT_LEFT
)
5961 lphdi
->fmt
|= HDF_LEFT
;
5962 else if (lpColumn
->fmt
& LVCFMT_RIGHT
)
5963 lphdi
->fmt
|= HDF_RIGHT
;
5964 else if (lpColumn
->fmt
& LVCFMT_CENTER
)
5965 lphdi
->fmt
|= HDF_CENTER
;
5967 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
5968 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
5970 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
5972 lphdi
->fmt
|= HDF_IMAGE
;
5973 lphdi
->iImage
= I_IMAGECALLBACK
;
5977 if (lpColumn
->mask
& LVCF_WIDTH
)
5979 lphdi
->mask
|= HDI_WIDTH
;
5980 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
5982 /* make it fill the remainder of the controls width */
5986 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
5988 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
5989 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
5992 /* retrieve the layout of the header */
5993 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
5994 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, debugrect(&rcHeader
));
5996 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
5999 lphdi
->cxy
= lpColumn
->cx
;
6002 if (lpColumn
->mask
& LVCF_TEXT
)
6004 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
6005 lphdi
->fmt
|= HDF_STRING
;
6006 lphdi
->pszText
= lpColumn
->pszText
;
6007 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
6010 if (lpColumn
->mask
& LVCF_IMAGE
)
6012 lphdi
->mask
|= HDI_IMAGE
;
6013 lphdi
->iImage
= lpColumn
->iImage
;
6016 if (lpColumn
->mask
& LVCF_ORDER
)
6018 lphdi
->mask
|= HDI_ORDER
;
6019 lphdi
->iOrder
= lpColumn
->iOrder
;
6026 * Inserts a new column.
6029 * [I] infoPtr : valid pointer to the listview structure
6030 * [I] nColumn : column index
6031 * [I] lpColumn : column information
6032 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
6035 * SUCCESS : new column index
6038 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
6039 const LVCOLUMNW
*lpColumn
, BOOL isW
)
6041 COLUMN_INFO
*lpColumnInfo
;
6045 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
6047 if (!lpColumn
|| nColumn
< 0 || nColumn
> infoPtr
->hdpaColumns
->nItemCount
) return -1;
6049 ZeroMemory(&hdi
, sizeof(HDITEMW
));
6050 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
6052 /* insert item in header control */
6053 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
6054 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
6055 (WPARAM
)nColumn
, (LPARAM
)&hdi
);
6056 if (nNewColumn
== -1) return -1;
6057 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
6059 /* create our own column info */
6060 if (!(lpColumnInfo
= COMCTL32_Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
6061 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
6063 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
6064 if (!Header_GetItemRect(infoPtr
->hwndHeader
, nNewColumn
, &lpColumnInfo
->rcHeader
)) goto fail
;
6066 /* now we have to actually adjust the data */
6067 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
6069 SUBITEM_INFO
*lpSubItem
, *lpMainItem
, **lpNewItems
= 0;
6073 /* preallocate memory, so we can fail gracefully */
6074 if (nNewColumn
== 0)
6076 lpNewItems
= COMCTL32_Alloc(sizeof(SUBITEM_INFO
*) * infoPtr
->nItemCount
);
6077 if (!lpNewItems
) goto fail
;
6078 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
6079 if (!(lpNewItems
[i
] = COMCTL32_Alloc(sizeof(SUBITEM_INFO
)))) break;
6080 if (i
!= infoPtr
->nItemCount
)
6082 for(; i
>=0; i
--) COMCTL32_Free(lpNewItems
[i
]);
6083 COMCTL32_Free(lpNewItems
);
6088 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
6090 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
6091 for (i
= 1; i
< hdpaSubItems
->nItemCount
; i
++)
6093 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
6094 if (lpSubItem
->iSubItem
>= nNewColumn
)
6095 lpSubItem
->iSubItem
++;
6098 /* for inserting column 0, we have to special-case the main item */
6099 if (nNewColumn
== 0)
6101 lpMainItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
6102 lpSubItem
= lpNewItems
[nItem
];
6103 lpSubItem
->hdr
= lpMainItem
->hdr
;
6104 lpSubItem
->iSubItem
= 1;
6105 ZeroMemory(&lpMainItem
->hdr
, sizeof(lpMainItem
->hdr
));
6106 lpMainItem
->iSubItem
= 0;
6107 DPA_InsertPtr(hdpaSubItems
, 1, lpSubItem
);
6111 COMCTL32_Free(lpNewItems
);
6114 /* make space for the new column */
6115 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
6120 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
6123 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
6124 COMCTL32_Free(lpColumnInfo
);
6131 * Sets the attributes of a header item.
6134 * [I] infoPtr : valid pointer to the listview structure
6135 * [I] nColumn : column index
6136 * [I] lpColumn : column attributes
6137 * [I] isW: if TRUE, the lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
6143 static BOOL
LISTVIEW_SetColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
6144 const LVCOLUMNW
*lpColumn
, BOOL isW
)
6146 HDITEMW hdi
, hdiget
;
6149 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
6151 if (!lpColumn
|| nColumn
< 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
6153 ZeroMemory(&hdi
, sizeof(HDITEMW
));
6154 if (lpColumn
->mask
& LVCF_FMT
)
6156 hdi
.mask
|= HDI_FORMAT
;
6157 hdiget
.mask
= HDI_FORMAT
;
6158 if (Header_GetItemW(infoPtr
->hwndHeader
, nColumn
, &hdiget
))
6159 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
6161 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
6163 /* set header item attributes */
6164 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, (WPARAM
)nColumn
, (LPARAM
)&hdi
);
6165 if (!bResult
) return FALSE
;
6167 if (lpColumn
->mask
& LVCF_FMT
)
6169 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6170 int oldFmt
= lpColumnInfo
->fmt
;
6172 lpColumnInfo
->fmt
= lpColumn
->fmt
;
6173 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
6175 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6176 if (uView
== LVS_REPORT
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
6185 * Sets the column order array
6188 * [I] infoPtr : valid pointer to the listview structure
6189 * [I] iCount : number of elements in column order array
6190 * [I] lpiArray : pointer to column order array
6196 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
6198 FIXME("iCount %d lpiArray %p\n", iCount
, lpiArray
);
6209 * Sets the width of a column
6212 * [I] infoPtr : valid pointer to the listview structure
6213 * [I] nColumn : column index
6214 * [I] cx : column width
6220 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
6222 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6223 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
6227 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
6229 /* set column width only if in report or list mode */
6230 if (uView
!= LVS_REPORT
&& uView
!= LVS_LIST
) return FALSE
;
6232 /* take care of invalid cx values */
6233 if(uView
== LVS_REPORT
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
6234 else if (uView
== LVS_LIST
&& cx
< 1) return FALSE
;
6236 /* resize all columns if in LVS_LIST mode */
6237 if(uView
== LVS_LIST
)
6239 infoPtr
->nItemWidth
= cx
;
6240 LISTVIEW_InvalidateList(infoPtr
);
6244 if (nColumn
< 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
6246 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< infoPtr
->hdpaColumns
->nItemCount
-1))
6251 lvItem
.mask
= LVIF_TEXT
;
6253 lvItem
.iSubItem
= nColumn
;
6254 lvItem
.pszText
= szDispText
;
6255 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6256 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
6258 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6259 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
6260 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
6262 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
6263 max_cx
+= infoPtr
->iconSize
.cx
+ IMAGE_PADDING
;
6264 max_cx
+= REPORT_MARGINX
+ TRAILING_PADDING
;
6267 /* autosize based on listview items width */
6268 if(cx
== LVSCW_AUTOSIZE
)
6270 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
6272 /* if iCol is the last column make it fill the remainder of the controls width */
6273 if(nColumn
== infoPtr
->hdpaColumns
->nItemCount
- 1)
6278 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6279 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
6281 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
6285 /* Despite what the MS docs say, if this is not the last
6286 column, then MS resizes the column to the width of the
6287 largest text string in the column, including headers
6288 and items. This is different from LVSCW_AUTOSIZE in that
6289 LVSCW_AUTOSIZE ignores the header string length. */
6292 /* retrieve header text */
6293 hdi
.mask
= HDI_TEXT
;
6294 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
6295 hdi
.pszText
= szDispText
;
6296 if (Header_GetItemW(infoPtr
->hwndHeader
, nColumn
, (LPARAM
)&hdi
))
6298 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
6299 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
6302 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
6304 /* FIXME: Take into account the header image, if one is present */
6305 SelectObject(hdc
, old_font
);
6306 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6308 cx
= max (cx
, max_cx
);
6312 if (cx
< 0) return FALSE
;
6314 /* call header to update the column change */
6315 hdi
.mask
= HDI_WIDTH
;
6317 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
6318 return Header_SetItemW(infoPtr
->hwndHeader
, nColumn
, (LPARAM
)&hdi
);
6323 * Sets the extended listview style.
6326 * [I] infoPtr : valid pointer to the listview structure
6328 * [I] dwStyle : style
6331 * SUCCESS : previous style
6334 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD dwMask
, DWORD dwStyle
)
6336 DWORD dwOldStyle
= infoPtr
->dwLvExStyle
;
6340 infoPtr
->dwLvExStyle
= (dwOldStyle
& ~dwMask
) | (dwStyle
& dwMask
);
6342 infoPtr
->dwLvExStyle
= dwStyle
;
6349 * Sets the new hot cursor used during hot tracking and hover selection.
6352 * [I] infoPtr : valid pointer to the listview structure
6353 * [I} hCurosr : the new hot cursor handle
6356 * Returns the previous hot cursor
6358 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
6360 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
6362 infoPtr
->hHotCursor
= hCursor
;
6370 * Sets the hot item index.
6373 * [I] infoPtr : valid pointer to the listview structure
6374 * [I] iIndex : index
6377 * SUCCESS : previous hot item index
6378 * FAILURE : -1 (no hot item)
6380 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
6382 INT iOldIndex
= infoPtr
->nHotItem
;
6384 infoPtr
->nHotItem
= iIndex
;
6392 * Sets the amount of time the cursor must hover over an item before it is selected.
6395 * [I] infoPtr : valid pointer to the listview structure
6396 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
6399 * Returns the previous hover time
6401 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
6403 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
6405 infoPtr
->dwHoverTime
= dwHoverTime
;
6407 return oldHoverTime
;
6412 * Sets spacing for icons of LVS_ICON style.
6415 * [I] infoPtr : valid pointer to the listview structure
6416 * [I] spacing : MAKELONG(cx, cy)
6419 * MAKELONG(oldcx, oldcy)
6421 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, DWORD spacing
)
6423 INT cy
= HIWORD(spacing
), cx
= LOWORD(spacing
);
6424 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
6425 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6427 TRACE("requested=(%d,%d)\n", cx
, cy
);
6429 /* this is supported only for LVS_ICON style */
6430 if (uView
!= LVS_ICON
) return oldspacing
;
6432 /* set to defaults, if instructed to */
6433 if (cx
== -1) cx
= GetSystemMetrics(SM_CXICONSPACING
);
6434 if (cy
== -1) cy
= GetSystemMetrics(SM_CYICONSPACING
);
6436 /* if 0 then compute width
6437 * FIXME: Should scan each item and determine max width of
6438 * icon or label, then make that the width */
6440 cx
= infoPtr
->iconSpacing
.cx
;
6442 /* if 0 then compute height */
6444 cy
= infoPtr
->iconSize
.cy
+ 2 * infoPtr
->ntmHeight
+
6445 ICON_BOTTOM_PADDING
+ ICON_TOP_PADDING
+ LABEL_VERT_PADDING
;
6448 infoPtr
->iconSpacing
.cx
= cx
;
6449 infoPtr
->iconSpacing
.cy
= cy
;
6451 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%ld,%ld), ntmH=%d\n",
6452 LOWORD(oldspacing
), HIWORD(oldspacing
), cx
, cy
,
6453 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
6454 infoPtr
->ntmHeight
);
6456 /* these depend on the iconSpacing */
6457 LISTVIEW_UpdateItemSize(infoPtr
);
6462 inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
6466 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
6473 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
6474 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
6483 * [I] infoPtr : valid pointer to the listview structure
6484 * [I] nType : image list type
6485 * [I] himl : image list handle
6488 * SUCCESS : old image list
6491 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
6493 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6494 INT oldHeight
= infoPtr
->nItemHeight
;
6495 HIMAGELIST himlOld
= 0;
6497 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
6502 himlOld
= infoPtr
->himlNormal
;
6503 infoPtr
->himlNormal
= himl
;
6504 if (uView
== LVS_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
6505 LISTVIEW_SetIconSpacing(infoPtr
, 0);
6509 himlOld
= infoPtr
->himlSmall
;
6510 infoPtr
->himlSmall
= himl
;
6511 if (uView
!= LVS_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
6515 himlOld
= infoPtr
->himlState
;
6516 infoPtr
->himlState
= himl
;
6517 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
6518 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
6522 ERR("Unknown icon type=%d\n", nType
);
6526 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
6527 if (infoPtr
->nItemHeight
!= oldHeight
)
6528 LISTVIEW_UpdateScroll(infoPtr
);
6535 * Preallocates memory (does *not* set the actual count of items !)
6538 * [I] infoPtr : valid pointer to the listview structure
6539 * [I] nItems : item count (projected number of items to allocate)
6540 * [I] dwFlags : update flags
6546 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
6548 TRACE("(nItems=%d, dwFlags=%lx)\n", nItems
, dwFlags
);
6550 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6552 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6553 INT nOldCount
= infoPtr
->nItemCount
;
6555 if (nItems
< nOldCount
)
6557 RANGE range
= { nItems
, nOldCount
};
6558 ranges_del(infoPtr
->selectionRanges
, range
);
6559 if (infoPtr
->nFocusedItem
>= nItems
)
6561 infoPtr
->nFocusedItem
= -1;
6562 SetRectEmpty(&infoPtr
->rcFocus
);
6566 infoPtr
->nItemCount
= nItems
;
6567 LISTVIEW_UpdateScroll(infoPtr
);
6569 /* the flags are valid only in ownerdata report and list modes */
6570 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
) dwFlags
= 0;
6572 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
6573 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
6575 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
6576 LISTVIEW_InvalidateList(infoPtr
);
6583 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6584 nFrom
= min(nOldCount
, nItems
);
6585 nTo
= max(nOldCount
, nItems
);
6587 if (uView
== LVS_REPORT
)
6590 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
6591 rcErase
.right
= infoPtr
->nItemWidth
;
6592 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
6593 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
6594 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
6595 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
6599 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
6601 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
6602 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
6603 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
6604 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
6605 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
6606 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
6607 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
6609 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
6611 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
6612 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
6613 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
6614 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
6615 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
6621 /* According to MSDN for non-LVS_OWNERDATA this is just
6622 * a performance issue. The control allocates its internal
6623 * data structures for the number of items specified. It
6624 * cuts down on the number of memory allocations. Therefore
6625 * we will just issue a WARN here
6627 WARN("for non-ownerdata performance option not implemented.\n");
6635 * Sets the position of an item.
6638 * [I] infoPtr : valid pointer to the listview structure
6639 * [I] nItem : item index
6640 * [I] pt : coordinate
6646 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, POINT pt
)
6648 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6651 TRACE("(nItem=%d, &pt=%s\n", nItem
, debugpoint(&pt
));
6653 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
6654 !(uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)) return FALSE
;
6656 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6658 /* This point value seems to be an undocumented feature.
6659 * The best guess is that it means either at the origin,
6660 * or at true beginning of the list. I will assume the origin. */
6661 if ((pt
.x
== -1) && (pt
.y
== -1))
6664 if (uView
== LVS_ICON
)
6666 pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6667 pt
.y
-= ICON_TOP_PADDING
;
6672 infoPtr
->bAutoarrange
= FALSE
;
6674 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, FALSE
);
6679 * Sets the state of one or many items.
6682 * [I] infoPtr : valid pointer to the listview structure
6683 * [I] nItem : item index
6684 * [I] lpLVItem : item or subitem info
6690 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
)
6692 BOOL bResult
= TRUE
;
6695 lvItem
.iItem
= nItem
;
6696 lvItem
.iSubItem
= 0;
6697 lvItem
.mask
= LVIF_STATE
;
6698 lvItem
.state
= lpLVItem
->state
;
6699 lvItem
.stateMask
= lpLVItem
->stateMask
;
6700 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
6704 /* apply to all items */
6705 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
6706 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) bResult
= FALSE
;
6709 bResult
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
6716 * Sets the text of an item or subitem.
6719 * [I] hwnd : window handle
6720 * [I] nItem : item index
6721 * [I] lpLVItem : item or subitem info
6722 * [I] isW : TRUE if input is Unicode
6728 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
6732 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
6734 lvItem
.iItem
= nItem
;
6735 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
6736 lvItem
.mask
= LVIF_TEXT
;
6737 lvItem
.pszText
= lpLVItem
->pszText
;
6738 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
6740 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
6742 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
6747 * Set item index that marks the start of a multiple selection.
6750 * [I] infoPtr : valid pointer to the listview structure
6751 * [I] nIndex : index
6754 * Index number or -1 if there is no selection mark.
6756 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
6758 INT nOldIndex
= infoPtr
->nSelectionMark
;
6760 TRACE("(nIndex=%d)\n", nIndex
);
6762 infoPtr
->nSelectionMark
= nIndex
;
6769 * Sets the text background color.
6772 * [I] infoPtr : valid pointer to the listview structure
6773 * [I] clrTextBk : text background color
6779 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrTextBk
)
6781 TRACE("(clrTextBk=%lx)\n", clrTextBk
);
6783 if (infoPtr
->clrTextBk
!= clrTextBk
)
6785 infoPtr
->clrTextBk
= clrTextBk
;
6786 LISTVIEW_InvalidateList(infoPtr
);
6794 * Sets the text foreground color.
6797 * [I] infoPtr : valid pointer to the listview structure
6798 * [I] clrText : text color
6804 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF clrText
)
6806 TRACE("(clrText=%lx)\n", clrText
);
6808 if (infoPtr
->clrText
!= clrText
)
6810 infoPtr
->clrText
= clrText
;
6811 LISTVIEW_InvalidateList(infoPtr
);
6817 /* LISTVIEW_SetToolTips */
6818 /* LISTVIEW_SetUnicodeFormat */
6819 /* LISTVIEW_SetWorkAreas */
6823 * Callback internally used by LISTVIEW_SortItems()
6826 * [I] first : pointer to first ITEM_INFO to compare
6827 * [I] second : pointer to second ITEM_INFO to compare
6828 * [I] lParam : HWND of control
6831 * if first comes before second : negative
6832 * if first comes after second : positive
6833 * if first and second are equivalent : zero
6835 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
6837 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongW((HWND
)lParam
, 0);
6838 ITEM_INFO
* lv_first
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)first
, 0 );
6839 ITEM_INFO
* lv_second
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)second
, 0 );
6841 /* Forward the call to the client defined callback */
6842 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
6847 * Sorts the listview items.
6850 * [I] infoPtr : valid pointer to the listview structure
6851 * [I] pfnCompare : application-defined value
6852 * [I] lParamSort : pointer to comparision callback
6858 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
, LPARAM lParamSort
)
6860 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6863 LPVOID selectionMarkItem
;
6867 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
6869 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
6871 if (!infoPtr
->hdpaItems
) return FALSE
;
6873 /* if there are 0 or 1 items, there is no need to sort */
6874 if (infoPtr
->nItemCount
< 2) return TRUE
;
6876 if (infoPtr
->nFocusedItem
>= 0)
6878 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
6879 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
6880 if (lpItem
) lpItem
->state
|= LVIS_FOCUSED
;
6882 /* FIXME: go thorugh selected items and mark them so in lpItem->state */
6883 /* clear the lpItem->state for non-selected ones */
6884 /* remove the selection ranges */
6886 infoPtr
->pfnCompare
= pfnCompare
;
6887 infoPtr
->lParamSort
= lParamSort
;
6888 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
->hwndSelf
);
6890 /* Adjust selections and indices so that they are the way they should
6891 * be after the sort (otherwise, the list items move around, but
6892 * whatever is at the item's previous original position will be
6895 selectionMarkItem
=(infoPtr
->nSelectionMark
>=0)?DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
):NULL
;
6896 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
6898 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, i
);
6899 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
6901 if (lpItem
->state
& LVIS_SELECTED
)
6903 item
.state
= LVIS_SELECTED
;
6904 item
.stateMask
= LVIS_SELECTED
;
6905 LISTVIEW_SetItemState(infoPtr
, i
, &item
);
6907 if (lpItem
->state
& LVIS_FOCUSED
)
6909 infoPtr
->nFocusedItem
= i
;
6910 lpItem
->state
&= ~LVIS_FOCUSED
;
6913 if (selectionMarkItem
!= NULL
)
6914 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
6915 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
6917 /* refresh the display */
6918 if (uView
!= LVS_ICON
&& uView
!= LVS_SMALLICON
)
6919 LISTVIEW_InvalidateList(infoPtr
);
6926 * Updates an items or rearranges the listview control.
6929 * [I] infoPtr : valid pointer to the listview structure
6930 * [I] nItem : item index
6936 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
6938 TRACE("(nItem=%d)\n", nItem
);
6940 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6942 /* rearrange with default alignment style */
6943 if (is_autoarrange(infoPtr
))
6944 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
6946 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6954 * Creates the listview control.
6957 * [I] hwnd : window handle
6958 * [I] lpcs : the create parameters
6964 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
6966 LISTVIEW_INFO
*infoPtr
;
6967 UINT uView
= lpcs
->style
& LVS_TYPEMASK
;
6970 TRACE("(lpcs=%p)\n", lpcs
);
6972 /* initialize info pointer */
6973 infoPtr
= (LISTVIEW_INFO
*)COMCTL32_Alloc(sizeof(LISTVIEW_INFO
));
6974 if (!infoPtr
) return -1;
6976 SetWindowLongW(hwnd
, 0, (LONG
)infoPtr
);
6978 infoPtr
->hwndSelf
= hwnd
;
6979 infoPtr
->dwStyle
= lpcs
->style
;
6980 /* determine the type of structures to use */
6981 infoPtr
->notifyFormat
= SendMessageW(GetParent(infoPtr
->hwndSelf
), WM_NOTIFYFORMAT
,
6982 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
6984 /* initialize color information */
6985 infoPtr
->clrBk
= CLR_NONE
;
6986 infoPtr
->clrText
= comctl32_color
.clrWindowText
;
6987 infoPtr
->clrTextBk
= CLR_DEFAULT
;
6988 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
6990 /* set default values */
6991 infoPtr
->nFocusedItem
= -1;
6992 infoPtr
->nSelectionMark
= -1;
6993 infoPtr
->nHotItem
= -1;
6994 infoPtr
->bRedraw
= TRUE
;
6995 infoPtr
->bFirstPaint
= TRUE
;
6996 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
);
6997 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
);
6998 infoPtr
->nEditLabelItem
= -1;
6999 infoPtr
->dwHoverTime
= -1; /* default system hover time */
7001 /* get default font (icon title) */
7002 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
7003 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
7004 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
7005 LISTVIEW_SaveTextMetrics(infoPtr
);
7008 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, (LPCWSTR
)NULL
,
7009 WS_CHILD
| HDS_HORZ
| (DWORD
)((LVS_NOSORTHEADER
& lpcs
->style
)?0:HDS_BUTTONS
),
7010 0, 0, 0, 0, hwnd
, (HMENU
)0,
7011 lpcs
->hInstance
, NULL
);
7013 /* set header unicode format */
7014 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, (WPARAM
)TRUE
, (LPARAM
)NULL
);
7016 /* set header font */
7017 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, (LPARAM
)TRUE
);
7019 /* allocate memory for the selection ranges */
7020 if (!(infoPtr
->selectionRanges
= ranges_create(10))) return -1;
7022 /* allocate memory for the data structure */
7023 /* FIXME: what if we fail? */
7024 infoPtr
->hdpaItems
= DPA_Create(10);
7025 infoPtr
->hdpaPosX
= DPA_Create(10);
7026 infoPtr
->hdpaPosY
= DPA_Create(10);
7027 infoPtr
->hdpaColumns
= DPA_Create(10);
7029 /* initialize the icon sizes */
7030 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, uView
!= LVS_ICON
);
7031 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
7033 /* init item size to avoid division by 0 */
7034 LISTVIEW_UpdateItemSize (infoPtr
);
7036 if (uView
== LVS_REPORT
)
7038 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
))
7040 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
7044 /* set HDS_HIDDEN flag to hide the header bar */
7045 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
,
7046 GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
) | HDS_HIDDEN
);
7055 * Erases the background of the listview control.
7058 * [I] infoPtr : valid pointer to the listview structure
7059 * [I] hdc : device context handle
7065 static inline BOOL
LISTVIEW_EraseBkgnd(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
7069 TRACE("(hdc=%p)\n", hdc
);
7071 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
7073 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
7079 * Helper function for LISTVIEW_[HV]Scroll *only*.
7080 * Performs vertical/horizontal scrolling by a give amount.
7083 * [I] infoPtr : valid pointer to the listview structure
7084 * [I] dx : amount of horizontal scroll
7085 * [I] dy : amount of vertical scroll
7087 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7089 /* now we can scroll the list */
7090 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
7091 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
7092 /* if we have focus, adjust rect */
7093 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
7094 UpdateWindow(infoPtr
->hwndSelf
);
7099 * Performs vertical scrolling.
7102 * [I] infoPtr : valid pointer to the listview structure
7103 * [I] nScrollCode : scroll code
7104 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7105 * [I] hScrollWnd : scrollbar control window handle
7111 * SB_LINEUP/SB_LINEDOWN:
7112 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
7113 * for LVS_REPORT is 1 line
7114 * for LVS_LIST cannot occur
7117 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
7118 INT nScrollDiff
, HWND hScrollWnd
)
7120 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7121 INT nOldScrollPos
, nNewScrollPos
;
7122 SCROLLINFO scrollInfo
;
7125 TRACE("(nScrollCode=%d, nScrollDiff=%d)\n", nScrollCode
, nScrollDiff
);
7127 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
7129 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7130 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
7132 is_an_icon
= ((uView
== LVS_ICON
) || (uView
== LVS_SMALLICON
));
7134 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
7136 nOldScrollPos
= scrollInfo
.nPos
;
7137 switch (nScrollCode
)
7143 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
7147 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
7151 nScrollDiff
= -scrollInfo
.nPage
;
7155 nScrollDiff
= scrollInfo
.nPage
;
7158 case SB_THUMBPOSITION
:
7160 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
7167 /* quit right away if pos isn't changing */
7168 if (nScrollDiff
== 0) return 0;
7170 /* calculate new position, and handle overflows */
7171 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
7172 if (nScrollDiff
> 0) {
7173 if (nNewScrollPos
< nOldScrollPos
||
7174 nNewScrollPos
> scrollInfo
.nMax
)
7175 nNewScrollPos
= scrollInfo
.nMax
;
7177 if (nNewScrollPos
> nOldScrollPos
||
7178 nNewScrollPos
< scrollInfo
.nMin
)
7179 nNewScrollPos
= scrollInfo
.nMin
;
7182 /* set the new position, and reread in case it changed */
7183 scrollInfo
.fMask
= SIF_POS
;
7184 scrollInfo
.nPos
= nNewScrollPos
;
7185 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
7187 /* carry on only if it really changed */
7188 if (nNewScrollPos
== nOldScrollPos
) return 0;
7190 /* now adjust to client coordinates */
7191 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
7192 if (uView
== LVS_REPORT
) nScrollDiff
*= infoPtr
->nItemHeight
;
7194 /* and scroll the window */
7195 scroll_list(infoPtr
, 0, nScrollDiff
);
7202 * Performs horizontal scrolling.
7205 * [I] infoPtr : valid pointer to the listview structure
7206 * [I] nScrollCode : scroll code
7207 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7208 * [I] hScrollWnd : scrollbar control window handle
7214 * SB_LINELEFT/SB_LINERIGHT:
7215 * for LVS_ICON, LVS_SMALLICON 1 pixel
7216 * for LVS_REPORT is 1 pixel
7217 * for LVS_LIST is 1 column --> which is a 1 because the
7218 * scroll is based on columns not pixels
7221 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
7222 INT nScrollDiff
, HWND hScrollWnd
)
7224 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7225 INT nOldScrollPos
, nNewScrollPos
;
7226 SCROLLINFO scrollInfo
;
7228 TRACE("(nScrollCode=%d, nScrollDiff=%d)\n", nScrollCode
, nScrollDiff
);
7230 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
7232 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7233 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
7235 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
7237 nOldScrollPos
= scrollInfo
.nPos
;
7239 switch (nScrollCode
)
7253 nScrollDiff
= -scrollInfo
.nPage
;
7257 nScrollDiff
= scrollInfo
.nPage
;
7260 case SB_THUMBPOSITION
:
7262 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
7269 /* quit right away if pos isn't changing */
7270 if (nScrollDiff
== 0) return 0;
7272 /* calculate new position, and handle overflows */
7273 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
7274 if (nScrollDiff
> 0) {
7275 if (nNewScrollPos
< nOldScrollPos
||
7276 nNewScrollPos
> scrollInfo
.nMax
)
7277 nNewScrollPos
= scrollInfo
.nMax
;
7279 if (nNewScrollPos
> nOldScrollPos
||
7280 nNewScrollPos
< scrollInfo
.nMin
)
7281 nNewScrollPos
= scrollInfo
.nMin
;
7284 /* set the new position, and reread in case it changed */
7285 scrollInfo
.fMask
= SIF_POS
;
7286 scrollInfo
.nPos
= nNewScrollPos
;
7287 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
7289 /* carry on only if it really changed */
7290 if (nNewScrollPos
== nOldScrollPos
) return 0;
7292 if(uView
== LVS_REPORT
)
7293 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
7295 /* now adjust to client coordinates */
7296 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
7297 if (uView
== LVS_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
7299 /* and scroll the window */
7300 scroll_list(infoPtr
, nScrollDiff
, 0);
7305 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
7307 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7308 INT gcWheelDelta
= 0;
7309 UINT pulScrollLines
= 3;
7310 SCROLLINFO scrollInfo
;
7312 TRACE("(wheelDelta=%d)\n", wheelDelta
);
7314 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
7315 gcWheelDelta
-= wheelDelta
;
7317 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7318 scrollInfo
.fMask
= SIF_POS
;
7325 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
7326 * should be fixed in the future.
7328 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7329 LISTVIEW_VScroll(infoPtr
, SB_THUMBPOSITION
,
7330 scrollInfo
.nPos
+ (gcWheelDelta
< 0) ?
7331 LISTVIEW_SCROLL_ICON_LINE_SIZE
:
7332 -LISTVIEW_SCROLL_ICON_LINE_SIZE
, 0);
7336 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
7338 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7340 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
7341 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
7342 LISTVIEW_VScroll(infoPtr
, SB_THUMBPOSITION
, scrollInfo
.nPos
+ cLineScroll
, 0);
7348 LISTVIEW_HScroll(infoPtr
, (gcWheelDelta
< 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0, 0);
7359 * [I] infoPtr : valid pointer to the listview structure
7360 * [I] nVirtualKey : virtual key
7361 * [I] lKeyData : key data
7366 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
7368 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7370 NMLVKEYDOWN nmKeyDown
;
7372 TRACE("(nVirtualKey=%d, lKeyData=%ld)\n", nVirtualKey
, lKeyData
);
7374 /* send LVN_KEYDOWN notification */
7375 nmKeyDown
.wVKey
= nVirtualKey
;
7376 nmKeyDown
.flags
= 0;
7377 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
7379 switch (nVirtualKey
)
7382 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
7384 notify(infoPtr
, NM_RETURN
);
7385 notify(infoPtr
, LVN_ITEMACTIVATE
);
7390 if (infoPtr
->nItemCount
> 0)
7395 if (infoPtr
->nItemCount
> 0)
7396 nItem
= infoPtr
->nItemCount
- 1;
7400 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
7404 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
7408 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
7412 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
7416 if (uView
== LVS_REPORT
)
7417 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
);
7419 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
7420 * LISTVIEW_GetCountPerRow(infoPtr
);
7421 if(nItem
< 0) nItem
= 0;
7425 if (uView
== LVS_REPORT
)
7426 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
);
7428 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
7429 * LISTVIEW_GetCountPerRow(infoPtr
);
7430 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
7434 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
))
7435 LISTVIEW_KeySelection(infoPtr
, nItem
);
7445 * [I] infoPtr : valid pointer to the listview structure
7450 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
7454 /* if we did not have the focus, there's nothing to do */
7455 if (!infoPtr
->bFocus
) return 0;
7457 /* send NM_KILLFOCUS notification */
7458 notify(infoPtr
, NM_KILLFOCUS
);
7460 /* if we have a focus rectagle, get rid of it */
7461 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
7463 /* set window focus flag */
7464 infoPtr
->bFocus
= FALSE
;
7466 /* invalidate the selected items before reseting focus flag */
7467 LISTVIEW_InvalidateSelectedItems(infoPtr
);
7474 * Processes double click messages (left mouse button).
7477 * [I] infoPtr : valid pointer to the listview structure
7478 * [I] wKey : key flag
7479 * [I] pts : mouse coordinate
7484 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7486 LVHITTESTINFO htInfo
;
7488 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7490 /* send NM_RELEASEDCAPTURE notification */
7491 notify(infoPtr
, NM_RELEASEDCAPTURE
);
7493 htInfo
.pt
.x
= pts
.x
;
7494 htInfo
.pt
.y
= pts
.y
;
7496 /* send NM_DBLCLK notification */
7497 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
7498 notify_click(infoPtr
, NM_DBLCLK
, &htInfo
);
7500 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
7501 if(htInfo
.iItem
!= -1) notify(infoPtr
, LVN_ITEMACTIVATE
);
7508 * Processes mouse down messages (left mouse button).
7511 * [I] infoPtr : valid pointer to the listview structure
7512 * [I] wKey : key flag
7513 * [I] pts : mouse coordinate
7518 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7520 LVHITTESTINFO lvHitTestInfo
;
7521 static BOOL bGroupSelect
= TRUE
;
7522 POINT pt
= { pts
.x
, pts
.y
};
7525 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7527 /* send NM_RELEASEDCAPTURE notification */
7528 notify(infoPtr
, NM_RELEASEDCAPTURE
);
7530 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
7532 /* set left button down flag */
7533 infoPtr
->bLButtonDown
= TRUE
;
7535 lvHitTestInfo
.pt
.x
= pts
.x
;
7536 lvHitTestInfo
.pt
.y
= pts
.y
;
7538 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
7539 TRACE("at %s, nItem=%d\n", debugpoint(&pt
), nItem
);
7540 infoPtr
->nEditLabelItem
= -1;
7541 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
7543 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
7545 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
7546 infoPtr
->nEditLabelItem
= nItem
;
7548 LISTVIEW_SetSelection(infoPtr
, nItem
);
7552 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
7556 LISTVIEW_AddGroupSelection(infoPtr
, nItem
);
7557 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
7558 infoPtr
->nSelectionMark
= nItem
;
7564 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
7565 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
7567 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
7568 infoPtr
->nSelectionMark
= nItem
;
7571 else if (wKey
& MK_CONTROL
)
7575 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
7577 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
7578 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
7579 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
7580 infoPtr
->nSelectionMark
= nItem
;
7582 else if (wKey
& MK_SHIFT
)
7584 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
7588 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
7589 infoPtr
->nEditLabelItem
= nItem
;
7591 /* set selection (clears other pre-existing selections) */
7592 LISTVIEW_SetSelection(infoPtr
, nItem
);
7598 /* remove all selections */
7599 LISTVIEW_DeselectAll(infoPtr
);
7607 * Processes mouse up messages (left mouse button).
7610 * [I] infoPtr : valid pointer to the listview structure
7611 * [I] wKey : key flag
7612 * [I] pts : mouse coordinate
7617 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7619 LVHITTESTINFO lvHitTestInfo
;
7621 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7623 if (!infoPtr
->bLButtonDown
) return 0;
7625 lvHitTestInfo
.pt
.x
= pts
.x
;
7626 lvHitTestInfo
.pt
.y
= pts
.y
;
7628 /* send NM_CLICK notification */
7629 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
7630 notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
);
7632 /* set left button flag */
7633 infoPtr
->bLButtonDown
= FALSE
;
7635 /* if we clicked on a selected item, edit the label */
7636 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
7637 LISTVIEW_EditLabelT(infoPtr
, lvHitTestInfo
.iItem
, TRUE
);
7644 * Destroys the listview control (called after WM_DESTROY).
7647 * [I] infoPtr : valid pointer to the listview structure
7652 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
7656 /* delete all items */
7657 LISTVIEW_DeleteAllItems(infoPtr
);
7659 /* destroy data structure */
7660 DPA_Destroy(infoPtr
->hdpaItems
);
7661 if (infoPtr
->selectionRanges
) ranges_destroy(infoPtr
->selectionRanges
);
7663 /* destroy image lists */
7664 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
7666 if (infoPtr
->himlNormal
)
7667 ImageList_Destroy(infoPtr
->himlNormal
);
7668 if (infoPtr
->himlSmall
)
7669 ImageList_Destroy(infoPtr
->himlSmall
);
7670 if (infoPtr
->himlState
)
7671 ImageList_Destroy(infoPtr
->himlState
);
7674 /* destroy font, bkgnd brush */
7676 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
7677 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7679 /* free listview info pointer*/
7680 COMCTL32_Free(infoPtr
);
7682 SetWindowLongW(infoPtr
->hwndSelf
, 0, 0);
7688 * Handles notifications from header.
7691 * [I] infoPtr : valid pointer to the listview structure
7692 * [I] nCtrlId : control identifier
7693 * [I] lpnmh : notification information
7698 static LRESULT
LISTVIEW_HeaderNotification(LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
7700 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7702 TRACE("(lpnmh=%p)\n", lpnmh
);
7704 if (!lpnmh
|| lpnmh
->iItem
< 0 || lpnmh
->iItem
>= infoPtr
->hdpaColumns
->nItemCount
) return 0;
7706 switch (lpnmh
->hdr
.code
)
7710 case HDN_ITEMCHANGEDW
:
7711 case HDN_ITEMCHANGEDA
:
7713 COLUMN_INFO
*lpColumnInfo
;
7716 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
7720 hdi
.mask
= HDI_WIDTH
;
7721 if (!Header_GetItemW(infoPtr
->hwndHeader
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
7725 cxy
= lpnmh
->pitem
->cxy
;
7727 /* determine how much we change since the last know position */
7728 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
7729 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
7732 RECT rcCol
= lpColumnInfo
->rcHeader
;
7734 lpColumnInfo
->rcHeader
.right
+= dx
;
7735 LISTVIEW_ScrollColumns(infoPtr
, lpnmh
->iItem
+ 1, dx
);
7736 if (uView
== LVS_REPORT
&& is_redrawing(infoPtr
))
7738 /* this trick works for left aligned columns only */
7739 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7741 rcCol
.right
= min (rcCol
.right
, lpColumnInfo
->rcHeader
.right
);
7742 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- 3 * infoPtr
->ntmAveCharWidth
);
7744 rcCol
.top
= infoPtr
->rcList
.top
;
7745 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
7746 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
7752 case HDN_ITEMCLICKW
:
7753 case HDN_ITEMCLICKA
:
7755 /* Handle sorting by Header Column */
7758 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
7760 nmlv
.iSubItem
= lpnmh
->iItem
;
7761 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
7771 * Determines the type of structure to use.
7774 * [I] infoPtr : valid pointer to the listview structureof the sender
7775 * [I] hwndFrom : listview window handle
7776 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
7781 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
7783 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
7785 if (nCommand
!= NF_REQUERY
) return 0;
7787 infoPtr
->notifyFormat
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
7794 * Paints/Repaints the listview control.
7797 * [I] infoPtr : valid pointer to the listview structure
7798 * [I] hdc : device context handle
7803 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
7805 TRACE("(hdc=%p)\n", hdc
);
7807 if (infoPtr
->bFirstPaint
)
7809 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7811 infoPtr
->bFirstPaint
= FALSE
;
7812 LISTVIEW_UpdateItemSize(infoPtr
);
7813 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)
7814 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
7815 LISTVIEW_UpdateScroll(infoPtr
);
7818 LISTVIEW_Refresh(infoPtr
, hdc
);
7823 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
7825 if (ps
.fErase
) LISTVIEW_FillBkgnd(infoPtr
, hdc
, &ps
.rcPaint
);
7826 LISTVIEW_Refresh(infoPtr
, hdc
);
7827 EndPaint(infoPtr
->hwndSelf
, &ps
);
7835 * Processes double click messages (right mouse button).
7838 * [I] infoPtr : valid pointer to the listview structure
7839 * [I] wKey : key flag
7840 * [I] pts : mouse coordinate
7845 static LRESULT
LISTVIEW_RButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7847 LVHITTESTINFO lvHitTestInfo
;
7849 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7851 /* send NM_RELEASEDCAPTURE notification */
7852 notify(infoPtr
, NM_RELEASEDCAPTURE
);
7854 /* send NM_RDBLCLK notification */
7855 lvHitTestInfo
.pt
.x
= pts
.x
;
7856 lvHitTestInfo
.pt
.y
= pts
.y
;
7857 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
7858 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
7865 * Processes mouse down messages (right mouse button).
7868 * [I] infoPtr : valid pointer to the listview structure
7869 * [I] wKey : key flag
7870 * [I] pts : mouse coordinate
7875 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7877 LVHITTESTINFO lvHitTestInfo
;
7880 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7882 /* send NM_RELEASEDCAPTURE notification */
7883 notify(infoPtr
, NM_RELEASEDCAPTURE
);
7885 /* make sure the listview control window has the focus */
7886 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
7888 /* set right button down flag */
7889 infoPtr
->bRButtonDown
= TRUE
;
7891 /* determine the index of the selected item */
7892 lvHitTestInfo
.pt
.x
= pts
.x
;
7893 lvHitTestInfo
.pt
.y
= pts
.y
;
7894 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
7896 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
7898 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
7899 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
7900 !LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
7901 LISTVIEW_SetSelection(infoPtr
, nItem
);
7905 LISTVIEW_DeselectAll(infoPtr
);
7913 * Processes mouse up messages (right mouse button).
7916 * [I] infoPtr : valid pointer to the listview structure
7917 * [I] wKey : key flag
7918 * [I] pts : mouse coordinate
7923 static LRESULT
LISTVIEW_RButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7925 LVHITTESTINFO lvHitTestInfo
;
7928 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7930 if (!infoPtr
->bRButtonDown
) return 0;
7932 /* set button flag */
7933 infoPtr
->bRButtonDown
= FALSE
;
7935 /* Send NM_RClICK notification */
7936 lvHitTestInfo
.pt
.x
= pts
.x
;
7937 lvHitTestInfo
.pt
.y
= pts
.y
;
7938 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
7939 notify_click(infoPtr
, NM_RCLICK
, &lvHitTestInfo
);
7941 /* Change to screen coordinate for WM_CONTEXTMENU */
7942 pt
= lvHitTestInfo
.pt
;
7943 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
7945 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
7946 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
7947 (WPARAM
)infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
7958 * [I] infoPtr : valid pointer to the listview structure
7959 * [I] hwnd : window handle of window containing the cursor
7960 * [I] nHittest : hit-test code
7961 * [I] wMouseMsg : ideintifier of the mouse message
7964 * TRUE if cursor is set
7967 static BOOL
LISTVIEW_SetCursor(LISTVIEW_INFO
*infoPtr
, HWND hwnd
, UINT nHittest
, UINT wMouseMsg
)
7969 LVHITTESTINFO lvHitTestInfo
;
7971 if(!(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)) return FALSE
;
7973 if(!infoPtr
->hHotCursor
) return FALSE
;
7975 GetCursorPos(&lvHitTestInfo
.pt
);
7976 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) return FALSE
;
7978 SetCursor(infoPtr
->hHotCursor
);
7988 * [I] infoPtr : valid pointer to the listview structure
7989 * [I] hwndLoseFocus : handle of previously focused window
7994 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
7996 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
7998 /* if we have the focus already, there's nothing to do */
7999 if (infoPtr
->bFocus
) return 0;
8001 /* send NM_SETFOCUS notification */
8002 notify(infoPtr
, NM_SETFOCUS
);
8004 /* set window focus flag */
8005 infoPtr
->bFocus
= TRUE
;
8007 /* put the focus rect back on */
8008 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
8010 /* redraw all visible selected items */
8011 LISTVIEW_InvalidateSelectedItems(infoPtr
);
8021 * [I] infoPtr : valid pointer to the listview structure
8022 * [I] fRedraw : font handle
8023 * [I] fRedraw : redraw flag
8028 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
8030 HFONT oldFont
= infoPtr
->hFont
;
8032 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
8034 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
8035 if (infoPtr
->hFont
== oldFont
) return 0;
8037 LISTVIEW_SaveTextMetrics(infoPtr
);
8039 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
8040 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
8042 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
8049 * Message handling for WM_SETREDRAW.
8050 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
8053 * [I] infoPtr : valid pointer to the listview structure
8054 * [I] bRedraw: state of redraw flag
8057 * DefWinProc return value
8059 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
8061 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
8063 /* we can not use straight equality here because _any_ non-zero value is TRUE */
8064 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
8066 infoPtr
->bRedraw
= bRedraw
;
8068 if(!bRedraw
) return 0;
8070 if (is_autoarrange(infoPtr
))
8071 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8072 LISTVIEW_UpdateScroll(infoPtr
);
8074 /* despite what the WM_SETREDRAW docs says, apps expect us
8075 * to invalidate the listview here... stupid! */
8076 LISTVIEW_InvalidateList(infoPtr
);
8083 * Resizes the listview control. This function processes WM_SIZE
8084 * messages. At this time, the width and height are not used.
8087 * [I] infoPtr : valid pointer to the listview structure
8088 * [I] Width : new width
8089 * [I] Height : new height
8094 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
8096 RECT rcOld
= infoPtr
->rcList
;
8098 TRACE("(width=%d, height=%d)\n", Width
, Height
);
8100 LISTVIEW_UpdateSize(infoPtr
);
8101 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
8103 /* do not bother with display related stuff if we're not redrawing */
8104 if (!is_redrawing(infoPtr
)) return 0;
8106 if (is_autoarrange(infoPtr
))
8107 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8109 LISTVIEW_UpdateScroll(infoPtr
);
8111 /* refresh all only for lists whose height changed significantly */
8112 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_LIST
&&
8113 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
8114 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
8115 LISTVIEW_InvalidateList(infoPtr
);
8122 * Sets the size information.
8125 * [I] infoPtr : valid pointer to the listview structure
8130 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
8132 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
8134 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
8136 if (uView
== LVS_LIST
)
8138 /* Apparently the "LIST" style is supposed to have the same
8139 * number of items in a column even if there is no scroll bar.
8140 * Since if a scroll bar already exists then the bottom is already
8141 * reduced, only reduce if the scroll bar does not currently exist.
8142 * The "2" is there to mimic the native control. I think it may be
8143 * related to either padding or edges. (GLA 7/2002)
8145 if (!(infoPtr
->dwStyle
& WS_HSCROLL
))
8146 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
8147 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
8149 else if (uView
== LVS_REPORT
)
8154 hl
.prc
= &infoPtr
->rcList
;
8156 Header_Layout(infoPtr
->hwndHeader
, &hl
);
8158 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
8160 if (!(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
))
8161 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
8167 * Processes WM_STYLECHANGED messages.
8170 * [I] infoPtr : valid pointer to the listview structure
8171 * [I] wStyleType : window style type (normal or extended)
8172 * [I] lpss : window style information
8177 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
8178 const STYLESTRUCT
*lpss
)
8180 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
8181 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
8183 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
8184 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
8186 if (wStyleType
!= GWL_STYLE
) return 0;
8188 /* FIXME: if LVS_NOSORTHEADER changed, update header */
8189 /* what if LVS_OWNERDATA changed? */
8190 /* or LVS_SINGLESEL */
8191 /* or LVS_SORT{AS,DES}CENDING */
8193 infoPtr
->dwStyle
= lpss
->styleNew
;
8195 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
8196 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
8197 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
8199 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
8200 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
8201 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
8203 if (uNewView
!= uOldView
)
8205 SIZE oldIconSize
= infoPtr
->iconSize
;
8208 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8209 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8211 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
8212 SetRectEmpty(&infoPtr
->rcFocus
);
8214 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
8215 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
8217 if (uNewView
== LVS_ICON
)
8219 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
8221 TRACE("icon old size=(%ld,%ld), new size=(%ld,%ld)\n",
8222 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
8223 LISTVIEW_SetIconSpacing(infoPtr
, 0);
8226 else if (uNewView
== LVS_REPORT
)
8231 hl
.prc
= &infoPtr
->rcList
;
8233 Header_Layout(infoPtr
->hwndHeader
, &hl
);
8234 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
8237 LISTVIEW_UpdateItemSize(infoPtr
);
8240 if (uNewView
== LVS_REPORT
)
8241 ShowWindow(infoPtr
->hwndHeader
, (LVS_NOCOLUMNHEADER
& lpss
->styleNew
) ? SW_HIDE
: SW_SHOWNORMAL
);
8243 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
8244 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
8245 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8247 /* update the size of the client area */
8248 LISTVIEW_UpdateSize(infoPtr
);
8250 /* add scrollbars if needed */
8251 LISTVIEW_UpdateScroll(infoPtr
);
8253 /* invalidate client area + erase background */
8254 LISTVIEW_InvalidateList(infoPtr
);
8261 * Window procedure of the listview control.
8264 static LRESULT WINAPI
8265 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
8267 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongW(hwnd
, 0);
8269 TRACE("(uMsg=%x wParam=%x lParam=%lx)\n", uMsg
, wParam
, lParam
);
8271 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
8272 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
8276 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
8281 case LVM_APPROXIMATEVIEWRECT
:
8282 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
8283 LOWORD(lParam
), HIWORD(lParam
));
8285 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
8287 /* case LVM_CANCELEDITLABEL: */
8289 /* case LVM_CREATEDRAGIMAGE: */
8291 case LVM_DELETEALLITEMS
:
8292 return LISTVIEW_DeleteAllItems(infoPtr
);
8294 case LVM_DELETECOLUMN
:
8295 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
8297 case LVM_DELETEITEM
:
8298 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
8300 case LVM_EDITLABELW
:
8301 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, TRUE
);
8303 case LVM_EDITLABELA
:
8304 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, FALSE
);
8306 /* case LVM_ENABLEGROUPVIEW: */
8308 case LVM_ENSUREVISIBLE
:
8309 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
8312 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
8315 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
8317 case LVM_GETBKCOLOR
:
8318 return infoPtr
->clrBk
;
8320 /* case LVM_GETBKIMAGE: */
8322 case LVM_GETCALLBACKMASK
:
8323 return infoPtr
->uCallbackMask
;
8325 case LVM_GETCOLUMNA
:
8326 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
8328 case LVM_GETCOLUMNW
:
8329 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
8331 case LVM_GETCOLUMNORDERARRAY
:
8332 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
8334 case LVM_GETCOLUMNWIDTH
:
8335 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
8337 case LVM_GETCOUNTPERPAGE
:
8338 return LISTVIEW_GetCountPerPage(infoPtr
);
8340 case LVM_GETEDITCONTROL
:
8341 return (LRESULT
)infoPtr
->hwndEdit
;
8343 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
8344 return infoPtr
->dwLvExStyle
;
8346 /* case LVM_GETGROUPINFO: */
8348 /* case LVM_GETGROUPMETRICS: */
8351 return (LRESULT
)infoPtr
->hwndHeader
;
8353 case LVM_GETHOTCURSOR
:
8354 return (LRESULT
)infoPtr
->hHotCursor
;
8356 case LVM_GETHOTITEM
:
8357 return infoPtr
->nHotItem
;
8359 case LVM_GETHOVERTIME
:
8360 return infoPtr
->dwHoverTime
;
8362 case LVM_GETIMAGELIST
:
8363 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
8365 /* case LVM_GETINSERTMARK: */
8367 /* case LVM_GETINSERTMARKCOLOR: */
8369 /* case LVM_GETINSERTMARKRECT: */
8371 case LVM_GETISEARCHSTRINGA
:
8372 case LVM_GETISEARCHSTRINGW
:
8373 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
8377 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
8380 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
8382 case LVM_GETITEMCOUNT
:
8383 return infoPtr
->nItemCount
;
8385 case LVM_GETITEMPOSITION
:
8386 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
8388 case LVM_GETITEMRECT
:
8389 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
8391 case LVM_GETITEMSPACING
:
8392 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
8394 case LVM_GETITEMSTATE
:
8395 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
8397 case LVM_GETITEMTEXTA
:
8398 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
8400 case LVM_GETITEMTEXTW
:
8401 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
8403 case LVM_GETNEXTITEM
:
8404 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
8406 case LVM_GETNUMBEROFWORKAREAS
:
8407 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
8411 if (!lParam
) return FALSE
;
8412 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
8415 /* case LVM_GETOUTLINECOLOR: */
8417 /* case LVM_GETSELECTEDCOLUMN: */
8419 case LVM_GETSELECTEDCOUNT
:
8420 return LISTVIEW_GetSelectedCount(infoPtr
);
8422 case LVM_GETSELECTIONMARK
:
8423 return infoPtr
->nSelectionMark
;
8425 case LVM_GETSTRINGWIDTHA
:
8426 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, FALSE
);
8428 case LVM_GETSTRINGWIDTHW
:
8429 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, TRUE
);
8431 case LVM_GETSUBITEMRECT
:
8432 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
8434 case LVM_GETTEXTBKCOLOR
:
8435 return infoPtr
->clrTextBk
;
8437 case LVM_GETTEXTCOLOR
:
8438 return infoPtr
->clrText
;
8440 /* case LVM_GETTILEINFO: */
8442 /* case LVM_GETTILEVIEWINFO: */
8444 case LVM_GETTOOLTIPS
:
8445 FIXME("LVM_GETTOOLTIPS: unimplemented\n");
8448 case LVM_GETTOPINDEX
:
8449 return LISTVIEW_GetTopIndex(infoPtr
);
8451 /*case LVM_GETUNICODEFORMAT:
8452 FIXME("LVM_GETUNICODEFORMAT: unimplemented\n");
8455 /* case LVM_GETVIEW: */
8457 case LVM_GETVIEWRECT
:
8458 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
8460 case LVM_GETWORKAREAS
:
8461 FIXME("LVM_GETWORKAREAS: unimplemented\n");
8464 /* case LVM_HASGROUP: */
8467 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, FALSE
);
8469 case LVM_INSERTCOLUMNA
:
8470 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
8472 case LVM_INSERTCOLUMNW
:
8473 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
8475 /* case LVM_INSERTGROUP: */
8477 /* case LVM_INSERTGROUPSORTED: */
8479 case LVM_INSERTITEMA
:
8480 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
8482 case LVM_INSERTITEMW
:
8483 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
8485 /* case LVM_INSERTMARKHITTEST: */
8487 /* case LVM_ISGROUPVIEWENABLED: */
8489 /* case LVM_MAPIDTOINDEX: */
8491 /* case LVM_MAPINDEXTOID: */
8493 /* case LVM_MOVEGROUP: */
8495 /* case LVM_MOVEITEMTOGROUP: */
8497 case LVM_REDRAWITEMS
:
8498 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
8500 /* case LVM_REMOVEALLGROUPS: */
8502 /* case LVM_REMOVEGROUP: */
8505 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
8507 case LVM_SETBKCOLOR
:
8508 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
8510 /* case LVM_SETBKIMAGE: */
8512 case LVM_SETCALLBACKMASK
:
8513 infoPtr
->uCallbackMask
= (UINT
)wParam
;
8516 case LVM_SETCOLUMNA
:
8517 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
8519 case LVM_SETCOLUMNW
:
8520 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
8522 case LVM_SETCOLUMNORDERARRAY
:
8523 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
8525 case LVM_SETCOLUMNWIDTH
:
8526 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, SLOWORD(lParam
));
8528 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
8529 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
8531 /* case LVM_SETGROUPINFO: */
8533 /* case LVM_SETGROUPMETRICS: */
8535 case LVM_SETHOTCURSOR
:
8536 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
8538 case LVM_SETHOTITEM
:
8539 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
8541 case LVM_SETHOVERTIME
:
8542 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)wParam
);
8544 case LVM_SETICONSPACING
:
8545 return LISTVIEW_SetIconSpacing(infoPtr
, (DWORD
)lParam
);
8547 case LVM_SETIMAGELIST
:
8548 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
8550 /* case LVM_SETINFOTIP: */
8552 /* case LVM_SETINSERTMARK: */
8554 /* case LVM_SETINSERTMARKCOLOR: */
8557 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
8560 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
8562 case LVM_SETITEMCOUNT
:
8563 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
8565 case LVM_SETITEMPOSITION
:
8567 POINT pt
= { SLOWORD(lParam
), SHIWORD(lParam
) };
8568 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, pt
);
8571 case LVM_SETITEMPOSITION32
:
8572 if (lParam
== 0) return FALSE
;
8573 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, *((POINT
*)lParam
));
8575 case LVM_SETITEMSTATE
:
8576 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
8578 case LVM_SETITEMTEXTA
:
8579 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
8581 case LVM_SETITEMTEXTW
:
8582 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
8584 /* case LVM_SETOUTLINECOLOR: */
8586 /* case LVM_SETSELECTEDCOLUMN: */
8588 case LVM_SETSELECTIONMARK
:
8589 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
8591 case LVM_SETTEXTBKCOLOR
:
8592 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
8594 case LVM_SETTEXTCOLOR
:
8595 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
8597 /* case LVM_SETTILEINFO: */
8599 /* case LVM_SETTILEVIEWINFO: */
8601 /* case LVM_SETTILEWIDTH: */
8603 /* case LVM_SETTOOLTIPS: */
8605 /* case LVM_SETUNICODEFORMAT: */
8607 /* case LVM_SETVIEW: */
8609 /* case LVM_SETWORKAREAS: */
8611 /* case LVM_SORTGROUPS: */
8614 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, (LPARAM
)wParam
);
8616 /* LVM_SORTITEMSEX: */
8618 case LVM_SUBITEMHITTEST
:
8619 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
8622 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
8625 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
8628 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
8631 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
8634 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
8637 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
8640 return (LRESULT
)infoPtr
->hFont
;
8643 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
8646 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
8649 return LISTVIEW_KillFocus(infoPtr
);
8651 case WM_LBUTTONDBLCLK
:
8652 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8654 case WM_LBUTTONDOWN
:
8655 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8658 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8661 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8664 return LISTVIEW_MouseHover(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8667 return LISTVIEW_NCDestroy(infoPtr
);
8670 if (lParam
&& ((LPNMHDR
)lParam
)->hwndFrom
== infoPtr
->hwndHeader
)
8671 return LISTVIEW_HeaderNotification(infoPtr
, (LPNMHEADERW
)lParam
);
8674 case WM_NOTIFYFORMAT
:
8675 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
8678 return LISTVIEW_Paint(infoPtr
, (HDC
)wParam
);
8680 case WM_RBUTTONDBLCLK
:
8681 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8683 case WM_RBUTTONDOWN
:
8684 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8687 return LISTVIEW_RButtonUp(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8690 if(LISTVIEW_SetCursor(infoPtr
, (HWND
)wParam
, LOWORD(lParam
), HIWORD(lParam
)))
8695 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
8698 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
8701 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
8704 return LISTVIEW_Size(infoPtr
, (int)SLOWORD(lParam
), (int)SHIWORD(lParam
));
8706 case WM_STYLECHANGED
:
8707 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
8709 case WM_SYSCOLORCHANGE
:
8710 COMCTL32_RefreshSysColors();
8713 /* case WM_TIMER: */
8716 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
8719 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
8720 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
8721 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
8723 case WM_WINDOWPOSCHANGED
:
8724 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
8726 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
8727 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
8728 /* FIXME: why do we need this here? */
8729 LISTVIEW_UpdateSize(infoPtr
);
8730 LISTVIEW_UpdateScroll(infoPtr
);
8732 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
8734 /* case WM_WININICHANGE: */
8737 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
8738 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
8741 /* call default window procedure */
8742 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
8750 * Registers the window class.
8758 void LISTVIEW_Register(void)
8762 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
8763 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
8764 wndClass
.lpfnWndProc
= (WNDPROC
)LISTVIEW_WindowProc
;
8765 wndClass
.cbClsExtra
= 0;
8766 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
8767 wndClass
.hCursor
= LoadCursorW(0, IDC_ARROWW
);
8768 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
8769 wndClass
.lpszClassName
= WC_LISTVIEWW
;
8770 RegisterClassW(&wndClass
);
8775 * Unregisters the window class.
8783 void LISTVIEW_Unregister(void)
8785 UnregisterClassW(WC_LISTVIEWW
, (HINSTANCE
)NULL
);
8790 * Handle any WM_COMMAND messages
8793 * [I] infoPtr : valid pointer to the listview structure
8794 * [I] wParam : the first message parameter
8795 * [I] lParam : the second message parameter
8800 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
8802 switch (HIWORD(wParam
))
8807 * Adjust the edit window size
8810 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
8811 HFONT hFont
, hOldFont
= 0;
8816 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
8817 len
= GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
8818 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
8820 /* Select font to get the right dimension of the string */
8821 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
8824 hOldFont
= SelectObject(hdc
, hFont
);
8827 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
8829 TEXTMETRICW textMetric
;
8831 /* Add Extra spacing for the next character */
8832 GetTextMetricsW(hdc
, &textMetric
);
8833 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
8841 rect
.bottom
- rect
.top
,
8842 SWP_DRAWFRAME
|SWP_NOMOVE
);
8845 SelectObject(hdc
, hOldFont
);
8847 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8853 return SendMessageW (GetParent (infoPtr
->hwndSelf
), WM_COMMAND
, wParam
, lParam
);
8862 * Subclassed edit control windproc function
8865 * [I] hwnd : the edit window handle
8866 * [I] uMsg : the message that is to be processed
8867 * [I] wParam : first message parameter
8868 * [I] lParam : second message parameter
8869 * [I] isW : TRUE if input is Unicode
8874 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
8876 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongW(GetParent(hwnd
), 0);
8877 BOOL cancel
= FALSE
;
8879 TRACE("(hwnd=%p, uMsg=%x, wParam=%x, lParam=%lx, isW=%d)\n",
8880 hwnd
, uMsg
, wParam
, lParam
, isW
);
8885 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
8892 WNDPROC editProc
= infoPtr
->EditWndProc
;
8893 infoPtr
->EditWndProc
= 0;
8894 SetWindowLongW(hwnd
, GWL_WNDPROC
, (LONG
)editProc
);
8895 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
8899 if (VK_ESCAPE
== (INT
)wParam
)
8904 else if (VK_RETURN
== (INT
)wParam
)
8908 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
8912 if (infoPtr
->hwndEdit
)
8914 LPWSTR buffer
= NULL
;
8916 infoPtr
->hwndEdit
= 0;
8919 DWORD len
= isW
? GetWindowTextLengthW(hwnd
) : GetWindowTextLengthA(hwnd
);
8923 if ( (buffer
= COMCTL32_Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))) )
8925 if (isW
) GetWindowTextW(hwnd
, buffer
, len
+1);
8926 else GetWindowTextA(hwnd
, (CHAR
*)buffer
, len
+1);
8930 LISTVIEW_EndEditLabelT(infoPtr
, buffer
, isW
);
8932 if (buffer
) COMCTL32_Free(buffer
);
8936 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
8942 * Subclassed edit control Unicode windproc function
8945 * [I] hwnd : the edit window handle
8946 * [I] uMsg : the message that is to be processed
8947 * [I] wParam : first message parameter
8948 * [I] lParam : second message parameter
8952 LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
8954 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
8959 * Subclassed edit control ANSI windproc function
8962 * [I] hwnd : the edit window handle
8963 * [I] uMsg : the message that is to be processed
8964 * [I] wParam : first message parameter
8965 * [I] lParam : second message parameter
8969 LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
8971 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
8976 * Creates a subclassed edit cotrol
8979 * [I] infoPtr : valid pointer to the listview structure
8980 * [I] text : initial text for the edit
8981 * [I] style : the window style
8982 * [I] isW : TRUE if input is Unicode
8986 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, DWORD style
,
8987 INT x
, INT y
, INT width
, INT height
, BOOL isW
)
8989 WCHAR editName
[5] = { 'E', 'd', 'i', 't', '\0' };
8994 TEXTMETRICW textMetric
;
8995 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongW(infoPtr
->hwndSelf
, GWL_HINSTANCE
);
8997 TRACE("(text=%s, ..., isW=%d)\n", debugtext_t(text
, isW
), isW
);
8999 style
|= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|WS_BORDER
;
9000 hdc
= GetDC(infoPtr
->hwndSelf
);
9002 /* Select the font to get appropriate metric dimensions */
9003 if(infoPtr
->hFont
!= 0)
9004 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
9006 /*Get String Lenght in pixels */
9007 GetTextExtentPoint32W(hdc
, text
, lstrlenW(text
), &sz
);
9009 /*Add Extra spacing for the next character */
9010 GetTextMetricsW(hdc
, &textMetric
);
9011 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
9013 if(infoPtr
->hFont
!= 0)
9014 SelectObject(hdc
, hOldFont
);
9016 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9018 hedit
= CreateWindowW(editName
, text
, style
, x
, y
, sz
.cx
, height
, infoPtr
->hwndSelf
, 0, hinst
, 0);
9020 hedit
= CreateWindowA("Edit", (LPCSTR
)text
, style
, x
, y
, sz
.cx
, height
, infoPtr
->hwndSelf
, 0, hinst
, 0);
9022 if (!hedit
) return 0;
9024 infoPtr
->EditWndProc
= (WNDPROC
)
9025 (isW
? SetWindowLongW(hedit
, GWL_WNDPROC
, (LONG
)EditLblWndProcW
) :
9026 SetWindowLongA(hedit
, GWL_WNDPROC
, (LONG
)EditLblWndProcA
) );
9028 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);