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 * -- LVSICF_NOINVALIDATEALL, LVSICF_NOSCROLL not implemented
52 * -- LISTVIEW_SortItems is broken
53 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
56 * -- LISTVIEW_SetItemCount is too invalidation happy
57 * -- in sorted mode, LISTVIEW_InsertItemT sorts the array,
58 * instead of inserting in the right spot
59 * -- we should keep an ordered array of coordinates in iconic mode
60 * this would allow to frame items (iterator_frameditems),
61 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
64 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
71 * -- LVS_NOSCROLL (see Q137520)
72 * -- LVS_SORTASCENDING, LVS_SORTDESCENDING
75 * -- LVS_EX_BORDERSELECT
76 * -- LVS_EX_CHECKBOXES
79 * -- LVS_EX_HEADERDRAGDROP
82 * -- LVS_EX_MULTIWORKAREAS
83 * -- LVS_EX_ONECLICKACTIVATE
85 * -- LVS_EX_SIMPLESELECT
86 * -- LVS_EX_SUBITEMIMAGES
87 * -- LVS_EX_TRACKSELECT
88 * -- LVS_EX_TWOCLICKACTIVATE
89 * -- LVS_EX_UNDERLINECOLD
90 * -- LVS_EX_UNDERLINEHOT
93 * -- LVN_BEGINDRAG, LVN_BEGINRDRAG
94 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
99 * -- LVN_ODSTATECHANGED
104 * -- LVM_CANCELEDITLABEL
105 * -- LVM_CREATEDRAGIMAGE
106 * -- LVM_ENABLEGROUPVIEW
107 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
108 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
109 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
110 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
111 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
112 * -- LVM_GETINSERTMARKRECT
113 * -- LVM_GETNUMBEROFWORKAREAS
114 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
115 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
116 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
117 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
118 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
119 * -- LVM_GETTOOLTIPS, LVM_SETTOOLTIPS
120 * -- LVM_GETUNICODEFORMAT, LVM_SETUNICODEFORMAT
121 * -- LVM_GETVIEW, LVM_SETVIEW
122 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
123 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
124 * -- LVM_INSERTGROUPSORTED
125 * -- LVM_INSERTMARKHITTEST
126 * -- LVM_ISGROUPVIEWENABLED
127 * -- LVM_MAPIDTOINDEX, LVM_MAPINDEXTOID
129 * -- LVM_MOVEITEMTOGROUP
131 * -- LVM_SETTILEWIDTH
135 * Known differences in message stream from native control (not known if
136 * these differences cause problems):
137 * LVM_INSERTITEM issues LVM_SETITEMSTATE and LVM_SETITEM in certain cases.
138 * LVM_SETITEM does not always issue LVN_ITEMCHANGING/LVN_ITEMCHANGED.
139 * WM_CREATE does not issue WM_QUERYUISTATE and associated registry
140 * processing for "USEDOUBLECLICKTIME".
144 #include "wine/port.h"
155 #include "commctrl.h"
156 #include "comctl32.h"
158 #include "wine/debug.h"
159 #include "wine/unicode.h"
161 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
163 /* make sure you set this to 0 for production use! */
164 #define DEBUG_RANGES 1
166 typedef struct tagCOLUMN_INFO
168 RECT rcHeader
; /* tracks the header's rectangle */
169 int fmt
; /* same as LVCOLUMN.fmt */
172 typedef struct tagITEMHDR
176 } ITEMHDR
, *LPITEMHDR
;
178 typedef struct tagSUBITEM_INFO
184 typedef struct tagITEM_INFO
192 typedef struct tagRANGE
198 typedef struct tagRANGES
203 typedef struct tagITERATOR
212 typedef struct tagLISTVIEW_INFO
219 COLORREF clrTextBkDefault
;
220 HIMAGELIST himlNormal
;
221 HIMAGELIST himlSmall
;
222 HIMAGELIST himlState
;
227 RANGES selectionRanges
;
231 RECT rcList
; /* This rectangle is really the window
232 * client rectangle possibly reduced by the
233 * horizontal scroll bar and/or header - see
234 * LISTVIEW_UpdateSize. This rectangle offset
235 * by the LISTVIEW_GetOrigin value is in
236 * client coordinates */
245 INT ntmHeight
; /* from GetTextMetrics from above font */
250 DWORD dwStyle
; /* the cached window GWL_STYLE */
251 DWORD dwLvExStyle
; /* extended listview style */
252 INT nItemCount
; /* the number of items in the list */
253 HDPA hdpaItems
; /* array ITEM_INFO pointers */
254 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
255 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
256 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
257 POINT currIconPos
; /* this is the position next icon will be placed */
258 PFNLVCOMPARE pfnCompare
;
265 DWORD lastKeyPressTimestamp
;
267 INT nSearchParamLength
;
268 WCHAR szSearchParam
[ MAX_PATH
];
275 /* How many we debug buffer to allocate */
276 #define DEBUG_BUFFERS 20
277 /* The size of a single debug bbuffer */
278 #define DEBUG_BUFFER_SIZE 256
280 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
281 #define SB_INTERNAL -1
283 /* maximum size of a label */
284 #define DISP_TEXT_SIZE 512
286 /* padding for items in list and small icon display modes */
287 #define WIDTH_PADDING 12
289 /* padding for items in list, report and small icon display modes */
290 #define HEIGHT_PADDING 1
292 /* offset of items in report display mode */
293 #define REPORT_MARGINX 2
295 /* padding for icon in large icon display mode
296 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
297 * that HITTEST will see.
298 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
299 * ICON_TOP_PADDING - sum of the two above.
300 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
301 * LABEL_VERT_PADDING - between bottom of text and end of box
303 * ICON_LR_PADDING - additional width above icon size.
304 * ICON_LR_HALF - half of the above value
306 #define ICON_TOP_PADDING_NOTHITABLE 2
307 #define ICON_TOP_PADDING_HITABLE 2
308 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
309 #define ICON_BOTTOM_PADDING 4
310 #define LABEL_VERT_PADDING 7
311 #define ICON_LR_PADDING 16
312 #define ICON_LR_HALF (ICON_LR_PADDING/2)
314 /* default label width for items in list and small icon display modes */
315 #define DEFAULT_LABEL_WIDTH 40
317 /* default column width for items in list display mode */
318 #define DEFAULT_COLUMN_WIDTH 128
320 /* Size of "line" scroll for V & H scrolls */
321 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
323 /* Padding betwen image and label */
324 #define IMAGE_PADDING 2
326 /* Padding behind the label */
327 #define TRAILING_PADDING 5
329 /* Border for the icon caption */
330 #define CAPTION_BORDER 2
332 /* Standard DrawText flags */
333 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
334 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
335 #define LV_SL_DT_FLAGS (DT_TOP | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
337 /* The time in milisecods to reset the search in the list */
338 #define KEY_DELAY 450
340 /* Dump the LISTVIEW_INFO structure to the debug channel */
341 #define LISTVIEW_DUMP(iP) do { \
342 TRACE("hwndSelf=%p, clrBk=0x%06lx, clrText=0x%06lx, clrTextBk=0x%06lx, ItemHeight=%d, ItemWidth=%d, Style=0x%08lx\n", \
343 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
344 iP->nItemHeight, iP->nItemWidth, infoPtr->dwStyle); \
345 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08lx, Focus=%d\n", \
346 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
347 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
348 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%ld, icSz.cy=%ld, icSp.cx=%ld, icSp.cy=%ld, notifyFmt=%d\n", \
349 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
350 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
351 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, debugrect(&iP->rcList)); \
356 * forward declarations
358 static BOOL
LISTVIEW_GetItemT(LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
359 static void LISTVIEW_GetItemBox(LISTVIEW_INFO
*, INT
, LPRECT
);
360 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO
*, INT
, LPPOINT
);
361 static BOOL
LISTVIEW_GetItemPosition(LISTVIEW_INFO
*, INT
, LPPOINT
);
362 static BOOL
LISTVIEW_GetItemRect(LISTVIEW_INFO
*, INT
, LPRECT
);
363 static INT
LISTVIEW_GetLabelWidth(LISTVIEW_INFO
*, INT
);
364 static void LISTVIEW_GetOrigin(LISTVIEW_INFO
*, LPPOINT
);
365 static BOOL
LISTVIEW_GetViewRect(LISTVIEW_INFO
*, LPRECT
);
366 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*, INT
);
367 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
368 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*);
369 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*, INT
);
370 static BOOL
LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
371 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*, INT
, BOOL
);
372 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
373 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*, PFNLVCOMPARE
, LPARAM
);
374 static INT
LISTVIEW_GetStringWidthT(LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
375 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
);
376 static UINT
LISTVIEW_GetItemState(LISTVIEW_INFO
*, INT
, UINT
);
377 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, LPLVITEMW
);
378 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
379 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
380 static INT
LISTVIEW_GetTopIndex(LISTVIEW_INFO
*);
381 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
382 static HWND
CreateEditLabelT(LISTVIEW_INFO
*, LPCWSTR
, DWORD
, INT
, INT
, INT
, INT
, BOOL
);
384 /******** Text handling functions *************************************/
386 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
387 * text string. The string may be ANSI or Unicode, in which case
388 * the boolean isW tells us the type of the string.
390 * The name of the function tell what type of strings it expects:
391 * W: Unicode, T: ANSI/Unicode - function of isW
394 static inline BOOL
is_textW(LPCWSTR text
)
396 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
399 static inline BOOL
is_textT(LPCWSTR text
, BOOL isW
)
401 /* we can ignore isW since LPSTR_TEXTCALLBACKW == LPSTR_TEXTCALLBACKA */
402 return is_textW(text
);
405 static inline int textlenT(LPCWSTR text
, BOOL isW
)
407 return !is_textT(text
, isW
) ? 0 :
408 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
411 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
414 if (isSrcW
) lstrcpynW(dest
, src
, max
);
415 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
417 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
418 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
421 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
423 LPWSTR wstr
= (LPWSTR
)text
;
425 if (!isW
&& is_textT(text
, isW
))
427 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
428 wstr
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
429 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
431 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
435 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
437 if (!isW
&& is_textT(wstr
, isW
)) HeapFree(GetProcessHeap(), 0, wstr
);
441 * dest is a pointer to a Unicode string
442 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
444 static BOOL
textsetptrT(LPWSTR
*dest
, LPWSTR src
, BOOL isW
)
448 if (src
== LPSTR_TEXTCALLBACKW
)
450 if (is_textW(*dest
)) COMCTL32_Free(*dest
);
451 *dest
= LPSTR_TEXTCALLBACKW
;
455 LPWSTR pszText
= textdupTtoW(src
, isW
);
456 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
457 bResult
= Str_SetPtrW(dest
, pszText
);
458 textfreeT(pszText
, isW
);
464 * compares a Unicode to a Unicode/ANSI text string
466 static inline int textcmpWT(LPWSTR aw
, LPWSTR bt
, BOOL isW
)
468 if (!aw
) return bt
? -1 : 0;
469 if (!bt
) return aw
? 1 : 0;
470 if (aw
== LPSTR_TEXTCALLBACKW
)
471 return bt
== LPSTR_TEXTCALLBACKW
? 0 : -1;
472 if (bt
!= LPSTR_TEXTCALLBACKW
)
474 LPWSTR bw
= textdupTtoW(bt
, isW
);
475 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
483 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
487 n
= min(min(n
, strlenW(s1
)), strlenW(s2
));
488 res
= CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
);
489 return res
? res
- sizeof(WCHAR
) : res
;
492 /******** Debugging functions *****************************************/
494 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
496 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
497 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
500 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
502 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
503 n
= min(textlenT(text
, isW
), n
);
504 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
507 static char* debug_getbuf()
509 static int index
= 0;
510 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
511 return buffers
[index
++ % DEBUG_BUFFERS
];
514 static inline char* debugrange(const RANGE
* lprng
)
518 char* buf
= debug_getbuf();
519 snprintf(buf
, DEBUG_BUFFER_SIZE
, "[%d, %d)", lprng
->lower
, lprng
->upper
);
521 } else return "(null)";
524 static inline char* debugpoint(const POINT
* lppt
)
528 char* buf
= debug_getbuf();
529 snprintf(buf
, DEBUG_BUFFER_SIZE
, "(%ld, %ld)", lppt
->x
, lppt
->y
);
531 } else return "(null)";
534 static inline char* debugrect(const RECT
* rect
)
538 char* buf
= debug_getbuf();
539 snprintf(buf
, DEBUG_BUFFER_SIZE
, "[(%d, %d);(%d, %d)]",
540 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
542 } else return "(null)";
545 static char* debugnmlistview(LPNMLISTVIEW plvnm
)
549 char* buf
= debug_getbuf();
550 snprintf(buf
, DEBUG_BUFFER_SIZE
, "iItem=%d, iSubItem=%d, uNewState=0x%x,"
551 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld\n",
552 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
553 plvnm
->uChanged
, debugpoint(&plvnm
->ptAction
), plvnm
->lParam
);
555 } else return "(null)";
558 static char* debuglvitem_t(LPLVITEMW lpLVItem
, BOOL isW
)
560 char* buf
= debug_getbuf(), *text
= buf
;
561 int len
, size
= DEBUG_BUFFER_SIZE
;
563 if (lpLVItem
== NULL
) return "(null)";
564 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
565 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
566 if (lpLVItem
->mask
& LVIF_STATE
)
567 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
569 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
570 if (lpLVItem
->mask
& LVIF_TEXT
)
571 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
573 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
574 if (lpLVItem
->mask
& LVIF_IMAGE
)
575 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
577 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
578 if (lpLVItem
->mask
& LVIF_PARAM
)
579 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
581 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
582 if (lpLVItem
->mask
& LVIF_INDENT
)
583 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
585 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
588 buf
= text
+ strlen(text
);
590 if (buf
- text
> 2) buf
[-2] = '}'; buf
[-1] = 0;
594 static char* debuglvcolumn_t(LPLVCOLUMNW lpColumn
, BOOL isW
)
596 char* buf
= debug_getbuf(), *text
= buf
;
597 int len
, size
= DEBUG_BUFFER_SIZE
;
599 if (lpColumn
== NULL
) return "(null)";
600 len
= snprintf(buf
, size
, "{");
601 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
602 if (lpColumn
->mask
& LVCF_SUBITEM
)
603 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
605 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
606 if (lpColumn
->mask
& LVCF_FMT
)
607 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
609 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
610 if (lpColumn
->mask
& LVCF_WIDTH
)
611 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
613 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
614 if (lpColumn
->mask
& LVCF_TEXT
)
615 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
617 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
618 if (lpColumn
->mask
& LVCF_IMAGE
)
619 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
621 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
622 if (lpColumn
->mask
& LVCF_ORDER
)
623 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
625 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
628 buf
= text
+ strlen(text
);
630 if (buf
- text
> 2) buf
[-2] = '}'; buf
[-1] = 0;
635 /******** Notification functions i************************************/
637 static LRESULT
notify_hdr(LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
641 TRACE("(code=%d)\n", code
);
643 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
644 pnmh
->idFrom
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_ID
);
646 result
= SendMessageW(GetParent(infoPtr
->hwndSelf
), WM_NOTIFY
,
647 (WPARAM
)pnmh
->idFrom
, (LPARAM
)pnmh
);
649 TRACE(" <= %ld\n", result
);
654 static inline LRESULT
notify(LISTVIEW_INFO
*infoPtr
, INT code
)
657 return notify_hdr(infoPtr
, code
, &nmh
);
660 static inline void notify_itemactivate(LISTVIEW_INFO
*infoPtr
)
662 notify(infoPtr
, LVN_ITEMACTIVATE
);
665 static inline LRESULT
notify_listview(LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
667 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
668 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
671 static LRESULT
notify_click(LISTVIEW_INFO
*infoPtr
, INT code
, LVHITTESTINFO
*lvht
)
675 ZeroMemory(&nmlv
, sizeof(nmlv
));
676 nmlv
.iItem
= lvht
->iItem
;
677 nmlv
.iSubItem
= lvht
->iSubItem
;
678 nmlv
.ptAction
= lvht
->pt
;
679 return notify_listview(infoPtr
, code
, &nmlv
);
682 static int get_ansi_notification(INT unicodeNotificationCode
)
684 switch (unicodeNotificationCode
)
686 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
687 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
688 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
689 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
690 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
691 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
693 ERR("unknown notification %x\n", unicodeNotificationCode
);
698 Send notification. depends on dispinfoW having same
699 structure as dispinfoA.
700 infoPtr : listview struct
701 notificationCode : *Unicode* notification code
702 pdi : dispinfo structure (can be unicode or ansi)
703 isW : TRUE if dispinfo is Unicode
705 static BOOL
notify_dispinfoT(LISTVIEW_INFO
*infoPtr
, INT notificationCode
, LPNMLVDISPINFOW pdi
, BOOL isW
)
707 BOOL bResult
= FALSE
;
708 BOOL convertToAnsi
= FALSE
, convertToUnicode
= FALSE
;
710 INT cchTempBufMax
= 0, savCchTextMax
= 0;
711 LPWSTR pszTempBuf
= NULL
, savPszText
= NULL
;
713 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_textT(pdi
->item
.pszText
, isW
))
715 convertToAnsi
= (isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
716 convertToUnicode
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
719 if (convertToAnsi
|| convertToUnicode
)
721 if (notificationCode
!= LVN_GETDISPINFOW
)
723 cchTempBufMax
= convertToUnicode
?
724 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
725 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
729 cchTempBufMax
= pdi
->item
.cchTextMax
;
730 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
733 pszTempBuf
= HeapAlloc(GetProcessHeap(), 0,
734 (convertToUnicode
? sizeof(WCHAR
) : sizeof(CHAR
)) * cchTempBufMax
);
735 if (!pszTempBuf
) return FALSE
;
736 if (convertToUnicode
)
737 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
738 pszTempBuf
, cchTempBufMax
);
740 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) pszTempBuf
,
741 cchTempBufMax
, NULL
, NULL
);
742 savCchTextMax
= pdi
->item
.cchTextMax
;
743 savPszText
= pdi
->item
.pszText
;
744 pdi
->item
.pszText
= pszTempBuf
;
745 pdi
->item
.cchTextMax
= cchTempBufMax
;
748 if (infoPtr
->notifyFormat
== NFR_ANSI
)
749 realNotifCode
= get_ansi_notification(notificationCode
);
751 realNotifCode
= notificationCode
;
752 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
753 bResult
= notify_hdr(infoPtr
, realNotifCode
, (LPNMHDR
)pdi
);
755 if (convertToUnicode
|| convertToAnsi
)
757 if (convertToUnicode
) /* note : pointer can be changed by app ! */
758 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) savPszText
,
759 savCchTextMax
, NULL
, NULL
);
761 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
762 savPszText
, savCchTextMax
);
763 pdi
->item
.pszText
= savPszText
; /* restores our buffer */
764 pdi
->item
.cchTextMax
= savCchTextMax
;
765 HeapFree(GetProcessHeap(), 0, pszTempBuf
);
770 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, LISTVIEW_INFO
*infoPtr
, HDC hdc
, LPRECT rcBounds
)
772 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
773 lpnmlvcd
->nmcd
.hdc
= hdc
;
774 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
775 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
776 lpnmlvcd
->clrText
= infoPtr
->clrText
;
779 static inline DWORD
notify_customdraw (LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
781 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
782 return notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
785 /******** Item iterator functions **********************************/
787 static RANGES
ranges_create(int count
);
788 static void ranges_destroy(RANGES ranges
);
789 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
790 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
791 static void ranges_dump(RANGES ranges
);
793 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
795 RANGE range
= { nItem
, nItem
+ 1 };
797 return ranges_add(ranges
, range
);
800 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
802 RANGE range
= { nItem
, nItem
+ 1 };
804 return ranges_del(ranges
, range
);
808 * ITERATOR DOCUMENTATION
810 * The iterator functions allow for easy, and convenient iteration
811 * over items of iterest in the list. Typically, you create a
812 * iterator, use it, and destroy it, as such:
815 * iterator_xxxitems(&i, ...);
816 * while (iterator_{prev,next}(&i)
818 * //code which uses i.nItem
820 * iterator_destroy(&i);
822 * where xxx is either: framed, or visible.
823 * Note that it is important that the code destroys the iterator
824 * after it's done with it, as the creation of the iterator may
825 * allocate memory, which thus needs to be freed.
827 * You can iterate both forwards, and backwards through the list,
828 * by using iterator_next or iterator_prev respectively.
830 * Lower numbered items are draw on top of higher number items in
831 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
832 * items may overlap). So, to test items, you should use
834 * which lists the items top to bottom (in Z-order).
835 * For drawing items, you should use
837 * which lists the items bottom to top (in Z-order).
838 * If you keep iterating over the items after the end-of-items
839 * marker (-1) is returned, the iterator will start from the
840 * beginning. Typically, you don't need to test for -1,
841 * because iterator_{next,prev} will return TRUE if more items
842 * are to be iterated over, or FALSE otherwise.
844 * Note: the iterator is defined to be bidirectional. That is,
845 * any number of prev followed by any number of next, or
846 * five versa, should leave the iterator at the same item:
847 * prev * n, next * n = next * n, prev * n
849 * The iterator has a notion of a out-of-order, special item,
850 * which sits at the start of the list. This is used in
851 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
852 * which needs to be first, as it may overlap other items.
854 * The code is a bit messy because we have:
855 * - a special item to deal with
856 * - simple range, or composite range
858 * If find bugs, or want to add features, please make sure you
859 * always check/modify *both* iterator_prev, and iterator_next.
863 * This function iterates through the items in increasing order,
864 * but prefixed by the special item, then -1. That is:
865 * special, 1, 2, 3, ..., n, -1.
866 * Each item is listed only once.
868 static inline BOOL
iterator_next(ITERATOR
* i
)
872 i
->nItem
= i
->nSpecial
;
873 if (i
->nItem
!= -1) return TRUE
;
875 if (i
->nItem
== i
->nSpecial
)
877 if (i
->ranges
) i
->index
= 0;
883 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
884 if (i
->nItem
< i
->range
.upper
) return TRUE
;
889 if (i
->index
< i
->ranges
->hdpa
->nItemCount
)
890 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
893 else if (i
->nItem
>= i
->range
.upper
) goto end
;
895 i
->nItem
= i
->range
.lower
;
896 if (i
->nItem
>= 0) goto testitem
;
903 * This function iterates through the items in decreasing order,
904 * followed by the special item, then -1. That is:
905 * n, n-1, ..., 3, 2, 1, special, -1.
906 * Each item is listed only once.
908 static inline BOOL
iterator_prev(ITERATOR
* i
)
915 if (i
->ranges
) i
->index
= i
->ranges
->hdpa
->nItemCount
;
918 if (i
->nItem
== i
->nSpecial
)
926 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
927 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
933 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
936 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
938 i
->nItem
= i
->range
.upper
;
939 if (i
->nItem
> 0) goto testitem
;
941 return (i
->nItem
= i
->nSpecial
) != -1;
944 static RANGE
iterator_range(ITERATOR
* i
)
948 if (!i
->ranges
) return i
->range
;
950 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
951 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->ranges
->hdpa
->nItemCount
- 1)).upper
;
956 * Releases resources associated with this ierator.
958 static inline void iterator_destroy(ITERATOR
* i
)
960 if (i
->ranges
) ranges_destroy(i
->ranges
);
964 * Create an empty iterator.
966 static inline BOOL
iterator_empty(ITERATOR
* i
)
968 ZeroMemory(i
, sizeof(*i
));
969 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
975 * Create an iterator over a bunch of ranges.
976 * Please note that the iterator will take ownership of the ranges,
977 * and will free them upon destruction.
979 static inline BOOL
iterator_ranges(ITERATOR
* i
, RANGES ranges
)
987 * Creates an iterator over the items which intersect lprc.
989 static BOOL
iterator_frameditems(ITERATOR
* i
, LISTVIEW_INFO
* infoPtr
, const RECT
* lprc
)
991 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
992 RECT frame
= *lprc
, rcItem
, rcTemp
;
995 /* in case we fail, we want to return an empty iterator */
996 if (!iterator_empty(i
)) return FALSE
;
998 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1000 TRACE("(lprc=%s)\n", debugrect(lprc
));
1001 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1003 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)
1007 if (uView
== LVS_ICON
&& infoPtr
->nFocusedItem
!= -1)
1009 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1010 if (IntersectRect(&rcTemp
, &rcItem
, lprc
))
1011 i
->nSpecial
= infoPtr
->nFocusedItem
;
1013 if (!(i
->ranges
= ranges_create(50))) return FALSE
;
1014 /* to do better here, we need to have PosX, and PosY sorted */
1015 TRACE("building icon ranges:\n");
1016 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1018 rcItem
.left
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1019 rcItem
.top
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1020 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1021 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1022 if (IntersectRect(&rcTemp
, &rcItem
, &frame
))
1023 ranges_additem(i
->ranges
, nItem
);
1027 else if (uView
== LVS_REPORT
)
1031 if (frame
.left
>= infoPtr
->nItemWidth
) return TRUE
;
1032 if (frame
.top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1034 lower
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1035 upper
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1);
1036 if (upper
< lower
) return TRUE
;
1037 i
->range
.lower
= lower
;
1038 i
->range
.upper
= upper
+ 1;
1039 TRACE(" report=%s\n", debugrange(&i
->range
));
1043 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1044 INT nFirstRow
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1045 INT nLastRow
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1046 INT nFirstCol
= max(frame
.left
/ infoPtr
->nItemWidth
, 0);
1047 INT nLastCol
= min((frame
.right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1048 INT lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1052 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1053 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1055 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1057 if (!(i
->ranges
= ranges_create(nLastCol
- nFirstCol
+ 1))) return FALSE
;
1058 TRACE("building list ranges:\n");
1059 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1061 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1062 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1063 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1064 TRACE(" list=%s\n", debugrange(&item_range
));
1065 ranges_add(i
->ranges
, item_range
);
1073 * Creates an iterator over the items which intersect the visible region of hdc.
1075 static BOOL
iterator_visibleitems(ITERATOR
* i
, LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1077 POINT Origin
, Position
;
1078 RECT rcItem
, rcClip
;
1081 rgntype
= GetClipBox(hdc
, &rcClip
);
1082 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1083 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1084 if (rgntype
== SIMPLEREGION
) return TRUE
;
1086 /* first deal with the special item */
1087 if (i
->nSpecial
!= -1)
1089 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1090 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1093 /* if we can't deal with the region, we'll just go with the simple range */
1094 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1095 TRACE("building visible range:\n");
1096 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1098 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1099 if (!ranges_add(i
->ranges
, i
->range
))
1101 ranges_destroy(i
->ranges
);
1107 /* now delete the invisible items from the list */
1108 while(iterator_next(i
))
1110 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1111 rcItem
.left
= Position
.x
+ Origin
.x
;
1112 rcItem
.top
= Position
.y
+ Origin
.y
;
1113 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1114 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1115 if (!RectVisible(hdc
, &rcItem
))
1116 ranges_delitem(i
->ranges
, i
->nItem
);
1118 /* the iterator should restart on the next iterator_next */
1124 /******** Misc helper functions ************************************/
1126 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1127 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1129 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1130 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1133 /******** Internal API functions ************************************/
1135 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1137 assert (nSubItem
>= 0 && nSubItem
< infoPtr
->hdpaColumns
->nItemCount
);
1138 return (COLUMN_INFO
*)DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1141 static inline void LISTVIEW_GetHeaderRect(LISTVIEW_INFO
*infoPtr
, INT nSubItem
, RECT
*lprc
)
1143 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1146 static inline BOOL
LISTVIEW_GetItemW(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1148 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1151 /* The Invalidate* are macros, so we preserve the caller location */
1152 #define LISTVIEW_InvalidateRect(infoPtr, rect) while(infoPtr->bRedraw) { \
1153 TRACE(" invalidating rect=%s\n", debugrect(rect)); \
1154 InvalidateRect(infoPtr->hwndSelf, rect, TRUE); \
1158 #define LISTVIEW_InvalidateItem(infoPtr, nItem) do { \
1160 LISTVIEW_GetItemBox(infoPtr, nItem, &rcBox); \
1161 LISTVIEW_InvalidateRect(infoPtr, &rcBox); \
1164 #define LISTVIEW_InvalidateSubItem(infoPtr, nItem, nSubItem) do { \
1165 POINT Origin, Position; \
1167 assert ((infoPtr->dwStyle & LVS_TYPEMASK) == LVS_REPORT); \
1168 LISTVIEW_GetOrigin(infoPtr, &Origin); \
1169 LISTVIEW_GetItemOrigin(infoPtr, nItem, &Position); \
1170 LISTVIEW_GetHeaderRect(infoPtr, nSubItem, &rcBox); \
1172 rcBox.bottom = infoPtr->nItemHeight; \
1173 OffsetRect(&rcBox, Origin.x + Position.x, Origin.y + Position.y); \
1174 LISTVIEW_InvalidateRect(infoPtr, &rcBox); \
1177 #define LISTVIEW_InvalidateList(infoPtr)\
1178 LISTVIEW_InvalidateRect(infoPtr, NULL)
1181 static inline void LISTVIEW_InvalidateColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1185 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1186 rcCol
.top
= infoPtr
->rcList
.top
;
1187 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1188 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1193 * Retrieves the number of items that can fit vertically in the client area.
1196 * [I] infoPtr : valid pointer to the listview structure
1199 * Number of items per row.
1201 static inline INT
LISTVIEW_GetCountPerRow(LISTVIEW_INFO
*infoPtr
)
1203 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1205 return max(nListWidth
/infoPtr
->nItemWidth
, 1);
1210 * Retrieves the number of items that can fit horizontally in the client
1214 * [I] infoPtr : valid pointer to the listview structure
1217 * Number of items per column.
1219 static inline INT
LISTVIEW_GetCountPerColumn(LISTVIEW_INFO
*infoPtr
)
1221 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1223 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1227 /*************************************************************************
1228 * LISTVIEW_ProcessLetterKeys
1230 * Processes keyboard messages generated by pressing the letter keys
1232 * What this does is perform a case insensitive search from the
1233 * current position with the following quirks:
1234 * - If two chars or more are pressed in quick succession we search
1235 * for the corresponding string (e.g. 'abc').
1236 * - If there is a delay we wipe away the current search string and
1237 * restart with just that char.
1238 * - If the user keeps pressing the same character, whether slowly or
1239 * fast, so that the search string is entirely composed of this
1240 * character ('aaaaa' for instance), then we search for first item
1241 * that starting with that character.
1242 * - If the user types the above character in quick succession, then
1243 * we must also search for the corresponding string ('aaaaa'), and
1244 * go to that string if there is a match.
1247 * [I] hwnd : handle to the window
1248 * [I] charCode : the character code, the actual character
1249 * [I] keyData : key data
1257 * - The current implementation has a list of characters it will
1258 * accept and it ignores averything else. In particular it will
1259 * ignore accentuated characters which seems to match what
1260 * Windows does. But I'm not sure it makes sense to follow
1262 * - We don't sound a beep when the search fails.
1266 * TREEVIEW_ProcessLetterKeys
1268 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1273 WCHAR buffer
[MAX_PATH
];
1274 DWORD lastKeyPressTimestamp
= infoPtr
->lastKeyPressTimestamp
;
1276 /* simple parameter checking */
1277 if (!charCode
|| !keyData
) return 0;
1279 /* only allow the valid WM_CHARs through */
1280 if (!isalnum(charCode
) &&
1281 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1282 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1283 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1284 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1285 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1286 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1287 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1288 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1289 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1292 /* if there's one item or less, there is no where to go */
1293 if (infoPtr
->nItemCount
<= 1) return 0;
1295 /* update the search parameters */
1296 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1297 if (infoPtr
->lastKeyPressTimestamp
- lastKeyPressTimestamp
< KEY_DELAY
) {
1298 if (infoPtr
->nSearchParamLength
< MAX_PATH
)
1299 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
1300 if (infoPtr
->charCode
!= charCode
)
1301 infoPtr
->charCode
= charCode
= 0;
1303 infoPtr
->charCode
=charCode
;
1304 infoPtr
->szSearchParam
[0]=charCode
;
1305 infoPtr
->nSearchParamLength
=1;
1306 /* Redundant with the 1 char string */
1310 /* and search from the current position */
1312 if (infoPtr
->nFocusedItem
>= 0) {
1313 endidx
=infoPtr
->nFocusedItem
;
1315 /* if looking for single character match,
1316 * then we must always move forward
1318 if (infoPtr
->nSearchParamLength
== 1)
1321 endidx
=infoPtr
->nItemCount
;
1325 if (idx
== infoPtr
->nItemCount
) {
1326 if (endidx
== infoPtr
->nItemCount
|| endidx
== 0)
1332 item
.mask
= LVIF_TEXT
;
1335 item
.pszText
= buffer
;
1336 item
.cchTextMax
= MAX_PATH
;
1337 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1339 /* check for a match */
1340 if (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
1343 } else if ( (charCode
!= 0) && (nItem
== -1) && (nItem
!= infoPtr
->nFocusedItem
) &&
1344 (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
1345 /* This would work but we must keep looking for a longer match */
1349 } while (idx
!= endidx
);
1352 LISTVIEW_KeySelection(infoPtr
, nItem
);
1357 /*************************************************************************
1358 * LISTVIEW_UpdateHeaderSize [Internal]
1360 * Function to resize the header control
1363 * [I] hwnd : handle to a window
1364 * [I] nNewScrollPos : scroll pos to set
1369 static void LISTVIEW_UpdateHeaderSize(LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1374 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1376 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1377 point
[0].x
= winRect
.left
;
1378 point
[0].y
= winRect
.top
;
1379 point
[1].x
= winRect
.right
;
1380 point
[1].y
= winRect
.bottom
;
1382 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1383 point
[0].x
= -nNewScrollPos
;
1384 point
[1].x
+= nNewScrollPos
;
1386 SetWindowPos(infoPtr
->hwndHeader
,0,
1387 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1388 SWP_NOZORDER
| SWP_NOACTIVATE
);
1393 * Update the scrollbars. This functions should be called whenever
1394 * the content, size or view changes.
1397 * [I] infoPtr : valid pointer to the listview structure
1402 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*infoPtr
)
1404 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1405 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1406 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1407 SCROLLINFO scrollInfo
;
1409 if (infoPtr
->dwStyle
& LVS_NOSCROLL
) return;
1411 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
1413 if (uView
== LVS_LIST
)
1415 /* update horizontal scrollbar */
1416 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
1417 INT nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
1419 TRACE("items=%d, perColumn=%d, perRow=%d\n",
1420 infoPtr
->nItemCount
, nCountPerColumn
, nCountPerRow
);
1422 scrollInfo
.nMin
= 0;
1423 scrollInfo
.nMax
= infoPtr
->nItemCount
/ nCountPerColumn
;
1424 if((infoPtr
->nItemCount
% nCountPerColumn
) == 0)
1426 if (scrollInfo
.nMax
< 0) scrollInfo
.nMax
= 0;
1427 scrollInfo
.nPos
= ListView_GetTopIndex(infoPtr
->hwndSelf
) / nCountPerColumn
;
1428 scrollInfo
.nPage
= nCountPerRow
;
1429 scrollInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
;
1430 SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
1431 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
1433 else if (uView
== LVS_REPORT
)
1437 /* update vertical scrollbar */
1438 scrollInfo
.nMin
= 0;
1439 scrollInfo
.nMax
= infoPtr
->nItemCount
- 1;
1440 scrollInfo
.nPos
= ListView_GetTopIndex(infoPtr
->hwndSelf
);
1441 scrollInfo
.nPage
= LISTVIEW_GetCountPerColumn(infoPtr
);
1442 scrollInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
;
1443 test
= (scrollInfo
.nMin
>= scrollInfo
.nMax
- max((INT
)scrollInfo
.nPage
- 1, 0));
1444 TRACE("LVS_REPORT Vert. nMax=%d, nPage=%d, test=%d\n",
1445 scrollInfo
.nMax
, scrollInfo
.nPage
, test
);
1446 SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
1447 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, (test
) ? FALSE
: TRUE
);
1449 /* update horizontal scrollbar */
1450 nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1451 scrollInfo
.fMask
= SIF_POS
;
1452 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)
1453 || infoPtr
->nItemCount
== 0)
1455 scrollInfo
.nPos
= 0;
1457 scrollInfo
.nMin
= 0;
1458 scrollInfo
.nMax
= max(infoPtr
->nItemWidth
, 0)-1;
1459 scrollInfo
.nPage
= nListWidth
;
1460 scrollInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
;
1461 test
= (scrollInfo
.nMin
>= scrollInfo
.nMax
- max((INT
)scrollInfo
.nPage
- 1, 0));
1462 TRACE("LVS_REPORT Horz. nMax=%d, nPage=%d, test=%d\n",
1463 scrollInfo
.nMax
, scrollInfo
.nPage
, test
);
1464 SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
1465 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, (test
) ? FALSE
: TRUE
);
1467 /* Update the Header Control */
1468 scrollInfo
.fMask
= SIF_POS
;
1469 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
);
1470 LISTVIEW_UpdateHeaderSize(infoPtr
, scrollInfo
.nPos
);
1477 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
))
1479 INT nViewWidth
= rcView
.right
- rcView
.left
;
1480 INT nViewHeight
= rcView
.bottom
- rcView
.top
;
1482 /* Update Horizontal Scrollbar */
1483 scrollInfo
.fMask
= SIF_POS
;
1484 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)
1485 || infoPtr
->nItemCount
== 0)
1487 scrollInfo
.nPos
= 0;
1489 scrollInfo
.nMin
= 0;
1490 scrollInfo
.nMax
= max(nViewWidth
, 0)-1;
1491 scrollInfo
.nPage
= nListWidth
;
1492 scrollInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
;
1493 TRACE("LVS_ICON/SMALLICON Horz.\n");
1494 SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
1496 /* Update Vertical Scrollbar */
1497 nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1498 scrollInfo
.fMask
= SIF_POS
;
1499 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)
1500 || infoPtr
->nItemCount
== 0)
1502 scrollInfo
.nPos
= 0;
1504 scrollInfo
.nMin
= 0;
1505 scrollInfo
.nMax
= max(nViewHeight
,0)-1;
1506 scrollInfo
.nPage
= nListHeight
;
1507 scrollInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
;
1508 TRACE("LVS_ICON/SMALLICON Vert.\n");
1509 SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
1517 * Shows/hides the focus rectangle.
1520 * [I] infoPtr : valid pointer to the listview structure
1521 * [I] fShow : TRUE to show the focus, FALSE to hide it.
1526 static void LISTVIEW_ShowFocusRect(LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
1528 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1531 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
1533 if (infoPtr
->nFocusedItem
< 0) return;
1535 /* we need some gymnastics in ICON mode to handle large items */
1536 if ( (infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_ICON
)
1540 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
1541 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
1543 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1548 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
1550 /* for some reason, owner draw should work only in report mode */
1551 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (uView
== LVS_REPORT
))
1556 item
.iItem
= infoPtr
->nFocusedItem
;
1558 item
.mask
= LVIF_PARAM
;
1559 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
1561 ZeroMemory(&dis
, sizeof(dis
));
1562 dis
.CtlType
= ODT_LISTVIEW
;
1563 dis
.CtlID
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_ID
);
1564 dis
.itemID
= item
.iItem
;
1565 dis
.itemAction
= ODA_FOCUS
;
1566 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
1567 dis
.hwndItem
= infoPtr
->hwndSelf
;
1569 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
1570 dis
.itemData
= item
.lParam
;
1572 SendMessageW(GetParent(infoPtr
->hwndSelf
), WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
1576 DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1579 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1583 * Invalidates all visible selected items.
1585 static void LISTVIEW_InvalidateSelectedItems(LISTVIEW_INFO
*infoPtr
)
1589 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
1590 while(iterator_next(&i
))
1592 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
1593 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
1595 iterator_destroy(&i
);
1600 * DESCRIPTION: [INTERNAL]
1601 * Computes an item's (left,top) corner, relative to rcView.
1602 * That is, the position has NOT been made relative to the Origin.
1603 * This is deliberate, to avoid computing the Origin over, and
1604 * over again, when this function is call in a loop. Instead,
1605 * one ca factor the computation of the Origin before the loop,
1606 * and offset the value retured by this function, on every iteration.
1609 * [I] infoPtr : valid pointer to the listview structure
1610 * [I] nItem : item number
1611 * [O] lpptOrig : item top, left corner
1616 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
1618 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1620 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
1622 if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
1624 lpptPosition
->x
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1625 lpptPosition
->y
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1627 else if (uView
== LVS_LIST
)
1629 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
1630 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
1631 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
1633 else /* LVS_REPORT */
1635 lpptPosition
->x
= REPORT_MARGINX
;
1636 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
1641 * DESCRIPTION: [INTERNAL]
1642 * Compute the rectangles of an item. This is to localize all
1643 * the computations in one place. If you are not interested in some
1644 * of these values, simply pass in a NULL -- the fucntion is smart
1645 * enough to compute only what's necessary. The function computes
1646 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
1647 * one, the BOX rectangle. This rectangle is very cheap to compute,
1648 * and is guaranteed to contain all the other rectangles. Computing
1649 * the ICON rect is also cheap, but all the others are potentaily
1650 * expensive. This gives an easy and effective optimization when
1651 * searching (like point inclusion, or rectangle intersection):
1652 * first test against the BOX, and if TRUE, test agains the desired
1654 * If the function does not have all the necessary information
1655 * to computed the requested rectangles, will crash with a
1656 * failed assertion. This is done so we catch all programming
1657 * errors, given that the function is called only from our code.
1659 * We have the following 'special' meanings for a few fields:
1660 * * If LVIS_FOCUSED is set, we assume the item has the focus
1661 * This is important in ICON mode, where it might get a larger
1662 * then usual rectange
1664 * Please note that subitem support works only in REPORT mode.
1667 * [I] infoPtr : valid pointer to the listview structure
1668 * [I] lpLVItem : item to compute the measures for
1669 * [O] lprcBox : ptr to Box rectangle
1670 * The internal LVIR_BOX rectangle
1671 * [0] lprcState : ptr to State icon rectangle
1672 * The internal LVIR_STATE rectangle
1673 * [O] lprcIcon : ptr to Icon rectangle
1674 * Same as LVM_GETITEMRECT with LVIR_ICON
1675 * [O] lprcLabel : ptr to Label rectangle
1676 * Same as LVM_GETITEMRECT with LVIR_LABEL
1681 static void LISTVIEW_GetItemMetrics(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
,
1682 LPRECT lprcBox
, LPRECT lprcState
,
1683 LPRECT lprcIcon
, LPRECT lprcLabel
)
1685 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1686 BOOL doState
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
1687 RECT Box
, State
, Icon
, Label
;
1688 COLUMN_INFO
*lpColumnInfo
= NULL
;
1690 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
1692 /* Be smart and try to figure out the minimum we have to do */
1693 if (lpLVItem
->iSubItem
) assert(uView
== LVS_REPORT
);
1694 if (uView
== LVS_ICON
&& (lprcBox
|| lprcLabel
))
1696 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
1697 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
1699 if (lprcLabel
) doLabel
= TRUE
;
1700 if (doLabel
|| lprcIcon
) doIcon
= TRUE
;
1701 if (doIcon
|| lprcState
) doState
= TRUE
;
1703 /************************************************************/
1704 /* compute the box rectangle (it should be cheap to do) */
1705 /************************************************************/
1706 if (lpLVItem
->iSubItem
|| uView
== LVS_REPORT
)
1707 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
1709 if (lpLVItem
->iSubItem
)
1711 Box
= lpColumnInfo
->rcHeader
;
1716 Box
.right
= infoPtr
->nItemWidth
;
1719 Box
.bottom
= infoPtr
->nItemHeight
;
1721 /************************************************************/
1722 /* compute STATEICON bounding box */
1723 /************************************************************/
1726 if (uView
== LVS_ICON
)
1728 State
.left
= Box
.left
- infoPtr
->iconStateSize
.cx
- 2;
1729 if (infoPtr
->himlNormal
)
1730 State
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
1731 State
.top
= Box
.top
+ infoPtr
->iconSize
.cy
- infoPtr
->iconStateSize
.cy
+ 4;
1735 /* we need the ident in report mode, if we don't have it, we fail */
1736 State
.left
= Box
.left
;
1737 if (uView
== LVS_REPORT
)
1739 State
.left
+= REPORT_MARGINX
;
1740 if (lpLVItem
->iSubItem
== 0)
1742 assert(lpLVItem
->mask
& LVIF_INDENT
);
1743 State
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
;
1746 State
.top
= Box
.top
;
1748 State
.right
= State
.left
;
1749 State
.bottom
= State
.top
;
1750 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
1752 State
.right
+= infoPtr
->iconStateSize
.cx
;
1753 State
.bottom
+= infoPtr
->iconStateSize
.cy
;
1755 if (lprcState
) *lprcState
= State
;
1756 TRACE(" - state=%s\n", debugrect(&State
));
1759 /************************************************************/
1760 /* compute ICON bounding box (ala LVM_GETITEMRECT) */
1761 /************************************************************/
1764 if (uView
== LVS_ICON
)
1766 Icon
.left
= Box
.left
;
1767 if (infoPtr
->himlNormal
)
1768 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
1769 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
1770 Icon
.right
= Icon
.left
;
1771 Icon
.bottom
= Icon
.top
;
1772 if (infoPtr
->himlNormal
)
1774 Icon
.right
+= infoPtr
->iconSize
.cx
;
1775 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
1778 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
1780 Icon
.left
= State
.right
;
1781 if (!IsRectEmpty(&State
)) Icon
.left
+= IMAGE_PADDING
;
1783 Icon
.right
= Icon
.left
;
1784 if (infoPtr
->himlSmall
&& (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 || (lpColumnInfo
->fmt
& LVCFMT_IMAGE
)))
1785 Icon
.right
+= infoPtr
->iconSize
.cx
;
1786 Icon
.bottom
= Icon
.top
+ infoPtr
->nItemHeight
;
1788 if(lprcIcon
) *lprcIcon
= Icon
;
1789 TRACE(" - icon=%s\n", debugrect(&Icon
));
1792 /************************************************************/
1793 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
1794 /************************************************************/
1797 SIZE labelSize
= { 0, 0 };
1799 /* calculate how far to the right can the label strech */
1800 Label
.right
= Box
.right
;
1801 if (uView
== LVS_REPORT
)
1803 if (lpLVItem
->iSubItem
== 0) Label
= lpColumnInfo
->rcHeader
;
1804 Label
.right
-= REPORT_MARGINX
;
1807 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && uView
== LVS_REPORT
))
1809 labelSize
.cx
= infoPtr
->nItemWidth
;
1810 labelSize
.cy
= infoPtr
->nItemHeight
;
1814 /* we need the text in non owner draw mode */
1815 assert(lpLVItem
->mask
& LVIF_TEXT
);
1816 if (is_textT(lpLVItem
->pszText
, TRUE
))
1818 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
1819 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
1820 HFONT hOldFont
= SelectObject(hdc
, hFont
);
1824 /* compute rough rectangle where the label will go */
1825 SetRectEmpty(&rcText
);
1826 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_PADDING
;
1827 rcText
.bottom
= infoPtr
->nItemHeight
;
1828 if (uView
== LVS_ICON
)
1829 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
1831 /* now figure out the flags */
1832 if (uView
== LVS_ICON
)
1833 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
1835 uFormat
= LV_SL_DT_FLAGS
;
1837 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
1839 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_PADDING
, infoPtr
->nItemWidth
);
1840 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
1842 SelectObject(hdc
, hOldFont
);
1843 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1847 if (uView
== LVS_ICON
)
1849 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
1850 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
1851 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
1852 Label
.right
= Label
.left
+ labelSize
.cx
;
1853 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
1854 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
1856 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
1857 labelSize
.cy
/= infoPtr
->ntmHeight
;
1858 labelSize
.cy
= max(labelSize
.cy
, 1);
1859 labelSize
.cy
*= infoPtr
->ntmHeight
;
1861 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
1863 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
1865 Label
.left
= Icon
.right
;
1866 if (!IsRectEmpty(&Icon
) || !IsRectEmpty(&State
)) Label
.left
+= IMAGE_PADDING
;
1867 Label
.top
= Box
.top
;
1868 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
1869 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
1872 if (lprcLabel
) *lprcLabel
= Label
;
1873 TRACE(" - label=%s\n", debugrect(&Label
));
1876 /* Fix the Box if necessary */
1879 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
1880 else *lprcBox
= Box
;
1882 TRACE(" - box=%s\n", debugrect(&Box
));
1886 * DESCRIPTION: [INTERNAL]
1889 * [I] infoPtr : valid pointer to the listview structure
1890 * [I] nItem : item number
1891 * [O] lprcBox : ptr to Box rectangle
1896 static void LISTVIEW_GetItemBox(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
1898 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1899 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
1900 POINT Position
, Origin
;
1903 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1904 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1906 /* Be smart and try to figure out the minimum we have to do */
1908 if (uView
== LVS_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
1909 lvItem
.mask
|= LVIF_TEXT
;
1910 lvItem
.iItem
= nItem
;
1911 lvItem
.iSubItem
= 0;
1912 lvItem
.pszText
= szDispText
;
1913 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
1914 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
1915 if (uView
== LVS_ICON
)
1917 lvItem
.mask
|= LVIF_STATE
;
1918 lvItem
.stateMask
= LVIS_FOCUSED
;
1919 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
1921 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0);
1923 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
1929 * Returns the current icon position, and advances it along the top.
1930 * The returned position is not offset by Origin.
1933 * [I] infoPtr : valid pointer to the listview structure
1934 * [O] lpPos : will get the current icon position
1939 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
1941 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1943 *lpPos
= infoPtr
->currIconPos
;
1945 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
1946 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
1948 infoPtr
->currIconPos
.x
= 0;
1949 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
1955 * Returns the current icon position, and advances it down the left edge.
1956 * The returned position is not offset by Origin.
1959 * [I] infoPtr : valid pointer to the listview structure
1960 * [O] lpPos : will get the current icon position
1965 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
1967 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1969 *lpPos
= infoPtr
->currIconPos
;
1971 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
1972 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
1974 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
1975 infoPtr
->currIconPos
.y
= 0;
1981 * Moves an icon to the specified position.
1982 * It takes care of invalidating the item, etc.
1985 * [I] infoPtr : valid pointer to the listview structure
1986 * [I] nItem : the item to move
1987 * [I] lpPos : the new icon position
1988 * [I] isNew : flags the item as being new
1994 static BOOL
LISTVIEW_MoveIconTo(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lppt
, BOOL isNew
)
2001 old
.x
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2002 old
.y
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2004 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2007 /* Allocating a POINTER for every item is too resource intensive,
2008 * so we'll keep the (x,y) in different arrays */
2009 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)lppt
->x
)) return FALSE
;
2010 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)lppt
->y
)) return FALSE
;
2012 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2015 rcItem
.left
= old
.x
+ Origin
.x
;
2016 rcItem
.top
= old
.y
+ Origin
.y
;
2017 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
2018 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
2019 LISTVIEW_InvalidateRect(infoPtr
, &rcItem
);
2022 rcItem
.left
= lppt
->x
+ Origin
.x
;
2023 rcItem
.top
= lppt
->y
+ Origin
.y
;
2024 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
2025 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
2026 LISTVIEW_InvalidateRect(infoPtr
, &rcItem
);
2033 * Arranges listview items in icon display mode.
2036 * [I] infoPtr : valid pointer to the listview structure
2037 * [I] nAlignCode : alignment code
2043 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2045 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2046 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2050 if (uView
!= LVS_ICON
&& uView
!= LVS_SMALLICON
) return FALSE
;
2052 if (nAlignCode
== LVA_DEFAULT
)
2054 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2055 else nAlignCode
= LVA_ALIGNTOP
;
2060 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2061 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2062 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2063 default: return FALSE
;
2066 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2067 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2069 next_pos(infoPtr
, &pos
);
2070 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2078 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2081 * [I] infoPtr : valid pointer to the listview structure
2082 * [O] lprcView : bounding rectangle
2088 static void LISTVIEW_GetAreaRect(LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2092 SetRectEmpty(lprcView
);
2094 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
2098 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2100 x
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2101 y
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2102 lprcView
->right
= max(lprcView
->right
, x
);
2103 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2105 if (infoPtr
->nItemCount
> 0)
2107 lprcView
->right
+= infoPtr
->nItemWidth
;
2108 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2113 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2114 x
= infoPtr
->nItemCount
/ y
;
2115 if (infoPtr
->nItemCount
% y
) x
++;
2116 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2117 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2121 lprcView
->right
= infoPtr
->nItemWidth
;
2122 lprcView
->bottom
= infoPtr
->nItemCount
* infoPtr
->nItemHeight
;
2129 * Retrieves the bounding rectangle of all the items.
2132 * [I] infoPtr : valid pointer to the listview structure
2133 * [O] lprcView : bounding rectangle
2139 static BOOL
LISTVIEW_GetViewRect(LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2143 TRACE("(lprcView=%p)\n", lprcView
);
2145 if (!lprcView
) return FALSE
;
2147 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2148 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2149 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2151 TRACE("lprcView=%s\n", debugrect(lprcView
));
2158 * Retrieves the subitem pointer associated with the subitem index.
2161 * [I] hdpaSubItems : DPA handle for a specific item
2162 * [I] nSubItem : index of subitem
2165 * SUCCESS : subitem pointer
2168 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2170 SUBITEM_INFO
*lpSubItem
;
2173 /* we should binary search here if need be */
2174 for (i
= 1; i
< hdpaSubItems
->nItemCount
; i
++)
2176 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
2177 if (lpSubItem
->iSubItem
== nSubItem
)
2187 * Calculates the width of a specific item.
2190 * [I] infoPtr : valid pointer to the listview structure
2191 * [I] nItem : item to calculate width, or -1 for max of all
2194 * Returns the width of an item width an item.
2196 static INT
LISTVIEW_CalculateItemWidth(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2198 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2199 INT nItemWidth
= 0, i
;
2201 if (uView
== LVS_ICON
)
2202 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2203 else if (uView
== LVS_REPORT
)
2207 /* calculate width of header */
2208 for (i
= 0; i
< infoPtr
->hdpaColumns
->nItemCount
; i
++)
2210 LISTVIEW_GetHeaderRect(infoPtr
, i
, &rcHeaderItem
);
2211 nItemWidth
+= (rcHeaderItem
.right
- rcHeaderItem
.left
);
2218 if (infoPtr
->nItemCount
== 0) return DEFAULT_COLUMN_WIDTH
;
2220 /* get width of string */
2223 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2225 nLabelWidth
= LISTVIEW_GetLabelWidth(infoPtr
, i
);
2226 nItemWidth
= max(nItemWidth
, nLabelWidth
);
2230 nItemWidth
= LISTVIEW_GetLabelWidth(infoPtr
, nItem
);
2231 if (!nItemWidth
) return DEFAULT_COLUMN_WIDTH
;
2232 nItemWidth
+= WIDTH_PADDING
;
2233 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2234 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2235 if (nItem
== -1) nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
);
2238 return max(nItemWidth
, 1);
2243 * Calculates the max width of any item in the list.
2246 * [I] infoPtr : valid pointer to the listview structure
2249 * Returns item width.
2251 static inline INT
LISTVIEW_CalculateMaxWidth(LISTVIEW_INFO
*infoPtr
)
2253 return LISTVIEW_CalculateItemWidth(infoPtr
, -1);
2258 * Retrieves and saves important text metrics info for the current
2262 * [I] infoPtr : valid pointer to the listview structure
2265 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2267 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2268 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2269 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2272 if (GetTextMetricsW(hdc
, &tm
))
2273 infoPtr
->ntmHeight
= tm
.tmHeight
;
2274 SelectObject(hdc
, hOldFont
);
2275 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2277 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
2283 * Calculates the height of an item.
2286 * [I] infoPtr : valid pointer to the listview structure
2289 * Returns item height.
2291 static INT
LISTVIEW_CalculateMaxHeight(LISTVIEW_INFO
*infoPtr
)
2295 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_ICON
)
2296 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2299 nItemHeight
= infoPtr
->ntmHeight
;
2300 if (infoPtr
->himlState
)
2301 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2302 if (infoPtr
->himlSmall
)
2303 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2304 if (infoPtr
->himlState
|| infoPtr
->himlSmall
)
2305 nItemHeight
+= HEIGHT_PADDING
;
2312 * A compare function for ranges
2315 * [I] range1 : pointer to range 1;
2316 * [I] range2 : pointer to range 2;
2320 * > 0 : if range 1 > range 2
2321 * < 0 : if range 2 > range 1
2322 * = 0 : if range intersects range 2
2324 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
2328 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
2330 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
2335 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange((RANGE
*)range1
), debugrange((RANGE
*)range2
), cmp
);
2341 #define ranges_check(ranges, desc) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
2343 #define ranges_check(ranges, desc) do { } while(0)
2346 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *func
, int line
)
2351 TRACE("*** Checking %s:%d:%s ***\n", func
, line
, desc
);
2353 assert (ranges
->hdpa
->nItemCount
>= 0);
2354 ranges_dump(ranges
);
2355 prev
= (RANGE
*)DPA_GetPtr(ranges
->hdpa
, 0);
2356 if (ranges
->hdpa
->nItemCount
> 0)
2357 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
2358 for (i
= 1; i
< ranges
->hdpa
->nItemCount
; i
++)
2360 curr
= (RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
);
2361 assert (prev
->upper
<= curr
->lower
);
2362 assert (curr
->lower
< curr
->upper
);
2365 TRACE("--- Done checking---\n");
2368 static RANGES
ranges_create(int count
)
2370 RANGES ranges
= (RANGES
)COMCTL32_Alloc(sizeof(struct tagRANGES
));
2371 if (!ranges
) return NULL
;
2372 ranges
->hdpa
= DPA_Create(count
);
2373 if (ranges
->hdpa
) return ranges
;
2374 COMCTL32_Free(ranges
);
2378 static void ranges_clear(RANGES ranges
)
2382 for(i
= 0; i
< ranges
->hdpa
->nItemCount
; i
++)
2383 COMCTL32_Free(DPA_GetPtr(ranges
->hdpa
, i
));
2384 DPA_DeleteAllPtrs(ranges
->hdpa
);
2388 static void ranges_destroy(RANGES ranges
)
2390 ranges_clear(ranges
);
2391 DPA_Destroy(ranges
->hdpa
);
2392 COMCTL32_Free(ranges
);
2395 static RANGES
ranges_clone(RANGES ranges
)
2400 if (!(clone
= ranges_create(ranges
->hdpa
->nItemCount
))) goto fail
;
2402 for (i
= 0; i
< ranges
->hdpa
->nItemCount
; i
++)
2404 RANGE
*newrng
= (RANGE
*)COMCTL32_Alloc(sizeof(RANGE
));
2405 if (!newrng
) goto fail
;
2406 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
2407 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
2412 TRACE ("clone failed\n");
2413 if (clone
) ranges_destroy(clone
);
2417 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
2421 for (i
= 0; i
< sub
->hdpa
->nItemCount
; i
++)
2422 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
2427 static void ranges_dump(RANGES ranges
)
2431 for (i
= 0; i
< ranges
->hdpa
->nItemCount
; i
++)
2432 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
2435 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
2437 RANGE srchrng
= { nItem
, nItem
+ 1 };
2439 TRACE("(nItem=%d)\n", nItem
);
2440 ranges_check(ranges
, "before contain");
2441 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
2444 static INT
ranges_itemcount(RANGES ranges
)
2448 for (i
= 0; i
< ranges
->hdpa
->nItemCount
; i
++)
2450 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
2451 count
+= sel
->upper
- sel
->lower
;
2457 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
2459 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
2462 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2463 if (index
== -1) return TRUE
;
2465 for (; index
< ranges
->hdpa
->nItemCount
; index
++)
2467 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
2468 if (chkrng
->lower
>= nItem
)
2469 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
2470 if (chkrng
->upper
> nItem
)
2471 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
2476 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
2481 TRACE("(%s)\n", debugrange(&range
));
2482 ranges_check(ranges
, "before add");
2484 /* try find overlapping regions first */
2485 srchrgn
.lower
= range
.lower
- 1;
2486 srchrgn
.upper
= range
.upper
+ 1;
2487 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
2493 TRACE("Adding new range\n");
2495 /* create the brand new range to insert */
2496 newrgn
= (RANGE
*)COMCTL32_Alloc(sizeof(RANGE
));
2497 if(!newrgn
) goto fail
;
2500 /* figure out where to insert it */
2501 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2502 TRACE("index=%d\n", index
);
2503 if (index
== -1) index
= 0;
2505 /* and get it over with */
2506 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
2508 COMCTL32_Free(newrgn
);
2514 RANGE
*chkrgn
, *mrgrgn
;
2515 INT fromindex
, mergeindex
;
2517 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
2518 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
2520 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
2521 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
2523 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
2525 /* merge now common anges */
2527 srchrgn
.lower
= chkrgn
->lower
- 1;
2528 srchrgn
.upper
= chkrgn
->upper
+ 1;
2532 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
2533 if (mergeindex
== -1) break;
2534 if (mergeindex
== index
)
2536 fromindex
= index
+ 1;
2540 TRACE("Merge with index %i\n", mergeindex
);
2542 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
2543 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
2544 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
2545 COMCTL32_Free(mrgrgn
);
2546 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
2547 if (mergeindex
< index
) index
--;
2551 ranges_check(ranges
, "after add");
2555 ranges_check(ranges
, "failed add");
2559 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
2564 TRACE("(%s)\n", debugrange(&range
));
2565 ranges_check(ranges
, "before del");
2567 /* we don't use DPAS_SORTED here, since we need *
2568 * to find the first overlapping range */
2569 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
2572 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
2574 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
2576 /* case 1: Same range */
2577 if ( (chkrgn
->upper
== range
.upper
) &&
2578 (chkrgn
->lower
== range
.lower
) )
2580 DPA_DeletePtr(ranges
->hdpa
, index
);
2583 /* case 2: engulf */
2584 else if ( (chkrgn
->upper
<= range
.upper
) &&
2585 (chkrgn
->lower
>= range
.lower
) )
2587 DPA_DeletePtr(ranges
->hdpa
, index
);
2589 /* case 3: overlap upper */
2590 else if ( (chkrgn
->upper
<= range
.upper
) &&
2591 (chkrgn
->lower
< range
.lower
) )
2593 chkrgn
->upper
= range
.lower
;
2595 /* case 4: overlap lower */
2596 else if ( (chkrgn
->upper
> range
.upper
) &&
2597 (chkrgn
->lower
>= range
.lower
) )
2599 chkrgn
->lower
= range
.upper
;
2602 /* case 5: fully internal */
2605 RANGE tmprgn
= *chkrgn
, *newrgn
;
2607 if (!(newrgn
= (RANGE
*)COMCTL32_Alloc(sizeof(RANGE
)))) goto fail
;
2608 newrgn
->lower
= chkrgn
->lower
;
2609 newrgn
->upper
= range
.lower
;
2610 chkrgn
->lower
= range
.upper
;
2611 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
2613 COMCTL32_Free(newrgn
);
2620 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
2623 ranges_check(ranges
, "after del");
2627 ranges_check(ranges
, "failed del");
2633 * Removes all selection ranges
2636 * [I] infoPtr : valid pointer to the listview structure
2637 * [I] toSkip : item range to skip removing the selection
2643 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
2652 lvItem
.stateMask
= LVIS_SELECTED
;
2654 /* need to clone the DPA because callbacks can change it */
2655 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
2656 iterator_ranges(&i
, ranges_diff(clone
, toSkip
));
2657 while(iterator_next(&i
))
2658 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
2659 /* note that the iterator destructor will free the cloned range */
2660 iterator_destroy(&i
);
2665 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2669 if (!(toSkip
= ranges_create(1))) return FALSE
;
2670 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
2671 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
2672 ranges_destroy(toSkip
);
2676 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
2678 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
2683 * Retrieves the number of items that are marked as selected.
2686 * [I] infoPtr : valid pointer to the listview structure
2689 * Number of items selected.
2691 static INT
LISTVIEW_GetSelectedCount(LISTVIEW_INFO
*infoPtr
)
2693 INT nSelectedCount
= 0;
2695 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
2698 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2700 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
2705 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
2707 TRACE("nSelectedCount=%d\n", nSelectedCount
);
2708 return nSelectedCount
;
2713 * Manages the item focus.
2716 * [I] infoPtr : valid pointer to the listview structure
2717 * [I] nItem : item index
2720 * TRUE : focused item changed
2721 * FALSE : focused item has NOT changed
2723 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2725 INT oldFocus
= infoPtr
->nFocusedItem
;
2728 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
2730 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
2731 lvItem
.stateMask
= LVIS_FOCUSED
;
2732 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
2734 return oldFocus
!= infoPtr
->nFocusedItem
;
2737 /* Helper function for LISTVIEW_ShiftIndices *only* */
2738 static INT
shift_item(LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
2740 if (nShiftItem
< nItem
) return nShiftItem
;
2742 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
2744 if (direction
> 0) return nShiftItem
+ direction
;
2746 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
2751 * Updates the various indices after an item has been inserted or deleted.
2754 * [I] infoPtr : valid pointer to the listview structure
2755 * [I] nItem : item index
2756 * [I] direction : Direction of shift, +1 or -1.
2761 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
2765 TRACE("Shifting %iu, %i steps\n", nItem
, direction
);
2767 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
2769 assert(abs(direction
) == 1);
2771 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
2773 nNewFocus
= shift_item(infoPtr
, infoPtr
->nFocusedItem
, nItem
, direction
);
2774 if (nNewFocus
!= infoPtr
->nFocusedItem
)
2775 LISTVIEW_SetItemFocus(infoPtr
, nNewFocus
);
2777 /* But we are not supposed to modify nHotItem! */
2783 * Adds a block of selections.
2786 * [I] infoPtr : valid pointer to the listview structure
2787 * [I] nItem : item index
2792 static void LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2794 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
2795 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
2799 if (nFirst
== -1) nFirst
= nItem
;
2801 item
.state
= LVIS_SELECTED
;
2802 item
.stateMask
= LVIS_SELECTED
;
2804 /* FIXME: this is not correct LVS_OWNERDATA
2805 * setting the item states individually will generate
2806 * a LVN_ITEMCHANGED notification for each one. Instead,
2807 * we have to send a LVN_ODSTATECHANGED notification.
2808 * See MSDN documentation for LVN_ITEMCHANGED.
2810 for (i
= nFirst
; i
<= nLast
; i
++)
2811 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
2817 * Sets a single group selection.
2820 * [I] infoPtr : valid pointer to the listview structure
2821 * [I] nItem : item index
2826 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2828 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2833 if (!(selection
= ranges_create(100))) return;
2835 item
.state
= LVIS_SELECTED
;
2836 item
.stateMask
= LVIS_SELECTED
;
2838 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
2840 if (infoPtr
->nSelectionMark
== -1)
2842 infoPtr
->nSelectionMark
= nItem
;
2843 ranges_additem(selection
, nItem
);
2849 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
2850 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
2851 ranges_add(selection
, sel
);
2856 RECT rcItem
, rcSel
, rcSelMark
;
2859 rcItem
.left
= LVIR_BOUNDS
;
2860 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return;
2861 rcSelMark
.left
= LVIR_BOUNDS
;
2862 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) return;
2863 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
2864 iterator_frameditems(&i
, infoPtr
, &rcSel
);
2865 while(iterator_next(&i
))
2867 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
2868 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
2870 iterator_destroy(&i
);
2873 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
2874 iterator_ranges(&i
, selection
);
2875 while(iterator_next(&i
))
2876 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
2877 /* this will also destroy the selection */
2878 iterator_destroy(&i
);
2880 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
2885 * Sets a single selection.
2888 * [I] infoPtr : valid pointer to the listview structure
2889 * [I] nItem : item index
2894 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2898 TRACE("nItem=%d\n", nItem
);
2900 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
2902 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
2903 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
2904 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
2906 infoPtr
->nSelectionMark
= nItem
;
2911 * Set selection(s) with keyboard.
2914 * [I] infoPtr : valid pointer to the listview structure
2915 * [I] nItem : item index
2918 * SUCCESS : TRUE (needs to be repainted)
2919 * FAILURE : FALSE (nothing has changed)
2921 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2923 /* FIXME: pass in the state */
2924 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
2925 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
2926 BOOL bResult
= FALSE
;
2928 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
2930 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
2933 LISTVIEW_SetSelection(infoPtr
, nItem
);
2940 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
2944 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
2949 LISTVIEW_SetSelection(infoPtr
, nItem
);
2952 ListView_EnsureVisible(infoPtr
->hwndSelf
, nItem
, FALSE
);
2955 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
2962 * Called when the mouse is being actively tracked and has hovered for a specified
2966 * [I] infoPtr : valid pointer to the listview structure
2967 * [I] fwKeys : key indicator
2968 * [I] pts : mouse position
2971 * 0 if the message was processed, non-zero if there was an error
2974 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
2975 * over the item for a certain period of time.
2978 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, WORD fwKyes
, POINTS pts
)
2980 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
2981 /* FIXME: select the item!!! */
2982 /*LISTVIEW_GetItemAtPt(infoPtr, pt)*/;
2989 * Called whenever WM_MOUSEMOVE is received.
2992 * [I] infoPtr : valid pointer to the listview structure
2993 * [I] fwKeys : key indicator
2994 * [I] pts : mouse position
2997 * 0 if the message is processed, non-zero if there was an error
2999 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, POINTS pts
)
3001 TRACKMOUSEEVENT trackinfo
;
3003 /* see if we are supposed to be tracking mouse hovering */
3004 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) {
3005 /* fill in the trackinfo struct */
3006 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
3007 trackinfo
.dwFlags
= TME_QUERY
;
3008 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
3009 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
3011 /* see if we are already tracking this hwnd */
3012 _TrackMouseEvent(&trackinfo
);
3014 if(!(trackinfo
.dwFlags
& TME_HOVER
)) {
3015 trackinfo
.dwFlags
= TME_HOVER
;
3017 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
3018 _TrackMouseEvent(&trackinfo
);
3027 * Tests wheather the item is assignable to a list with style lStyle
3029 static inline BOOL
is_assignable_item(LPLVITEMW lpLVItem
, LONG lStyle
)
3031 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
3032 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
3033 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
3041 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
3044 * [I] infoPtr : valid pointer to the listview structure
3045 * [I] lpLVItem : valid pointer to new item atttributes
3046 * [I] isNew : the item being set is being inserted
3047 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3048 * [O] bChanged : will be set to TRUE if the item really changed
3054 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
3063 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
3065 if (lpLVItem
->mask
== 0) return TRUE
;
3067 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3069 /* a virtual listview we stores only selection and focus */
3070 if ((lpLVItem
->mask
& ~LVIF_STATE
) || (lpLVItem
->stateMask
& ~(LVIS_FOCUSED
| LVIS_SELECTED
)))
3076 HDPA hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3077 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
3081 /* we need to get the lParam and state of the item */
3082 item
.iItem
= lpLVItem
->iItem
;
3083 item
.iSubItem
= lpLVItem
->iSubItem
;
3084 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
3085 item
.stateMask
= ~0;
3088 if (!isNew
&& !LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) return FALSE
;
3090 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
3091 /* determine what fields will change */
3092 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
))
3093 uChanged
|= LVIF_STATE
;
3095 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
3096 uChanged
|= LVIF_IMAGE
;
3098 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
3099 uChanged
|= LVIF_PARAM
;
3101 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
3102 uChanged
|= LVIF_INDENT
;
3104 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
3105 uChanged
|= LVIF_TEXT
;
3107 TRACE("uChanged=0x%x\n", uChanged
);
3108 if (!uChanged
) return TRUE
;
3111 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
3112 nmlv
.iItem
= lpLVItem
->iItem
;
3113 nmlv
.uNewState
= (item
.state
& ~lpLVItem
->stateMask
) | (lpLVItem
->state
& lpLVItem
->stateMask
);
3114 nmlv
.uOldState
= item
.state
;
3115 nmlv
.uChanged
= uChanged
;
3116 nmlv
.lParam
= item
.lParam
;
3118 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
3119 /* and we are _NOT_ virtual (LVS_OWERNDATA) */
3120 if(lpItem
&& !isNew
&& notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
3123 /* copy information */
3124 if (lpLVItem
->mask
& LVIF_TEXT
)
3125 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3127 if (lpLVItem
->mask
& LVIF_IMAGE
)
3128 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
3130 if (lpLVItem
->mask
& LVIF_PARAM
)
3131 lpItem
->lParam
= lpLVItem
->lParam
;
3133 if (lpLVItem
->mask
& LVIF_INDENT
)
3134 lpItem
->iIndent
= lpLVItem
->iIndent
;
3136 if (uChanged
& LVIF_STATE
)
3138 if (lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& ~(LVIS_FOCUSED
| LVIS_SELECTED
))
3140 lpItem
->state
&= ~lpLVItem
->stateMask
;
3141 lpItem
->state
|= (lpLVItem
->state
& lpLVItem
->stateMask
);
3143 if (lpLVItem
->state
& lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3145 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
3146 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3148 else if (lpLVItem
->stateMask
& LVIS_SELECTED
)
3149 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3151 /* if we are asked to change focus, and we manage it, do it */
3152 if (lpLVItem
->state
& lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
3154 if (lpLVItem
->state
& LVIS_FOCUSED
)
3156 LISTVIEW_SetItemFocus(infoPtr
, -1);
3157 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
3158 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, FALSE
);
3160 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
3161 infoPtr
->nFocusedItem
= -1;
3165 /* if we're inserting the item, we're done */
3166 if (isNew
) return TRUE
;
3168 /* send LVN_ITEMCHANGED notification */
3169 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
3170 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
3177 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
3180 * [I] infoPtr : valid pointer to the listview structure
3181 * [I] lpLVItem : valid pointer to new subitem atttributes
3182 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3183 * [O] bChanged : will be set to TRUE if the item really changed
3189 static BOOL
set_sub_item(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
, BOOL
*bChanged
)
3192 SUBITEM_INFO
*lpSubItem
;
3194 /* we do not support subitems for virtual listviews */
3195 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
3197 /* set subitem only if column is present */
3198 if (lpLVItem
->iSubItem
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
3200 /* First do some sanity checks */
3201 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
)) return FALSE
;
3202 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
))) return TRUE
;
3204 /* get the subitem structure, and create it if not there */
3205 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3206 assert (hdpaSubItems
);
3208 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
3211 SUBITEM_INFO
*tmpSubItem
;
3214 lpSubItem
= (SUBITEM_INFO
*)COMCTL32_Alloc(sizeof(SUBITEM_INFO
));
3215 if (!lpSubItem
) return FALSE
;
3216 /* we could binary search here, if need be...*/
3217 for (i
= 1; i
< hdpaSubItems
->nItemCount
; i
++)
3219 tmpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
3220 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
3222 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
3224 COMCTL32_Free(lpSubItem
);
3227 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
3231 if (lpLVItem
->mask
& LVIF_IMAGE
)
3232 if (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
)
3234 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
3238 if (lpLVItem
->mask
& LVIF_TEXT
)
3239 if (lpSubItem
->hdr
.pszText
!= lpLVItem
->pszText
)
3241 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3250 * Sets item attributes.
3253 * [I] infoPtr : valid pointer to the listview structure
3254 * [I] lpLVItem : new item atttributes
3255 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3261 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
3263 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3264 LPWSTR pszText
= NULL
;
3265 BOOL bResult
, bChanged
= FALSE
;
3267 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
3269 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
3272 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
3273 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_textW(lpLVItem
->pszText
))
3275 pszText
= lpLVItem
->pszText
;
3276 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
3279 /* actually set the fields */
3280 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
3282 if (lpLVItem
->iSubItem
)
3283 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
3285 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
3287 /* redraw item, if necessary */
3288 if (bChanged
&& !infoPtr
->bIsDrawing
)
3290 /* this little optimization eliminates some nasty flicker */
3291 if ( uView
== LVS_REPORT
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
3292 (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || lpLVItem
->iSubItem
) )
3293 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
3295 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
3300 textfreeT(lpLVItem
->pszText
, isW
);
3301 lpLVItem
->pszText
= pszText
;
3309 * Retrieves the index of the item at coordinate (0, 0) of the client area.
3312 * [I] infoPtr : valid pointer to the listview structure
3317 static INT
LISTVIEW_GetTopIndex(LISTVIEW_INFO
*infoPtr
)
3319 LONG lStyle
= infoPtr
->dwStyle
;
3320 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3322 SCROLLINFO scrollInfo
;
3324 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3325 scrollInfo
.fMask
= SIF_POS
;
3327 if (uView
== LVS_LIST
)
3329 if ((lStyle
& WS_HSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3330 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
3332 else if (uView
== LVS_REPORT
)
3334 if ((lStyle
& WS_VSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3335 nItem
= scrollInfo
.nPos
;
3339 if ((lStyle
& WS_VSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3340 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
3343 TRACE("nItem=%d\n", nItem
);
3351 * Erases the background of the given rectangle
3354 * [I] infoPtr : valid pointer to the listview structure
3355 * [I] hdc : device context handle
3356 * [I] lprcBox : clipping rectangle
3362 static inline BOOL
LISTVIEW_FillBkgnd(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
* lprcBox
)
3364 if (!infoPtr
->hBkBrush
) return FALSE
;
3366 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, debugrect(lprcBox
), infoPtr
->hBkBrush
);
3368 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
3376 * [I] infoPtr : valid pointer to the listview structure
3377 * [I] hdc : device context handle
3378 * [I] nItem : item index
3379 * [I] nSubItem : subitem index
3380 * [I] pos : item position in client coordinates
3381 * [I] cdmode : custom draw mode
3387 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
3389 UINT uFormat
, uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3390 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
3391 WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
3392 DWORD cditemmode
= CDRF_DODEFAULT
;
3393 RECT
* lprcFocus
, rcSelect
, rcBox
, rcState
, rcIcon
, rcLabel
;
3394 NMLVCUSTOMDRAW nmlvcd
;
3398 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, debugpoint(&pos
));
3400 /* get information needed for drawing the item */
3401 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
3402 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
| LVIF_PARAM
;
3403 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
3404 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
;
3405 lvItem
.iItem
= nItem
;
3406 lvItem
.iSubItem
= nSubItem
;
3409 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
3410 lvItem
.pszText
= szDispText
;
3411 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
3412 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3413 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3414 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
3415 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
3417 /* now check if we need to update the focus rectangle */
3418 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
3420 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
3421 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcState
, &rcIcon
, &rcLabel
);
3422 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
3423 OffsetRect(&rcState
, pos
.x
, pos
.y
);
3424 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
3425 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
3426 TRACE(" rcBox=%s, rcState=%s, rcIcon=%s. rcLabel=%s\n",
3427 debugrect(&rcBox
), debugrect(&rcState
), debugrect(&rcIcon
), debugrect(&rcLabel
));
3429 /* fill in the custom draw structure */
3430 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
);
3431 nmlvcd
.nmcd
.dwItemSpec
= lvItem
.iItem
;
3432 nmlvcd
.iSubItem
= lvItem
.iSubItem
;
3433 if (lvItem
.state
& LVIS_SELECTED
) nmlvcd
.nmcd
.uItemState
|= CDIS_SELECTED
;
3434 if (lvItem
.state
& LVIS_FOCUSED
) nmlvcd
.nmcd
.uItemState
|= CDIS_FOCUS
;
3435 if (lvItem
.iItem
== infoPtr
->nHotItem
) nmlvcd
.nmcd
.uItemState
|= CDIS_HOT
;
3436 nmlvcd
.nmcd
.lItemlParam
= lvItem
.lParam
;
3438 if (lvItem
.state
& LVIS_SELECTED
)
3440 if (infoPtr
->bFocus
)
3442 nmlvcd
.clrTextBk
= comctl32_color
.clrHighlight
;
3443 nmlvcd
.clrText
= comctl32_color
.clrHighlightText
;
3445 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
3447 nmlvcd
.clrTextBk
= comctl32_color
.clr3dFace
;
3448 nmlvcd
.clrText
= comctl32_color
.clrBtnText
;
3452 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
3453 cditemmode
= notify_customdraw (infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
3454 if (cditemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
3457 if (infoPtr
->himlState
&& !IsRectEmpty(&rcState
))
3459 UINT uStateImage
= (lvItem
.state
& LVIS_STATEIMAGEMASK
) >> 12;
3462 TRACE("uStateImage=%d\n", uStateImage
);
3463 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
, rcState
.left
, rcState
.top
, ILD_NORMAL
);
3468 himl
= (uView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
3469 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
3471 TRACE("iImage=%d\n", lvItem
.iImage
);
3472 ImageList_Draw(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
3473 (lvItem
.state
& LVIS_SELECTED
) && (infoPtr
->bFocus
) ? ILD_SELECTED
: ILD_NORMAL
);
3476 /* Don't bother painting item being edited */
3477 if (infoPtr
->hwndEdit
&& lprcFocus
&& nSubItem
== 0) goto postpaint
;
3479 /* Set the text attributes */
3480 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
3482 SetBkMode(hdc
, OPAQUE
);
3483 SetBkColor(hdc
, nmlvcd
.clrTextBk
== CLR_DEFAULT
? infoPtr
->clrTextBkDefault
: nmlvcd
.clrTextBk
);
3486 SetBkMode(hdc
, TRANSPARENT
);
3487 SetTextColor(hdc
, nmlvcd
.clrText
);
3489 /* draw the selection background, if we're drawing the main item */
3493 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3494 rcSelect
.right
= rcBox
.right
;
3496 if (lvItem
.state
& LVIS_SELECTED
)
3497 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, 0, 0, 0);
3498 if(lprcFocus
) *lprcFocus
= rcSelect
;
3501 /* figure out the text drawing flags */
3502 uFormat
= (uView
== LVS_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
3503 if (uView
== LVS_ICON
)
3504 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
3507 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
3509 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
3510 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
3511 default: uFormat
|= DT_LEFT
;
3514 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
))) rcLabel
.left
+= 2;
3515 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
3518 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
3519 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
3525 * Draws listview items when in owner draw mode.
3528 * [I] infoPtr : valid pointer to the listview structure
3529 * [I] hdc : device context handle
3534 static void LISTVIEW_RefreshOwnerDraw(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
3536 UINT uID
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_ID
);
3537 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
3538 POINT Origin
, Position
;
3545 ZeroMemory(&dis
, sizeof(dis
));
3547 /* Get scroll info once before loop */
3548 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3550 /* figure out what we need to draw */
3551 iterator_visibleitems(&i
, infoPtr
, hdc
);
3553 /* send cache hint notification */
3554 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3556 RANGE range
= iterator_range(&i
);
3559 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
3560 nmlv
.iFrom
= range
.lower
;
3561 nmlv
.iTo
= range
.upper
- 1;
3562 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
3565 /* iterate through the invalidated rows */
3566 while(iterator_next(&i
))
3568 item
.iItem
= i
.nItem
;
3570 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
3571 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
3572 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
3574 dis
.CtlType
= ODT_LISTVIEW
;
3576 dis
.itemID
= item
.iItem
;
3577 dis
.itemAction
= ODA_DRAWENTIRE
;
3579 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
3580 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
3581 dis
.hwndItem
= infoPtr
->hwndSelf
;
3583 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
3584 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
3585 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
3586 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
3587 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
3588 dis
.itemData
= item
.lParam
;
3590 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), debugrect(&dis
.rcItem
));
3591 SendMessageW(hwndParent
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
3593 iterator_destroy(&i
);
3598 * Draws listview items when in report display mode.
3601 * [I] infoPtr : valid pointer to the listview structure
3602 * [I] hdc : device context handle
3603 * [I] cdmode : custom draw mode
3608 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD cdmode
)
3610 INT rgntype
, nFirstCol
, nLastCol
, nCol
;
3611 RECT rcClip
, rcItem
;
3612 POINT Origin
, Position
;
3617 /* figure out what to draw */
3618 rgntype
= GetClipBox(hdc
, &rcClip
);
3619 if (rgntype
== NULLREGION
) return;
3621 /* Get scroll info once before loop */
3622 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3624 /* narrow down the columns we need to paint */
3625 for(nFirstCol
= 0; nFirstCol
< infoPtr
->hdpaColumns
->nItemCount
; nFirstCol
++)
3627 LISTVIEW_GetHeaderRect(infoPtr
, nFirstCol
, &rcItem
);
3628 if (rcItem
.right
+ Origin
.x
>= rcClip
.left
) break;
3630 for(nLastCol
= infoPtr
->hdpaColumns
->nItemCount
- 1; nLastCol
>= 0; nLastCol
--)
3632 LISTVIEW_GetHeaderRect(infoPtr
, nLastCol
, &rcItem
);
3633 if (rcItem
.left
+ Origin
.x
< rcClip
.right
) break;
3636 /* figure out what we need to draw */
3637 iterator_visibleitems(&i
, infoPtr
, hdc
);
3639 /* a last few bits before we start drawing */
3640 TRACE("Colums=(%d - %d)\n", nFirstCol
, nLastCol
);
3642 /* iterate through the invalidated rows */
3643 while(iterator_next(&i
))
3645 /* iterate through the invalidated columns */
3646 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
3648 LISTVIEW_GetItemOrigin(infoPtr
, i
.nItem
, &Position
);
3649 Position
.x
+= Origin
.x
;
3650 Position
.y
+= Origin
.y
;
3652 if (rgntype
== COMPLEXREGION
)
3654 LISTVIEW_GetHeaderRect(infoPtr
, nCol
, &rcItem
);
3656 rcItem
.bottom
= infoPtr
->nItemHeight
;
3657 OffsetRect(&rcItem
, Position
.x
, Position
.y
);
3658 if (!RectVisible(hdc
, &rcItem
)) continue;
3661 LISTVIEW_DrawItem(infoPtr
, hdc
, i
.nItem
, nCol
, Position
, cdmode
);
3664 iterator_destroy(&i
);
3669 * Draws listview items when in list display mode.
3672 * [I] infoPtr : valid pointer to the listview structure
3673 * [I] hdc : device context handle
3674 * [I] cdmode : custom draw mode
3679 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD cdmode
)
3681 POINT Origin
, Position
;
3684 /* Get scroll info once before loop */
3685 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3687 /* figure out what we need to draw */
3688 iterator_visibleitems(&i
, infoPtr
, hdc
);
3690 while(iterator_prev(&i
))
3692 LISTVIEW_GetItemOrigin(infoPtr
, i
.nItem
, &Position
);
3693 Position
.x
+= Origin
.x
;
3694 Position
.y
+= Origin
.y
;
3696 LISTVIEW_DrawItem(infoPtr
, hdc
, i
.nItem
, 0, Position
, cdmode
);
3698 iterator_destroy(&i
);
3704 * Draws listview items.
3707 * [I] infoPtr : valid pointer to the listview structure
3708 * [I] hdc : device context handle
3713 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
3715 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3716 COLORREF oldTextColor
, oldClrTextBk
, oldClrText
;
3717 NMLVCUSTOMDRAW nmlvcd
;
3723 LISTVIEW_DUMP(infoPtr
);
3725 infoPtr
->bIsDrawing
= TRUE
;
3727 /* save dc values we're gonna trash while drawing */
3728 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3729 oldBkMode
= GetBkMode(hdc
);
3730 infoPtr
->clrTextBkDefault
= GetBkColor(hdc
);
3731 oldTextColor
= GetTextColor(hdc
);
3733 oldClrTextBk
= infoPtr
->clrTextBk
;
3734 oldClrText
= infoPtr
->clrText
;
3736 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
3737 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
);
3738 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
3739 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
3741 /* Use these colors to draw the items */
3742 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
3743 infoPtr
->clrText
= nmlvcd
.clrText
;
3745 /* nothing to draw */
3746 if(infoPtr
->nItemCount
== 0) goto enddraw
;
3748 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (uView
== LVS_REPORT
))
3749 LISTVIEW_RefreshOwnerDraw(infoPtr
, hdc
);
3752 if (uView
== LVS_REPORT
)
3753 LISTVIEW_RefreshReport(infoPtr
, hdc
, cdmode
);
3754 else /* LVS_LIST, LVS_ICON or LVS_SMALLICON */
3755 LISTVIEW_RefreshList(infoPtr
, hdc
, cdmode
);
3757 /* if we have a focus rect, draw it */
3758 if (infoPtr
->bFocus
)
3759 DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
3763 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
3764 notify_customdraw(infoPtr
, CDDS_POSTPAINT
, &nmlvcd
);
3766 infoPtr
->clrTextBk
= oldClrTextBk
;
3767 infoPtr
->clrText
= oldClrText
;
3769 SelectObject(hdc
, hOldFont
);
3770 SetBkMode(hdc
, oldBkMode
);
3771 SetBkColor(hdc
, infoPtr
->clrTextBkDefault
);
3772 SetTextColor(hdc
, oldTextColor
);
3773 infoPtr
->bIsDrawing
= FALSE
;
3779 * Calculates the approximate width and height of a given number of items.
3782 * [I] infoPtr : valid pointer to the listview structure
3783 * [I] nItemCount : number of items
3784 * [I] wWidth : width
3785 * [I] wHeight : height
3788 * Returns a DWORD. The width in the low word and the height in high word.
3790 static DWORD
LISTVIEW_ApproximateViewRect(LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
3791 WORD wWidth
, WORD wHeight
)
3793 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3794 INT nItemCountPerColumn
= 1;
3795 INT nColumnCount
= 0;
3796 DWORD dwViewRect
= 0;
3798 if (nItemCount
== -1)
3799 nItemCount
= infoPtr
->nItemCount
;
3801 if (uView
== LVS_LIST
)
3803 if (wHeight
== 0xFFFF)
3805 /* use current height */
3806 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
3809 if (wHeight
< infoPtr
->nItemHeight
)
3810 wHeight
= infoPtr
->nItemHeight
;
3814 if (infoPtr
->nItemHeight
> 0)
3816 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
3817 if (nItemCountPerColumn
== 0)
3818 nItemCountPerColumn
= 1;
3820 if (nItemCount
% nItemCountPerColumn
!= 0)
3821 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
3823 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
3827 /* Microsoft padding magic */
3828 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
3829 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
3831 dwViewRect
= MAKELONG(wWidth
, wHeight
);
3833 else if (uView
== LVS_REPORT
)
3834 FIXME("uView == LVS_REPORT: not implemented\n");
3835 else if (uView
== LVS_SMALLICON
)
3836 FIXME("uView == LVS_SMALLICON: not implemented\n");
3837 else if (uView
== LVS_ICON
)
3838 FIXME("uView == LVS_ICON: not implemented\n");
3843 /* << LISTVIEW_CreateDragImage >> */
3848 * Removes all listview items and subitems.
3851 * [I] infoPtr : valid pointer to the listview structure
3857 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
)
3860 HDPA hdpaSubItems
= NULL
;
3867 /* we do it directly, to avoid notifications */
3868 ranges_clear(infoPtr
->selectionRanges
);
3869 infoPtr
->nSelectionMark
= -1;
3870 infoPtr
->nFocusedItem
= -1;
3871 SetRectEmpty(&infoPtr
->rcFocus
);
3872 /* But we are supposed to leave nHotItem as is! */
3875 /* send LVN_DELETEALLITEMS notification */
3876 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
3878 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
3880 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
3882 /* send LVN_DELETEITEM notification, if not supressed */
3886 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
3888 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3890 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, i
);
3891 for (j
= 0; j
< hdpaSubItems
->nItemCount
; j
++)
3893 hdrItem
= (ITEMHDR
*)DPA_GetPtr(hdpaSubItems
, j
);
3894 if (is_textW(hdrItem
->pszText
)) COMCTL32_Free(hdrItem
->pszText
);
3895 COMCTL32_Free(hdrItem
);
3897 DPA_Destroy(hdpaSubItems
);
3898 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
3900 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
3901 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
3902 infoPtr
->nItemCount
--;
3905 LISTVIEW_UpdateScroll(infoPtr
);
3907 LISTVIEW_InvalidateList(infoPtr
);
3914 * Scrolls, and updates the columns, when a column is changing width.
3917 * [I] infoPtr : valid pointer to the listview structure
3918 * [I] nColumn : column to scroll
3919 * [I] dx : amount of scroll, in pixels
3924 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
3926 COLUMN_INFO
*lpColumnInfo
;
3930 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, infoPtr
->hdpaColumns
->nItemCount
- 1));
3931 rcCol
= lpColumnInfo
->rcHeader
;
3932 if (nColumn
>= infoPtr
->hdpaColumns
->nItemCount
)
3933 rcCol
.left
= rcCol
.right
;
3935 /* ajust the other columns */
3936 for (nCol
= nColumn
; nCol
< infoPtr
->hdpaColumns
->nItemCount
; nCol
++)
3938 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
3939 lpColumnInfo
->rcHeader
.left
+= dx
;
3940 lpColumnInfo
->rcHeader
.right
+= dx
;
3943 /* do not update screen if not in report mode */
3944 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) != LVS_REPORT
) return;
3946 /* if we have a focus, must first erase the focus rect */
3947 if (infoPtr
->bFocus
) LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
3949 /* Need to reset the item width when inserting a new column */
3950 infoPtr
->nItemWidth
+= dx
;
3952 LISTVIEW_UpdateScroll(infoPtr
);
3954 /* scroll to cover the deleted column, and invalidate for redraw */
3955 rcOld
= infoPtr
->rcList
;
3956 rcOld
.left
= rcCol
.left
;
3957 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
3959 /* we can restore focus now */
3960 if (infoPtr
->bFocus
) LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
3965 * Removes a column from the listview control.
3968 * [I] infoPtr : valid pointer to the listview structure
3969 * [I] nColumn : column index
3975 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
3979 TRACE("nColumn=%d\n", nColumn
);
3981 if (nColumn
<= 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
3983 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
3985 if (!Header_DeleteItem(infoPtr
->hwndHeader
, nColumn
))
3988 COMCTL32_Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
3989 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
3991 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
3993 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
3995 INT nItem
, nSubItem
, i
;
3997 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
3999 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
4002 for (i
= 1; i
< hdpaSubItems
->nItemCount
; i
++)
4004 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
4005 if (lpSubItem
->iSubItem
== nColumn
)
4008 lpDelItem
= lpSubItem
;
4010 else if (lpSubItem
->iSubItem
> nColumn
)
4012 lpSubItem
->iSubItem
--;
4016 /* if we found our subitem, zapp it */
4020 if (is_textW(lpDelItem
->hdr
.pszText
))
4021 COMCTL32_Free(lpDelItem
->hdr
.pszText
);
4024 COMCTL32_Free(lpDelItem
);
4026 /* free dpa memory */
4027 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
4032 /* update the other column info */
4033 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
4040 * Invalidates the listview after an item's insertion or deletion.
4043 * [I] infoPtr : valid pointer to the listview structure
4044 * [I] nItem : item index
4045 * [I] dir : -1 if deleting, 1 if inserting
4050 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
4052 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4053 INT nPerCol
, nItemCol
, nItemRow
;
4057 assert (abs(dir
) == 1);
4059 /* arrange icons if autoarrange is on */
4060 if (infoPtr
->dwStyle
& LVS_AUTOARRANGE
)
4062 BOOL arrange
= TRUE
;
4063 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
4064 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
4065 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
4068 /* scrollbars need updating */
4069 LISTVIEW_UpdateScroll(infoPtr
);
4071 /* figure out the item's position */
4072 if (uView
== LVS_REPORT
)
4073 nPerCol
= infoPtr
->nItemCount
+ 1;
4074 else if (uView
== LVS_LIST
)
4075 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
4076 else /* LVS_ICON, or LVS_SMALLICON */
4079 nItemCol
= nItem
/ nPerCol
;
4080 nItemRow
= nItem
% nPerCol
;
4081 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4083 /* move the items below up a slot */
4084 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
4085 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
4086 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
4087 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
4088 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
4089 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
4090 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
4091 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4093 /* report has only that column, so we're done */
4094 if (uView
== LVS_REPORT
) return;
4096 /* now for LISTs, we have to deal with the columns to the right */
4097 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
4099 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
4100 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
4101 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
4102 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
4103 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
4104 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4109 * Removes an item from the listview control.
4112 * [I] infoPtr : valid pointer to the listview structure
4113 * [I] nItem : item index
4119 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
4121 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4126 TRACE("(nItem=%d)\n", nItem
);
4128 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
4130 /* remove selection, and focus */
4132 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4133 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
4135 /* we need to do this here, because we'll be deleting stuff */
4136 if (uView
== LVS_SMALLICON
|| uView
== LVS_ICON
)
4137 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
4139 /* send LVN_DELETEITEM notification. */
4140 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
4142 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
4144 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4150 hdpaSubItems
= (HDPA
)DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
4151 for (i
= 0; i
< hdpaSubItems
->nItemCount
; i
++)
4153 hdrItem
= (ITEMHDR
*)DPA_GetPtr(hdpaSubItems
, i
);
4154 if (is_textW(hdrItem
->pszText
)) COMCTL32_Free(hdrItem
->pszText
);
4155 COMCTL32_Free(hdrItem
);
4157 DPA_Destroy(hdpaSubItems
);
4160 if (uView
== LVS_SMALLICON
|| uView
== LVS_ICON
)
4162 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
4163 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
4164 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
4167 infoPtr
->nItemCount
--;
4168 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
4170 /* now is the invalidation fun */
4171 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
4178 * Callback implementation for editlabel control
4181 * [I] infoPtr : valid pointer to the listview structure
4182 * [I] pszText : modified text
4183 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
4189 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, LPWSTR pszText
, BOOL isW
)
4191 NMLVDISPINFOW dispInfo
;
4193 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
4195 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4196 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4197 dispInfo
.item
.iItem
= infoPtr
->nEditLabelItem
;
4198 dispInfo
.item
.iSubItem
= 0;
4199 dispInfo
.item
.stateMask
= ~0;
4200 if (!LISTVIEW_GetItemW(infoPtr
, &dispInfo
.item
)) return FALSE
;
4201 /* add the text from the edit in */
4202 dispInfo
.item
.mask
|= LVIF_TEXT
;
4203 dispInfo
.item
.pszText
= pszText
;
4204 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
4206 /* Do we need to update the Item Text */
4207 if (!notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
)) return FALSE
;
4208 if (!pszText
) return TRUE
;
4210 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4211 dispInfo
.item
.mask
= LVIF_TEXT
;
4212 dispInfo
.item
.iItem
= infoPtr
->nEditLabelItem
;
4213 dispInfo
.item
.iSubItem
= 0;
4214 dispInfo
.item
.pszText
= pszText
;
4215 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
4216 return LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
4221 * Begin in place editing of specified list view item
4224 * [I] infoPtr : valid pointer to the listview structure
4225 * [I] nItem : item index
4226 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
4232 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
4234 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
4235 NMLVDISPINFOW dispInfo
;
4238 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
4240 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
4241 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
4243 infoPtr
->nEditLabelItem
= nItem
;
4245 /* Is the EditBox still there, if so remove it */
4246 if(infoPtr
->hwndEdit
!= 0)
4248 SetFocus(infoPtr
->hwndSelf
);
4249 infoPtr
->hwndEdit
= 0;
4252 LISTVIEW_SetSelection(infoPtr
, nItem
);
4253 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
4255 rect
.left
= LVIR_LABEL
;
4256 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
4258 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4259 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
4260 dispInfo
.item
.iItem
= nItem
;
4261 dispInfo
.item
.iSubItem
= 0;
4262 dispInfo
.item
.stateMask
= ~0;
4263 dispInfo
.item
.pszText
= szDispText
;
4264 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
4265 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
4267 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, WS_VISIBLE
,
4268 rect
.left
-2, rect
.top
-1, 0, rect
.bottom
- rect
.top
+2, isW
);
4269 if (!infoPtr
->hwndEdit
) return 0;
4271 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
4273 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
4274 infoPtr
->hwndEdit
= 0;
4278 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
4279 SetFocus(infoPtr
->hwndEdit
);
4280 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
4281 return infoPtr
->hwndEdit
;
4287 * Ensures the specified item is visible, scrolling into view if necessary.
4290 * [I] infoPtr : valid pointer to the listview structure
4291 * [I] nItem : item index
4292 * [I] bPartial : partially or entirely visible
4298 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
4300 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4301 INT nScrollPosHeight
= 0;
4302 INT nScrollPosWidth
= 0;
4303 INT nHorzAdjust
= 0;
4304 INT nVertAdjust
= 0;
4307 RECT rcItem
, rcTemp
;
4309 rcItem
.left
= LVIR_BOUNDS
;
4310 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
4312 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
4314 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
4316 /* scroll left/right, but in LVS_REPORT mode */
4317 if (uView
== LVS_LIST
)
4318 nScrollPosWidth
= infoPtr
->nItemWidth
;
4319 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
4320 nScrollPosWidth
= 1;
4322 if (rcItem
.left
< infoPtr
->rcList
.left
)
4325 if (uView
!= LVS_REPORT
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
4330 if (uView
!= LVS_REPORT
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
4334 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
4336 /* scroll up/down, but not in LVS_LIST mode */
4337 if (uView
== LVS_REPORT
)
4338 nScrollPosHeight
= infoPtr
->nItemHeight
;
4339 else if ((uView
== LVS_ICON
) || (uView
== LVS_SMALLICON
))
4340 nScrollPosHeight
= 1;
4342 if (rcItem
.top
< infoPtr
->rcList
.top
)
4345 if (uView
!= LVS_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
4350 if (uView
!= LVS_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
4354 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
4356 if (nScrollPosWidth
)
4358 INT diff
= nHorzDiff
/ nScrollPosWidth
;
4359 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
4360 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
4363 if (nScrollPosHeight
)
4365 INT diff
= nVertDiff
/ nScrollPosHeight
;
4366 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
4367 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
4375 * Searches for an item with specific characteristics.
4378 * [I] hwnd : window handle
4379 * [I] nStart : base item index
4380 * [I] lpFindInfo : item information to look for
4383 * SUCCESS : index of item
4386 static INT
LISTVIEW_FindItemW(LISTVIEW_INFO
*infoPtr
, INT nStart
,
4387 LPLVFINDINFOW lpFindInfo
)
4389 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4390 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4391 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
4392 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
4393 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
4394 POINT Position
, Destination
;
4397 if (!lpFindInfo
|| nItem
< 0) return -1;
4400 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
))
4402 lvItem
.mask
|= LVIF_TEXT
;
4403 lvItem
.pszText
= szDispText
;
4404 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4407 if (lpFindInfo
->flags
& LVFI_WRAP
)
4410 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
4411 (uView
== LVS_ICON
|| uView
==LVS_SMALLICON
))
4416 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4417 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
4418 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
4419 switch(lpFindInfo
->vkDirection
)
4421 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
4422 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
4423 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
4424 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
4425 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
4426 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
4427 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
4429 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
4430 Destination
.x
= rcArea
.right
;
4431 Destination
.y
= rcArea
.bottom
;
4433 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
4438 /* if LVFI_PARAM is specified, all other flags are ignored */
4439 if (lpFindInfo
->flags
& LVFI_PARAM
)
4441 lvItem
.mask
|= LVIF_PARAM
;
4443 lvItem
.mask
&= ~LVIF_TEXT
;
4447 for (; nItem
< nLast
; nItem
++)
4449 lvItem
.iItem
= nItem
;
4450 lvItem
.iSubItem
= 0;
4451 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
4453 if (lvItem
.mask
& LVIF_PARAM
&& lpFindInfo
->lParam
== lvItem
.lParam
)
4456 if (lvItem
.mask
& LVIF_TEXT
)
4458 if (lpFindInfo
->flags
& LVFI_PARTIAL
)
4460 if (strstrW(lvItem
.pszText
, lpFindInfo
->psz
) == NULL
) continue;
4464 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
4468 if (!bNearest
) return nItem
;
4470 /* This is very inefficient. To do a good job here,
4471 * we need a sorted array of (x,y) item positions */
4472 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
4474 /* compute the distance^2 to the destination */
4475 xdist
= Destination
.x
- Position
.x
;
4476 ydist
= Destination
.y
- Position
.y
;
4477 dist
= xdist
* xdist
+ ydist
* ydist
;
4479 /* remember the distance, and item if it's closer */
4483 nNearestItem
= nItem
;
4490 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
4495 return nNearestItem
;
4500 * Searches for an item with specific characteristics.
4503 * [I] hwnd : window handle
4504 * [I] nStart : base item index
4505 * [I] lpFindInfo : item information to look for
4508 * SUCCESS : index of item
4511 static INT
LISTVIEW_FindItemA(LISTVIEW_INFO
*infoPtr
, INT nStart
,
4512 LPLVFINDINFOA lpFindInfo
)
4514 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
);
4518 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
4519 if (hasText
) fiw
.psz
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
4520 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
4521 if (hasText
) textfreeT((LPWSTR
)fiw
.psz
, FALSE
);
4527 * Retrieves the background image of the listview control.
4530 * [I] infoPtr : valid pointer to the listview structure
4531 * [O] lpBkImage : background image attributes
4537 /* static BOOL LISTVIEW_GetBkImage(LISTVIEW_INFO *infoPtr, LPLVBKIMAGE lpBkImage) */
4539 /* FIXME (listview, "empty stub!\n"); */
4545 * Retrieves column attributes.
4548 * [I] infoPtr : valid pointer to the listview structure
4549 * [I] nColumn : column index
4550 * [IO] lpColumn : column information
4551 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
4552 * otherwise it is in fact a LPLVCOLUMNA
4558 static BOOL
LISTVIEW_GetColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
4560 COLUMN_INFO
*lpColumnInfo
;
4563 if (!lpColumn
|| nColumn
< 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
4564 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
4566 /* initialize memory */
4567 ZeroMemory(&hdi
, sizeof(hdi
));
4569 if (lpColumn
->mask
& LVCF_TEXT
)
4571 hdi
.mask
|= HDI_TEXT
;
4572 hdi
.pszText
= lpColumn
->pszText
;
4573 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
4576 if (lpColumn
->mask
& LVCF_IMAGE
)
4577 hdi
.mask
|= HDI_IMAGE
;
4579 if (lpColumn
->mask
& LVCF_ORDER
)
4580 hdi
.mask
|= HDI_ORDER
;
4582 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
4584 if (lpColumn
->mask
& LVCF_FMT
)
4585 lpColumn
->fmt
= lpColumnInfo
->fmt
;
4587 if (lpColumn
->mask
& LVCF_WIDTH
)
4588 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
4590 if (lpColumn
->mask
& LVCF_IMAGE
)
4591 lpColumn
->iImage
= hdi
.iImage
;
4593 if (lpColumn
->mask
& LVCF_ORDER
)
4594 lpColumn
->iOrder
= hdi
.iOrder
;
4600 static BOOL
LISTVIEW_GetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
4607 /* FIXME: little hack */
4608 for (i
= 0; i
< iCount
; i
++)
4616 * Retrieves the column width.
4619 * [I] infoPtr : valid pointer to the listview structure
4620 * [I] int : column index
4623 * SUCCESS : column width
4626 static INT
LISTVIEW_GetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
4628 INT nColumnWidth
= 0;
4631 TRACE("nColumn=%d\n", nColumn
);
4633 /* we have a 'column' in LIST and REPORT mode only */
4634 switch(infoPtr
->dwStyle
& LVS_TYPEMASK
)
4637 nColumnWidth
= infoPtr
->nItemWidth
;
4640 if (nColumn
< 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return 0;
4641 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
4642 nColumnWidth
= rcHeader
.right
- rcHeader
.left
;
4646 TRACE("nColumnWidth=%d\n", nColumnWidth
);
4647 return nColumnWidth
;
4652 * In list or report display mode, retrieves the number of items that can fit
4653 * vertically in the visible area. In icon or small icon display mode,
4654 * retrieves the total number of visible items.
4657 * [I] infoPtr : valid pointer to the listview structure
4660 * Number of fully visible items.
4662 static INT
LISTVIEW_GetCountPerPage(LISTVIEW_INFO
*infoPtr
)
4664 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
4668 return infoPtr
->nItemCount
;
4670 return LISTVIEW_GetCountPerColumn(infoPtr
);
4672 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
4679 * Retrieves an image list handle.
4682 * [I] infoPtr : valid pointer to the listview structure
4683 * [I] nImageList : image list identifier
4686 * SUCCESS : image list handle
4689 static HIMAGELIST
LISTVIEW_GetImageList(LISTVIEW_INFO
*infoPtr
, INT nImageList
)
4693 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
4694 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
4695 case LVSIL_STATE
: return infoPtr
->himlState
;
4700 /* LISTVIEW_GetISearchString */
4704 * Retrieves item attributes.
4707 * [I] hwnd : window handle
4708 * [IO] lpLVItem : item info
4709 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
4710 * if FALSE, the lpLVItem is a LPLVITEMA.
4713 * This is the internal 'GetItem' interface -- it tries to
4714 * be smart, and avoids text copies, if possible, by modifing
4715 * lpLVItem->pszText to point to the text string. Please note
4716 * that this is not always possible (e.g. OWNERDATA), so on
4717 * entry you *must* supply valid values for pszText, and cchTextMax.
4718 * The only difference to the documented interface is that upon
4719 * return, you should use *only* the lpLVItem->pszText, rather than
4720 * the buffer pointer you provided on input. Most code already does
4721 * that, so it's not a problem.
4722 * For the two cases when the text must be copied (that is,
4723 * for LVM_GETITEM, and LVMGETITEMTEXT), use LISTVIEW_GetItemExtT.
4729 static BOOL
LISTVIEW_GetItemT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
4731 NMLVDISPINFOW dispInfo
;
4736 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4738 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4741 if (lpLVItem
->mask
== 0) return TRUE
;
4743 /* a quick optimization if all we're asked is the focus state
4744 * these queries are worth optimising since they are common,
4745 * and can be answered in constant time, without the heavy accesses */
4746 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
4747 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
4749 lpLVItem
->state
= 0;
4750 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4751 lpLVItem
->state
|= LVIS_FOCUSED
;
4755 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4757 /* if the app stores all the data, handle it separately */
4758 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4760 dispInfo
.item
.state
= 0;
4762 /* if we need to callback, do it now */
4763 if ((lpLVItem
->mask
& ~LVIF_STATE
) || infoPtr
->uCallbackMask
)
4765 /* NOTE: copy only fields which we _know_ are initialized, some apps
4766 * depend on the uninitialized fields being 0 */
4767 dispInfo
.item
.mask
= lpLVItem
->mask
;
4768 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
4769 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
4770 if (lpLVItem
->mask
& LVIF_TEXT
)
4772 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
4773 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
4775 if (lpLVItem
->mask
& LVIF_STATE
)
4776 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
4777 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
4778 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
4779 *lpLVItem
= dispInfo
.item
;
4780 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
4783 /* we store only a little state, so if we're not asked, we're done */
4784 if (!(lpLVItem
->mask
& LVIF_STATE
) || lpLVItem
->iSubItem
) return TRUE
;
4786 /* if focus is handled by us, report it */
4787 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4789 lpLVItem
->state
&= ~LVIS_FOCUSED
;
4790 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4791 lpLVItem
->state
|= LVIS_FOCUSED
;
4794 /* and do the same for selection, if we handle it */
4795 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4797 lpLVItem
->state
&= ~LVIS_SELECTED
;
4798 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
4799 lpLVItem
->state
|= LVIS_SELECTED
;
4805 /* find the item and subitem structures before we proceed */
4806 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4807 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
4810 if (lpLVItem
->iSubItem
)
4812 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4813 if(!lpSubItem
) return FALSE
;
4814 pItemHdr
= &lpSubItem
->hdr
;
4817 pItemHdr
= &lpItem
->hdr
;
4819 /* Do we need to query the state from the app? */
4820 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& lpLVItem
->iSubItem
== 0)
4822 dispInfo
.item
.mask
|= LVIF_STATE
;
4823 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
4826 /* Do we need to enquire about the image? */
4827 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
4828 dispInfo
.item
.mask
|= LVIF_IMAGE
;
4830 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
4831 if ((lpLVItem
->mask
& LVIF_TEXT
) && !is_textW(pItemHdr
->pszText
))
4833 dispInfo
.item
.mask
|= LVIF_TEXT
;
4834 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
4835 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
4836 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
4837 *dispInfo
.item
.pszText
= '\0';
4840 /* If we don't have all the requested info, query the application */
4841 if (dispInfo
.item
.mask
!= 0)
4843 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
4844 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
4845 dispInfo
.item
.lParam
= lpItem
->lParam
;
4846 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
4847 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
4850 /* Now, handle the iImage field */
4851 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
4853 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
4854 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
4855 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
4857 else if (lpLVItem
->mask
& LVIF_IMAGE
)
4858 lpLVItem
->iImage
= pItemHdr
->iImage
;
4860 /* The pszText field */
4861 if (dispInfo
.item
.mask
& LVIF_TEXT
)
4863 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
4864 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
4866 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
4868 else if (lpLVItem
->mask
& LVIF_TEXT
)
4870 if (isW
) lpLVItem
->pszText
= pItemHdr
->pszText
;
4871 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
4874 /* if this is a subitem, we're done */
4875 if (lpLVItem
->iSubItem
) return TRUE
;
4877 /* Next is the lParam field */
4878 if (dispInfo
.item
.mask
& LVIF_PARAM
)
4880 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
4881 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
4882 lpItem
->lParam
= dispInfo
.item
.lParam
;
4884 else if (lpLVItem
->mask
& LVIF_PARAM
)
4885 lpLVItem
->lParam
= lpItem
->lParam
;
4887 /* ... the state field (this one is different due to uCallbackmask) */
4888 if (lpLVItem
->mask
& LVIF_STATE
)
4890 lpLVItem
->state
= lpItem
->state
;
4891 if (dispInfo
.item
.mask
& LVIF_STATE
)
4893 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
4894 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
4896 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4898 lpLVItem
->state
&= ~LVIS_FOCUSED
;
4899 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4900 lpLVItem
->state
|= LVIS_FOCUSED
;
4902 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4904 lpLVItem
->state
&= ~LVIS_SELECTED
;
4905 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
4906 lpLVItem
->state
|= LVIS_SELECTED
;
4910 /* and last, but not least, the indent field */
4911 if (lpLVItem
->mask
& LVIF_INDENT
)
4912 lpLVItem
->iIndent
= lpItem
->iIndent
;
4919 * Retrieves item attributes.
4922 * [I] hwnd : window handle
4923 * [IO] lpLVItem : item info
4924 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
4925 * if FALSE, the lpLVItem is a LPLVITEMA.
4928 * This is the external 'GetItem' interface -- it properly copies
4929 * the text in the provided buffer.
4935 static BOOL
LISTVIEW_GetItemExtT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
4940 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4943 pszText
= lpLVItem
->pszText
;
4944 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
4945 if (bResult
&& lpLVItem
->pszText
!= pszText
)
4946 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
4947 lpLVItem
->pszText
= pszText
;
4955 * Retrieves the position (upper-left) of the listview control item.
4956 * Note that for LVS_ICON style, the upper-left is that of the icon
4957 * and not the bounding box.
4960 * [I] infoPtr : valid pointer to the listview structure
4961 * [I] nItem : item index
4962 * [O] lpptPosition : coordinate information
4968 static BOOL
LISTVIEW_GetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
4970 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4973 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
4975 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
4977 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4978 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
4980 if (uView
== LVS_ICON
)
4982 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
4983 lpptPosition
->y
+= ICON_TOP_PADDING
;
4985 lpptPosition
->x
+= Origin
.x
;
4986 lpptPosition
->y
+= Origin
.y
;
4988 TRACE (" lpptPosition=%s\n", debugpoint(lpptPosition
));
4995 * Retrieves the bounding rectangle for a listview control item.
4998 * [I] infoPtr : valid pointer to the listview structure
4999 * [I] nItem : item index
5000 * [IO] lprc : bounding rectangle coordinates
5001 * lprc->left specifies the portion of the item for which the bounding
5002 * rectangle will be retrieved.
5004 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
5005 * including the icon and label.
5008 * * Experiment shows that native control returns:
5009 * * width = min (48, length of text line)
5010 * * .left = position.x - (width - iconsize.cx)/2
5011 * * .right = .left + width
5012 * * height = #lines of text * ntmHeight + icon height + 8
5013 * * .top = position.y - 2
5014 * * .bottom = .top + height
5015 * * separation between items .y = itemSpacing.cy - height
5016 * * .x = itemSpacing.cx - width
5017 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
5020 * * Experiment shows that native control returns:
5021 * * width = iconSize.cx + 16
5022 * * .left = position.x - (width - iconsize.cx)/2
5023 * * .right = .left + width
5024 * * height = iconSize.cy + 4
5025 * * .top = position.y - 2
5026 * * .bottom = .top + height
5027 * * separation between items .y = itemSpacing.cy - height
5028 * * .x = itemSpacing.cx - width
5029 * LVIR_LABEL Returns the bounding rectangle of the item text.
5032 * * Experiment shows that native control returns:
5033 * * width = text length
5034 * * .left = position.x - width/2
5035 * * .right = .left + width
5036 * * height = ntmH * linecount + 2
5037 * * .top = position.y + iconSize.cy + 6
5038 * * .bottom = .top + height
5039 * * separation between items .y = itemSpacing.cy - height
5040 * * .x = itemSpacing.cx - width
5041 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
5042 * rectangles, but excludes columns in report view.
5049 * Note that the bounding rectangle of the label in the LVS_ICON view depends
5050 * upon whether the window has the focus currently and on whether the item
5051 * is the one with the focus. Ensure that the control's record of which
5052 * item has the focus agrees with the items' records.
5054 static BOOL
LISTVIEW_GetItemRect(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
5056 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5057 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5058 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
5059 POINT Position
, Origin
;
5063 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
5065 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5067 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5068 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
5070 /* Be smart and try to figure out the minimum we have to do */
5071 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
5072 if (uView
== LVS_REPORT
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
5073 if (uView
== LVS_ICON
&& lprc
->left
!= LVIR_ICON
&&
5074 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
5075 oversizedBox
= TRUE
;
5077 /* get what we need from the item before hand, so we make
5078 * only one request. This can speed up things, if data
5079 * is stored on the app side */
5081 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
5082 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
5083 lvItem
.iItem
= nItem
;
5084 lvItem
.iSubItem
= 0;
5085 lvItem
.pszText
= szDispText
;
5086 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5087 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
5088 /* we got the state already up, simulate it here, to avoid a reget */
5089 if (uView
== LVS_ICON
&& (lprc
->left
!= LVIR_ICON
))
5091 lvItem
.mask
|= LVIF_STATE
;
5092 lvItem
.stateMask
= LVIS_FOCUSED
;
5093 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
5096 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
5097 lprc
->left
= LVIR_BOUNDS
;
5101 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
);
5105 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, lprc
);
5109 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
);
5112 case LVIR_SELECTBOUNDS
:
5113 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, &label_rect
);
5114 UnionRect(lprc
, lprc
, &label_rect
);
5118 WARN("Unknown value: %d\n", lprc
->left
);
5122 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
5124 TRACE(" rect=%s\n", debugrect(lprc
));
5131 * Retrieves the spacing between listview control items.
5134 * [I] infoPtr : valid pointer to the listview structure
5135 * [IO] lprc : rectangle to receive the output
5136 * on input, lprc->top = nSubItem
5137 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
5139 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
5140 * not only those of the first column.
5141 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
5147 static BOOL
LISTVIEW_GetSubItemRect(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
5149 POINT Position
, Origin
;
5152 if (!lprc
|| (infoPtr
->dwStyle
& LVS_TYPEMASK
) != LVS_REPORT
) return FALSE
;
5154 TRACE("(nItem=%d, nSubItem=%d)\n", nItem
, lprc
->top
);
5156 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5157 if (!LISTVIEW_GetItemPosition(infoPtr
, nItem
, &Position
)) return FALSE
;
5159 lvItem
.mask
= lprc
->top
== 0 ? LVIF_INDENT
: 0;
5160 lvItem
.iItem
= nItem
;
5161 lvItem
.iSubItem
= lprc
->top
;
5163 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
5167 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
);
5172 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
);
5176 ERR("Unknown bounds=%d\n", lprc
->left
);
5180 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
5187 * Retrieves the width of a label.
5190 * [I] infoPtr : valid pointer to the listview structure
5193 * SUCCESS : string width (in pixels)
5196 static INT
LISTVIEW_GetLabelWidth(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5198 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5201 TRACE("(nItem=%d)\n", nItem
);
5203 lvItem
.mask
= LVIF_TEXT
;
5204 lvItem
.iItem
= nItem
;
5205 lvItem
.iSubItem
= 0;
5206 lvItem
.pszText
= szDispText
;
5207 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5208 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
5210 return LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
5215 * Retrieves the spacing between listview control items.
5218 * [I] infoPtr : valid pointer to the listview structure
5219 * [I] bSmall : flag for small or large icon
5222 * Horizontal + vertical spacing
5224 static LONG
LISTVIEW_GetItemSpacing(LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
5230 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
5234 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_ICON
)
5235 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
5237 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
5244 * Retrieves the state of a listview control item.
5247 * [I] infoPtr : valid pointer to the listview structure
5248 * [I] nItem : item index
5249 * [I] uMask : state mask
5252 * State specified by the mask.
5254 static UINT
LISTVIEW_GetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
5258 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5260 lvItem
.iItem
= nItem
;
5261 lvItem
.iSubItem
= 0;
5262 lvItem
.mask
= LVIF_STATE
;
5263 lvItem
.stateMask
= uMask
;
5264 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
5266 return lvItem
.state
& uMask
;
5271 * Retrieves the text of a listview control item or subitem.
5274 * [I] hwnd : window handle
5275 * [I] nItem : item index
5276 * [IO] lpLVItem : item information
5277 * [I] isW : TRUE if lpLVItem is Unicode
5280 * SUCCESS : string length
5283 static INT
LISTVIEW_GetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
5285 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5287 lpLVItem
->mask
= LVIF_TEXT
;
5288 lpLVItem
->iItem
= nItem
;
5289 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
5291 return textlenT(lpLVItem
->pszText
, isW
);
5296 * Searches for an item based on properties + relationships.
5299 * [I] infoPtr : valid pointer to the listview structure
5300 * [I] nItem : item index
5301 * [I] uFlags : relationship flag
5304 * SUCCESS : item index
5307 static INT
LISTVIEW_GetNextItem(LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
5309 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5311 LVFINDINFOW lvFindInfo
;
5312 INT nCountPerColumn
;
5315 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
5316 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
5318 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
5320 if (uFlags
& LVNI_CUT
)
5323 if (uFlags
& LVNI_DROPHILITED
)
5324 uMask
|= LVIS_DROPHILITED
;
5326 if (uFlags
& LVNI_FOCUSED
)
5327 uMask
|= LVIS_FOCUSED
;
5329 if (uFlags
& LVNI_SELECTED
)
5330 uMask
|= LVIS_SELECTED
;
5332 /* if we're asked for the focused item, that's only one,
5333 * so it's worth optimizing */
5334 if (uFlags
& LVNI_FOCUSED
)
5336 if (!(LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) == uMask
) return -1;
5337 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
5340 if (uFlags
& LVNI_ABOVE
)
5342 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
5347 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5353 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5354 lvFindInfo
.vkDirection
= VK_UP
;
5355 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5356 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5358 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5363 else if (uFlags
& LVNI_BELOW
)
5365 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
5367 while (nItem
< infoPtr
->nItemCount
)
5370 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5376 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5377 lvFindInfo
.vkDirection
= VK_DOWN
;
5378 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5379 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5381 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5386 else if (uFlags
& LVNI_TOLEFT
)
5388 if (uView
== LVS_LIST
)
5390 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
5391 while (nItem
- nCountPerColumn
>= 0)
5393 nItem
-= nCountPerColumn
;
5394 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5398 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5400 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5401 lvFindInfo
.vkDirection
= VK_LEFT
;
5402 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5403 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5405 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5410 else if (uFlags
& LVNI_TORIGHT
)
5412 if (uView
== LVS_LIST
)
5414 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
5415 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
5417 nItem
+= nCountPerColumn
;
5418 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5422 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5424 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5425 lvFindInfo
.vkDirection
= VK_RIGHT
;
5426 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5427 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5429 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5438 /* search by index */
5439 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
5441 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
5449 /* LISTVIEW_GetNumberOfWorkAreas */
5453 * Retrieves the origin coordinates when in icon or small icon display mode.
5456 * [I] infoPtr : valid pointer to the listview structure
5457 * [O] lpptOrigin : coordinate information
5462 static void LISTVIEW_GetOrigin(LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
5464 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5465 INT nHorzPos
= 0, nVertPos
= 0;
5466 SCROLLINFO scrollInfo
;
5468 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
5469 scrollInfo
.fMask
= SIF_POS
;
5471 if ((infoPtr
->dwStyle
& WS_HSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
5472 nHorzPos
= scrollInfo
.nPos
;
5473 if ((infoPtr
->dwStyle
& WS_VSCROLL
) && GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
5474 nVertPos
= scrollInfo
.nPos
;
5476 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
5478 lpptOrigin
->x
= infoPtr
->rcList
.left
;
5479 lpptOrigin
->y
= infoPtr
->rcList
.top
;
5480 if (uView
== LVS_LIST
)
5481 nHorzPos
*= infoPtr
->nItemWidth
;
5482 else if (uView
== LVS_REPORT
)
5483 nVertPos
*= infoPtr
->nItemHeight
;
5485 lpptOrigin
->x
-= nHorzPos
;
5486 lpptOrigin
->y
-= nVertPos
;
5488 TRACE(" origin=%s\n", debugpoint(lpptOrigin
));
5493 * Retrieves the width of a string.
5496 * [I] hwnd : window handle
5497 * [I] lpszText : text string to process
5498 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
5501 * SUCCESS : string width (in pixels)
5504 static INT
LISTVIEW_GetStringWidthT(LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
5509 if (is_textT(lpszText
, isW
))
5511 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
5512 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
5513 HFONT hOldFont
= SelectObject(hdc
, hFont
);
5516 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
5518 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
5519 SelectObject(hdc
, hOldFont
);
5520 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
5522 return stringSize
.cx
;
5527 * Determines which listview item is located at the specified position.
5530 * [I] infoPtr : valid pointer to the listview structure
5531 * [IO] lpht : hit test information
5532 * [I] subitem : fill out iSubItem.
5533 * [I] select : return the index only if the hit selects the item
5536 * (mm 20001022): We must not allow iSubItem to be touched, for
5537 * an app might pass only a structure with space up to iItem!
5538 * (MS Office 97 does that for instance in the file open dialog)
5541 * SUCCESS : item index
5544 static INT
LISTVIEW_HitTest(LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
5546 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5547 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5548 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
5549 POINT Origin
, Position
, opt
;
5553 TRACE("(pt=%s, subitem=%d, select=%d)\n", debugpoint(&lpht
->pt
), subitem
, select
);
5557 if (subitem
) lpht
->iSubItem
= 0;
5559 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
5560 lpht
->flags
|= LVHT_TOLEFT
;
5561 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
5562 lpht
->flags
|= LVHT_TORIGHT
;
5564 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
5565 lpht
->flags
|= LVHT_ABOVE
;
5566 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
5567 lpht
->flags
|= LVHT_BELOW
;
5569 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
5570 if (lpht
->flags
) return -1;
5572 lpht
->flags
|= LVHT_NOWHERE
;
5574 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5576 /* first deal with the large items */
5577 rcSearch
.left
= lpht
->pt
.x
;
5578 rcSearch
.top
= lpht
->pt
.y
;
5579 rcSearch
.right
= rcSearch
.left
+ 1;
5580 rcSearch
.bottom
= rcSearch
.top
+ 1;
5582 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
5583 iterator_next(&i
); /* go to first item in the sequence */
5584 lpht
->iItem
= i
.nItem
;
5585 iterator_destroy(&i
);
5587 TRACE("lpht->iItem=%d\n", lpht
->iItem
);
5588 if (lpht
->iItem
== -1) return -1;
5590 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
5591 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
5592 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
5593 if (uView
== LVS_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
5594 lvItem
.iItem
= lpht
->iItem
;
5595 lvItem
.iSubItem
= 0;
5596 lvItem
.pszText
= szDispText
;
5597 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5598 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
5599 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
5601 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcState
, &rcIcon
, &rcLabel
);
5602 LISTVIEW_GetItemOrigin(infoPtr
, lpht
->iItem
, &Position
);
5603 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
5604 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
5606 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
5609 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
5610 TRACE("rcBounds=%s\n", debugrect(&rcBounds
));
5611 if (!PtInRect(&rcBounds
, opt
)) return -1;
5613 if (PtInRect(&rcIcon
, opt
))
5614 lpht
->flags
|= LVHT_ONITEMICON
;
5615 else if (PtInRect(&rcLabel
, opt
))
5616 lpht
->flags
|= LVHT_ONITEMLABEL
;
5617 else if (infoPtr
->himlState
&& ((lvItem
.state
& LVIS_STATEIMAGEMASK
) >> 12) && PtInRect(&rcState
, opt
))
5618 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
5619 if (lpht
->flags
& LVHT_ONITEM
)
5620 lpht
->flags
&= ~LVHT_NOWHERE
;
5622 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
5623 if (uView
== LVS_REPORT
&& lpht
->iItem
!= -1 && subitem
)
5627 rcBounds
.right
= rcBounds
.left
;
5628 for (j
= 0; j
< infoPtr
->hdpaColumns
->nItemCount
; j
++)
5630 rcBounds
.left
= rcBounds
.right
;
5631 rcBounds
.right
+= LISTVIEW_GetColumnWidth(infoPtr
, j
);
5632 if (PtInRect(&rcBounds
, opt
))
5640 if (!select
|| lpht
->iItem
== -1) return lpht
->iItem
;
5642 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)) return lpht
->iItem
;
5644 if (uView
== LVS_REPORT
) UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
5645 return PtInRect(&rcBounds
, opt
) ? lpht
->iItem
: -1;
5649 /* LISTVIEW_InsertCompare: callback routine for comparing pszText members of the LV_ITEMS
5650 in a LISTVIEW on insert. Passed to DPA_Sort in LISTVIEW_InsertItem.
5651 This function should only be used for inserting items into a sorted list (LVM_INSERTITEM)
5652 and not during the processing of a LVM_SORTITEMS message. Applications should provide
5653 their own sort proc. when sending LVM_SORTITEMS.
5656 (remarks on LVITEM: LVM_INSERTITEM will insert the new item in the proper sort postion...
5658 LVS_SORTXXX must be specified,
5659 LVS_OWNERDRAW is not set,
5660 <item>.pszText is not LPSTR_TEXTCALLBACK.
5662 (LVS_SORT* flags): "For the LVS_SORTASCENDING... styles, item indices
5663 are sorted based on item text..."
5665 static INT WINAPI
LISTVIEW_InsertCompare( LPVOID first
, LPVOID second
, LPARAM lParam
)
5667 ITEM_INFO
* lv_first
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)first
, 0 );
5668 ITEM_INFO
* lv_second
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)second
, 0 );
5669 INT cmpv
= textcmpWT(lv_first
->hdr
.pszText
, lv_second
->hdr
.pszText
, TRUE
);
5671 /* if we're sorting descending, negate the return value */
5672 return (((LISTVIEW_INFO
*)lParam
)->dwStyle
& LVS_SORTDESCENDING
) ? -cmpv
: cmpv
;
5677 * Inserts a new item in the listview control.
5680 * [I] infoPtr : valid pointer to the listview structure
5681 * [I] lpLVItem : item information
5682 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
5685 * SUCCESS : new item index
5688 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
5690 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5695 BOOL is_sorted
, has_changed
;
5698 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
5700 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
5702 /* make sure it's an item, and not a subitem; cannot insert a subitem */
5703 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iSubItem
) return -1;
5705 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
5707 if ( !(lpItem
= (ITEM_INFO
*)COMCTL32_Alloc(sizeof(ITEM_INFO
))) )
5710 /* insert item in listview control data structure */
5711 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
5712 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
5714 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
5715 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
5717 nItem
= is_sorted
? infoPtr
->nItemCount
: min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
5718 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
5719 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
5720 if (nItem
== -1) goto fail
;
5721 infoPtr
->nItemCount
++;
5723 /* set the item attributes */
5726 item
.state
&= ~LVIS_STATEIMAGEMASK
;
5727 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
5729 /* if we're sorted, sort the list, and update the index */
5732 DPA_Sort( infoPtr
->hdpaItems
, LISTVIEW_InsertCompare
, (LPARAM
)infoPtr
);
5733 nItem
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, hdpaSubItems
);
5734 assert(nItem
!= -1);
5737 /* make room for the position, if we are in the right mode */
5738 if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5740 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
5742 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
5744 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5749 /* Add the subitem list to the items array. Do this last in case we go to
5750 * fail during the above.
5752 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
5754 /* send LVN_INSERTITEM notification */
5755 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
5757 nmlv
.lParam
= lpItem
->lParam
;
5758 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
5760 /* align items (set position of each item) */
5761 if ((uView
== LVS_SMALLICON
|| uView
== LVS_ICON
))
5765 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
5766 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
5768 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
5770 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
5773 /* now is the invalidation fun */
5774 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
5778 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5779 infoPtr
->nItemCount
--;
5781 DPA_DeletePtr(hdpaSubItems
, 0);
5782 DPA_Destroy (hdpaSubItems
);
5783 COMCTL32_Free (lpItem
);
5789 * Redraws a range of items.
5792 * [I] infoPtr : valid pointer to the listview structure
5793 * [I] nFirst : first item
5794 * [I] nLast : last item
5800 static BOOL
LISTVIEW_RedrawItems(LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
5804 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
5805 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
5808 for (i
= nFirst
; i
<= nLast
; i
++)
5809 LISTVIEW_InvalidateItem(infoPtr
, i
);
5816 * Scroll the content of a listview.
5819 * [I] infoPtr : valid pointer to the listview structure
5820 * [I] dx : horizontal scroll amount in pixels
5821 * [I] dy : vertical scroll amount in pixels
5828 * If the control is in report mode (LVS_REPORT) the control can
5829 * be scrolled only in line increments. "dy" will be rounded to the
5830 * nearest number of pixels that are a whole line. Ex: if line height
5831 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
5832 * is passed the the scroll will be 0. (per MSDN 7/2002)
5834 * For: (per experimentaion with native control and CSpy ListView)
5835 * LVS_ICON dy=1 = 1 pixel (vertical only)
5837 * LVS_SMALLICON dy=1 = 1 pixel (vertical only)
5839 * LVS_LIST dx=1 = 1 column (horizontal only)
5840 * but will only scroll 1 column per message
5841 * no matter what the value.
5842 * dy must be 0 or FALSE returned.
5843 * LVS_REPORT dx=1 = 1 pixel
5847 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
5849 switch(infoPtr
->dwStyle
& LVS_TYPEMASK
) {
5851 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
5852 dy
/= infoPtr
->nItemHeight
;
5855 if (dy
!= 0) return FALSE
;
5862 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
, 0);
5863 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
, 0);
5870 * Sets the background color.
5873 * [I] infoPtr : valid pointer to the listview structure
5874 * [I] clrBk : background color
5880 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrBk
)
5882 TRACE("(clrBk=%lx)\n", clrBk
);
5884 if(infoPtr
->clrBk
!= clrBk
) {
5885 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
5886 infoPtr
->clrBk
= clrBk
;
5887 if (clrBk
== CLR_NONE
)
5888 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongW(infoPtr
->hwndSelf
, GCL_HBRBACKGROUND
);
5890 infoPtr
->hBkBrush
= CreateSolidBrush(clrBk
);
5891 LISTVIEW_InvalidateList(infoPtr
);
5897 /* LISTVIEW_SetBkImage */
5899 /*** Helper for {Insert,Set}ColumnT *only* */
5900 static void column_fill_hditem(LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
5902 if (lpColumn
->mask
& LVCF_FMT
)
5904 /* format member is valid */
5905 lphdi
->mask
|= HDI_FORMAT
;
5907 /* set text alignment (leftmost column must be left-aligned) */
5908 if (nColumn
== 0 || lpColumn
->fmt
& LVCFMT_LEFT
)
5909 lphdi
->fmt
|= HDF_LEFT
;
5910 else if (lpColumn
->fmt
& LVCFMT_RIGHT
)
5911 lphdi
->fmt
|= HDF_RIGHT
;
5912 else if (lpColumn
->fmt
& LVCFMT_CENTER
)
5913 lphdi
->fmt
|= HDF_CENTER
;
5915 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
5916 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
5918 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
5920 lphdi
->fmt
|= HDF_IMAGE
;
5921 lphdi
->iImage
= I_IMAGECALLBACK
;
5925 if (lpColumn
->mask
& LVCF_WIDTH
)
5927 lphdi
->mask
|= HDI_WIDTH
;
5928 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
5930 /* make it fill the remainder of the controls width */
5934 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
5936 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
5937 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
5940 /* retrieve the layout of the header */
5941 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
5942 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, debugrect(&rcHeader
));
5944 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
5947 lphdi
->cxy
= lpColumn
->cx
;
5950 if (lpColumn
->mask
& LVCF_TEXT
)
5952 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
5953 lphdi
->fmt
|= HDF_STRING
;
5954 lphdi
->pszText
= lpColumn
->pszText
;
5955 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
5958 if (lpColumn
->mask
& LVCF_IMAGE
)
5960 lphdi
->mask
|= HDI_IMAGE
;
5961 lphdi
->iImage
= lpColumn
->iImage
;
5964 if (lpColumn
->mask
& LVCF_ORDER
)
5966 lphdi
->mask
|= HDI_ORDER
;
5967 lphdi
->iOrder
= lpColumn
->iOrder
;
5974 * Inserts a new column.
5977 * [I] infoPtr : valid pointer to the listview structure
5978 * [I] nColumn : column index
5979 * [I] lpColumn : column information
5980 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
5983 * SUCCESS : new column index
5986 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
5987 LPLVCOLUMNW lpColumn
, BOOL isW
)
5989 COLUMN_INFO
*lpColumnInfo
;
5993 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
5995 if (!lpColumn
|| nColumn
< 0 || nColumn
> infoPtr
->hdpaColumns
->nItemCount
) return -1;
5997 ZeroMemory(&hdi
, sizeof(HDITEMW
));
5998 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
6000 /* insert item in header control */
6001 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
6002 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
6003 (WPARAM
)nColumn
, (LPARAM
)&hdi
);
6004 if (nNewColumn
== -1) return -1;
6005 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
6007 /* create our own column info */
6008 if (!(lpColumnInfo
= COMCTL32_Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
6009 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
6011 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
6012 if (!Header_GetItemRect(infoPtr
->hwndHeader
, nNewColumn
, &lpColumnInfo
->rcHeader
)) goto fail
;
6014 /* now we have to actually adjust the data */
6015 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
6017 SUBITEM_INFO
*lpSubItem
, *lpMainItem
, **lpNewItems
= 0;
6021 /* preallocate memory, so we can fail gracefully */
6022 if (nNewColumn
== 0)
6024 lpNewItems
= COMCTL32_Alloc(sizeof(SUBITEM_INFO
*) * infoPtr
->nItemCount
);
6025 if (!lpNewItems
) goto fail
;
6026 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
6027 if (!(lpNewItems
[i
] = COMCTL32_Alloc(sizeof(SUBITEM_INFO
)))) break;
6028 if (i
!= infoPtr
->nItemCount
)
6030 for(; i
>=0; i
--) COMCTL32_Free(lpNewItems
[i
]);
6031 COMCTL32_Free(lpNewItems
);
6036 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
6038 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
6039 for (i
= 1; i
< hdpaSubItems
->nItemCount
; i
++)
6041 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
6042 if (lpSubItem
->iSubItem
>= nNewColumn
)
6043 lpSubItem
->iSubItem
++;
6046 /* for inserting column 0, we have to special-case the main item */
6047 if (nNewColumn
== 0)
6049 lpMainItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
6050 lpSubItem
= lpNewItems
[nItem
];
6051 lpSubItem
->hdr
= lpMainItem
->hdr
;
6052 lpSubItem
->iSubItem
= 1;
6053 ZeroMemory(&lpMainItem
->hdr
, sizeof(lpMainItem
->hdr
));
6054 lpMainItem
->iSubItem
= 0;
6055 DPA_InsertPtr(hdpaSubItems
, 1, lpSubItem
);
6059 COMCTL32_Free(lpNewItems
);
6062 /* make space for the new column */
6063 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
6068 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
6071 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
6072 COMCTL32_Free(lpColumnInfo
);
6079 * Sets the attributes of a header item.
6082 * [I] infoPtr : valid pointer to the listview structure
6083 * [I] nColumn : column index
6084 * [I] lpColumn : column attributes
6085 * [I] isW: if TRUE, the lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
6091 static BOOL
LISTVIEW_SetColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
6092 LPLVCOLUMNW lpColumn
, BOOL isW
)
6094 HDITEMW hdi
, hdiget
;
6097 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
6099 if (!lpColumn
|| nColumn
< 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
6101 ZeroMemory(&hdi
, sizeof(HDITEMW
));
6102 if (lpColumn
->mask
& LVCF_FMT
)
6104 hdi
.mask
|= HDI_FORMAT
;
6105 hdiget
.mask
= HDI_FORMAT
;
6106 if (Header_GetItemW(infoPtr
->hwndHeader
, nColumn
, &hdiget
))
6107 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
6109 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
6111 /* set header item attributes */
6112 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, (WPARAM
)nColumn
, (LPARAM
)&hdi
);
6113 if (!bResult
) return FALSE
;
6115 if (lpColumn
->mask
& LVCF_FMT
)
6117 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6118 int oldFmt
= lpColumnInfo
->fmt
;
6120 lpColumnInfo
->fmt
= lpColumn
->fmt
;
6121 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
6123 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6124 if (uView
== LVS_REPORT
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
6133 * Sets the column order array
6136 * [I] infoPtr : valid pointer to the listview structure
6137 * [I] iCount : number of elements in column order array
6138 * [I] lpiArray : pointer to column order array
6144 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6146 FIXME("iCount %d lpiArray %p\n", iCount
, lpiArray
);
6157 * Sets the width of a column
6160 * [I] infoPtr : valid pointer to the listview structure
6161 * [I] nColumn : column index
6162 * [I] cx : column width
6168 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
6170 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6171 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
6175 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
6177 /* set column width only if in report or list mode */
6178 if (uView
!= LVS_REPORT
&& uView
!= LVS_LIST
) return FALSE
;
6180 /* take care of invalid cx values */
6181 if(uView
== LVS_REPORT
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
6182 else if (uView
== LVS_LIST
&& cx
< 1) return FALSE
;
6184 /* resize all columns if in LVS_LIST mode */
6185 if(uView
== LVS_LIST
)
6187 infoPtr
->nItemWidth
= cx
;
6188 LISTVIEW_InvalidateList(infoPtr
);
6192 if (nColumn
< 0 || nColumn
>= infoPtr
->hdpaColumns
->nItemCount
) return FALSE
;
6194 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< infoPtr
->hdpaColumns
->nItemCount
-1))
6199 lvItem
.mask
= LVIF_TEXT
;
6201 lvItem
.iSubItem
= nColumn
;
6202 lvItem
.pszText
= szDispText
;
6203 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6204 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
6206 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6207 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
6208 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
6210 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
6211 max_cx
+= infoPtr
->iconSize
.cx
+ IMAGE_PADDING
;
6212 max_cx
+= REPORT_MARGINX
+ TRAILING_PADDING
;
6215 /* autosize based on listview items width */
6216 if(cx
== LVSCW_AUTOSIZE
)
6218 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
6220 /* if iCol is the last column make it fill the remainder of the controls width */
6221 if(nColumn
== infoPtr
->hdpaColumns
->nItemCount
- 1)
6226 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6227 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
6229 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
6233 /* Despite what the MS docs say, if this is not the last
6234 column, then MS resizes the column to the width of the
6235 largest text string in the column, including headers
6236 and items. This is different from LVSCW_AUTOSIZE in that
6237 LVSCW_AUTOSIZE ignores the header string length. */
6240 /* retrieve header text */
6241 hdi
.mask
= HDI_TEXT
;
6242 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
6243 hdi
.pszText
= szDispText
;
6244 if (Header_GetItemW(infoPtr
->hwndHeader
, nColumn
, (LPARAM
)&hdi
))
6246 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
6247 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
6250 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
6252 /* FIXME: Take into account the header image, if one is present */
6253 SelectObject(hdc
, old_font
);
6254 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6256 cx
= max (cx
, max_cx
);
6260 if (cx
< 0) return FALSE
;
6262 /* call header to update the column change */
6263 hdi
.mask
= HDI_WIDTH
;
6265 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
6266 return Header_SetItemW(infoPtr
->hwndHeader
, nColumn
, (LPARAM
)&hdi
);
6271 * Sets the extended listview style.
6274 * [I] infoPtr : valid pointer to the listview structure
6276 * [I] dwStyle : style
6279 * SUCCESS : previous style
6282 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD dwMask
, DWORD dwStyle
)
6284 DWORD dwOldStyle
= infoPtr
->dwLvExStyle
;
6288 infoPtr
->dwLvExStyle
= (dwOldStyle
& ~dwMask
) | (dwStyle
& dwMask
);
6290 infoPtr
->dwLvExStyle
= dwStyle
;
6297 * Sets the new hot cursor used during hot tracking and hover selection.
6300 * [I] infoPtr : valid pointer to the listview structure
6301 * [I} hCurosr : the new hot cursor handle
6304 * Returns the previous hot cursor
6306 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
6308 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
6310 infoPtr
->hHotCursor
= hCursor
;
6318 * Sets the hot item index.
6321 * [I] infoPtr : valid pointer to the listview structure
6322 * [I] iIndex : index
6325 * SUCCESS : previous hot item index
6326 * FAILURE : -1 (no hot item)
6328 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
6330 INT iOldIndex
= infoPtr
->nHotItem
;
6332 infoPtr
->nHotItem
= iIndex
;
6340 * Sets the amount of time the cursor must hover over an item before it is selected.
6343 * [I] infoPtr : valid pointer to the listview structure
6344 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
6347 * Returns the previous hover time
6349 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
6351 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
6353 infoPtr
->dwHoverTime
= dwHoverTime
;
6355 return oldHoverTime
;
6360 * Sets spacing for icons of LVS_ICON style.
6363 * [I] infoPtr : valid pointer to the listview structure
6364 * [I] spacing : MAKELONG(cx, cy)
6367 * MAKELONG(oldcx, oldcy)
6369 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, DWORD spacing
)
6371 INT cy
= HIWORD(spacing
), cx
= LOWORD(spacing
);
6372 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
6373 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6375 TRACE("requested=(%d,%d)\n", cx
, cy
);
6377 /* this is supported only for LVS_ICON style */
6378 if (uView
!= LVS_ICON
) return oldspacing
;
6380 /* set to defaults, if instructed to */
6381 if (cx
== -1) cx
= GetSystemMetrics(SM_CXICONSPACING
);
6382 if (cy
== -1) cy
= GetSystemMetrics(SM_CYICONSPACING
);
6384 /* if 0 then compute width
6385 * FIXME: Should scan each item and determine max width of
6386 * icon or label, then make that the width */
6388 cx
= infoPtr
->iconSpacing
.cx
;
6390 /* if 0 then compute height */
6392 cy
= infoPtr
->iconSize
.cy
+ 2 * infoPtr
->ntmHeight
+
6393 ICON_BOTTOM_PADDING
+ ICON_TOP_PADDING
+ LABEL_VERT_PADDING
;
6396 infoPtr
->iconSpacing
.cx
= cx
;
6397 infoPtr
->iconSpacing
.cy
= cy
;
6399 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%ld,%ld), ntmH=%d\n",
6400 LOWORD(oldspacing
), HIWORD(oldspacing
), cx
, cy
,
6401 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
6402 infoPtr
->ntmHeight
);
6404 /* these depend on the iconSpacing */
6405 infoPtr
->nItemWidth
= LISTVIEW_CalculateMaxWidth(infoPtr
);
6406 infoPtr
->nItemHeight
= LISTVIEW_CalculateMaxHeight(infoPtr
);
6411 inline void update_icon_size(HIMAGELIST himl
, BOOL small
, SIZE
*size
)
6415 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
6422 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
6423 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
6432 * [I] infoPtr : valid pointer to the listview structure
6433 * [I] nType : image list type
6434 * [I] himl : image list handle
6437 * SUCCESS : old image list
6440 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
6442 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6443 INT oldHeight
= infoPtr
->nItemHeight
;
6444 HIMAGELIST himlOld
= 0;
6449 himlOld
= infoPtr
->himlNormal
;
6450 infoPtr
->himlNormal
= himl
;
6451 if (uView
== LVS_ICON
) update_icon_size(himl
, FALSE
, &infoPtr
->iconSize
);
6452 LISTVIEW_SetIconSpacing(infoPtr
, 0);
6456 himlOld
= infoPtr
->himlSmall
;
6457 infoPtr
->himlSmall
= himl
;
6458 if (uView
!= LVS_ICON
) update_icon_size(himl
, TRUE
, &infoPtr
->iconSize
);
6462 himlOld
= infoPtr
->himlState
;
6463 infoPtr
->himlState
= himl
;
6464 update_icon_size(himl
, TRUE
, &infoPtr
->iconStateSize
);
6465 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
6469 ERR("Unknown icon type=%d\n", nType
);
6473 infoPtr
->nItemHeight
= LISTVIEW_CalculateMaxHeight(infoPtr
);
6474 if (infoPtr
->nItemHeight
!= oldHeight
)
6475 LISTVIEW_UpdateScroll(infoPtr
);
6482 * Preallocates memory (does *not* set the actual count of items !)
6485 * [I] infoPtr : valid pointer to the listview structure
6486 * [I] nItems : item count (projected number of items to allocate)
6487 * [I] dwFlags : update flags
6493 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
6495 TRACE("(nItems=%d, dwFlags=%lx)\n", nItems
, dwFlags
);
6497 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6499 int precount
,topvisible
;
6501 TRACE("LVS_OWNERDATA is set!\n");
6502 if (dwFlags
& (LVSICF_NOINVALIDATEALL
| LVSICF_NOSCROLL
))
6503 FIXME("flags %s %s not implemented\n",
6504 (dwFlags
& LVSICF_NOINVALIDATEALL
) ? "LVSICF_NOINVALIDATEALL"
6506 (dwFlags
& LVSICF_NOSCROLL
) ? "LVSICF_NOSCROLL" : "");
6508 LISTVIEW_DeselectAll(infoPtr
);
6510 precount
= infoPtr
->nItemCount
;
6511 topvisible
= LISTVIEW_GetTopIndex(infoPtr
) +
6512 LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
6514 infoPtr
->nItemCount
= nItems
;
6515 infoPtr
->nItemWidth
= max(LISTVIEW_CalculateMaxWidth(infoPtr
),
6516 DEFAULT_COLUMN_WIDTH
);
6518 LISTVIEW_UpdateSize(infoPtr
);
6519 LISTVIEW_UpdateScroll(infoPtr
);
6521 if (min(precount
,infoPtr
->nItemCount
) < topvisible
)
6522 LISTVIEW_InvalidateList(infoPtr
); /* FIXME: optimize */
6526 /* According to MSDN for non-LVS_OWNERDATA this is just
6527 * a performance issue. The control allocates its internal
6528 * data structures for the number of items specified. It
6529 * cuts down on the number of memory allocations. Therefore
6530 * we will just issue a WARN here
6532 WARN("for non-ownerdata performance option not implemented.\n");
6540 * Sets the position of an item.
6543 * [I] infoPtr : valid pointer to the listview structure
6544 * [I] nItem : item index
6545 * [I] pt : coordinate
6551 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, POINT pt
)
6553 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6556 TRACE("(nItem=%d, &pt=%s\n", nItem
, debugpoint(&pt
));
6558 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
6559 !(uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)) return FALSE
;
6561 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6563 /* This point value seems to be an undocumented feature.
6564 * The best guess is that it means either at the origin,
6565 * or at true beginning of the list. I will assume the origin. */
6566 if ((pt
.x
== -1) && (pt
.y
== -1))
6569 if (uView
== LVS_ICON
)
6571 pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6572 pt
.y
-= ICON_TOP_PADDING
;
6577 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, FALSE
);
6582 * Sets the state of one or many items.
6585 * [I] infoPtr : valid pointer to the listview structure
6586 * [I] nItem : item index
6587 * [I] lpLVItem : item or subitem info
6593 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
)
6595 BOOL bResult
= TRUE
;
6598 lvItem
.iItem
= nItem
;
6599 lvItem
.iSubItem
= 0;
6600 lvItem
.mask
= LVIF_STATE
;
6601 lvItem
.state
= lpLVItem
->state
;
6602 lvItem
.stateMask
= lpLVItem
->stateMask
;
6603 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
6607 /* apply to all items */
6608 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
6609 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) bResult
= FALSE
;
6612 bResult
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
6619 * Sets the text of an item or subitem.
6622 * [I] hwnd : window handle
6623 * [I] nItem : item index
6624 * [I] lpLVItem : item or subitem info
6625 * [I] isW : TRUE if input is Unicode
6631 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
6635 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
6637 lvItem
.iItem
= nItem
;
6638 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
6639 lvItem
.mask
= LVIF_TEXT
;
6640 lvItem
.pszText
= lpLVItem
->pszText
;
6641 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
6643 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
6645 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
6650 * Set item index that marks the start of a multiple selection.
6653 * [I] infoPtr : valid pointer to the listview structure
6654 * [I] nIndex : index
6657 * Index number or -1 if there is no selection mark.
6659 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
6661 INT nOldIndex
= infoPtr
->nSelectionMark
;
6663 TRACE("(nIndex=%d)\n", nIndex
);
6665 infoPtr
->nSelectionMark
= nIndex
;
6672 * Sets the text background color.
6675 * [I] infoPtr : valid pointer to the listview structure
6676 * [I] clrTextBk : text background color
6682 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrTextBk
)
6684 TRACE("(clrTextBk=%lx)\n", clrTextBk
);
6686 if (infoPtr
->clrTextBk
!= clrTextBk
)
6688 infoPtr
->clrTextBk
= clrTextBk
;
6689 LISTVIEW_InvalidateList(infoPtr
);
6697 * Sets the text foreground color.
6700 * [I] infoPtr : valid pointer to the listview structure
6701 * [I] clrText : text color
6707 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF clrText
)
6709 TRACE("(clrText=%lx)\n", clrText
);
6711 if (infoPtr
->clrText
!= clrText
)
6713 infoPtr
->clrText
= clrText
;
6714 LISTVIEW_InvalidateList(infoPtr
);
6720 /* LISTVIEW_SetToolTips */
6721 /* LISTVIEW_SetUnicodeFormat */
6722 /* LISTVIEW_SetWorkAreas */
6726 * Callback internally used by LISTVIEW_SortItems()
6729 * [I] first : pointer to first ITEM_INFO to compare
6730 * [I] second : pointer to second ITEM_INFO to compare
6731 * [I] lParam : HWND of control
6734 * if first comes before second : negative
6735 * if first comes after second : positive
6736 * if first and second are equivalent : zero
6738 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
6740 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongW((HWND
)lParam
, 0);
6741 ITEM_INFO
* lv_first
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)first
, 0 );
6742 ITEM_INFO
* lv_second
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)second
, 0 );
6744 /* Forward the call to the client defined callback */
6745 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
6750 * Sorts the listview items.
6753 * [I] infoPtr : valid pointer to the listview structure
6754 * [I] pfnCompare : application-defined value
6755 * [I] lParamSort : pointer to comparision callback
6761 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
, LPARAM lParamSort
)
6763 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6766 LPVOID selectionMarkItem
;
6770 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
6772 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
6774 if (!infoPtr
->hdpaItems
) return FALSE
;
6776 /* if there are 0 or 1 items, there is no need to sort */
6777 if (infoPtr
->nItemCount
< 2) return TRUE
;
6779 if (infoPtr
->nFocusedItem
>= 0)
6781 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
6782 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
6783 if (lpItem
) lpItem
->state
|= LVIS_FOCUSED
;
6785 /* FIXME: go thorugh selected items and mark them so in lpItem->state */
6786 /* clear the lpItem->state for non-selected ones */
6787 /* remove the selection ranges */
6789 infoPtr
->pfnCompare
= pfnCompare
;
6790 infoPtr
->lParamSort
= lParamSort
;
6791 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
->hwndSelf
);
6793 /* Adjust selections and indices so that they are the way they should
6794 * be after the sort (otherwise, the list items move around, but
6795 * whatever is at the item's previous original position will be
6798 selectionMarkItem
=(infoPtr
->nSelectionMark
>=0)?DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
):NULL
;
6799 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
6801 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, i
);
6802 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
6804 if (lpItem
->state
& LVIS_SELECTED
)
6806 item
.state
= LVIS_SELECTED
;
6807 item
.stateMask
= LVIS_SELECTED
;
6808 LISTVIEW_SetItemState(infoPtr
, i
, &item
);
6810 if (lpItem
->state
& LVIS_FOCUSED
)
6812 infoPtr
->nFocusedItem
= i
;
6813 lpItem
->state
&= ~LVIS_FOCUSED
;
6816 if (selectionMarkItem
!= NULL
)
6817 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
6818 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
6820 /* refresh the display */
6821 if (uView
!= LVS_ICON
&& uView
!= LVS_SMALLICON
)
6822 LISTVIEW_InvalidateList(infoPtr
);
6829 * Updates an items or rearranges the listview control.
6832 * [I] infoPtr : valid pointer to the listview structure
6833 * [I] nItem : item index
6839 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
6841 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6843 TRACE("(nItem=%d)\n", nItem
);
6845 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
6847 /* rearrange with default alignment style */
6848 if ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) && (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
))
6849 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
6851 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6859 * Creates the listview control.
6862 * [I] hwnd : window handle
6863 * [I] lpcs : the create parameters
6869 static LRESULT
LISTVIEW_Create(HWND hwnd
, LPCREATESTRUCTW lpcs
)
6871 LISTVIEW_INFO
*infoPtr
;
6872 UINT uView
= lpcs
->style
& LVS_TYPEMASK
;
6875 TRACE("(lpcs=%p)\n", lpcs
);
6877 /* initialize info pointer */
6878 infoPtr
= (LISTVIEW_INFO
*)COMCTL32_Alloc(sizeof(LISTVIEW_INFO
));
6879 if (!infoPtr
) return -1;
6881 SetWindowLongW(hwnd
, 0, (LONG
)infoPtr
);
6883 infoPtr
->hwndSelf
= hwnd
;
6884 infoPtr
->dwStyle
= lpcs
->style
;
6885 /* determine the type of structures to use */
6886 infoPtr
->notifyFormat
= SendMessageW(GetParent(infoPtr
->hwndSelf
), WM_NOTIFYFORMAT
,
6887 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
6889 /* initialize color information */
6890 infoPtr
->clrBk
= CLR_NONE
;
6891 infoPtr
->clrText
= comctl32_color
.clrWindowText
;
6892 infoPtr
->clrTextBk
= CLR_DEFAULT
;
6893 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
6895 /* set default values */
6896 infoPtr
->nFocusedItem
= -1;
6897 infoPtr
->nSelectionMark
= -1;
6898 infoPtr
->nHotItem
= -1;
6899 infoPtr
->bRedraw
= TRUE
;
6900 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
);
6901 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
);
6902 infoPtr
->nEditLabelItem
= -1;
6904 /* get default font (icon title) */
6905 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
6906 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
6907 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6908 LISTVIEW_SaveTextMetrics(infoPtr
);
6911 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, (LPCWSTR
)NULL
,
6912 WS_CHILD
| HDS_HORZ
| (DWORD
)((LVS_NOSORTHEADER
& lpcs
->style
)?0:HDS_BUTTONS
),
6913 0, 0, 0, 0, hwnd
, (HMENU
)0,
6914 lpcs
->hInstance
, NULL
);
6916 /* set header unicode format */
6917 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, (WPARAM
)TRUE
, (LPARAM
)NULL
);
6919 /* set header font */
6920 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, (LPARAM
)TRUE
);
6922 /* allocate memory for the selection ranges */
6923 if (!(infoPtr
->selectionRanges
= ranges_create(10))) return -1;
6925 infoPtr
->hdpaColumns
= DPA_Create(10);
6927 if (uView
== LVS_ICON
)
6929 infoPtr
->iconSize
.cx
= GetSystemMetrics(SM_CXICON
);
6930 infoPtr
->iconSize
.cy
= GetSystemMetrics(SM_CYICON
);
6932 else if (uView
== LVS_REPORT
)
6934 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
))
6936 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
6940 /* set HDS_HIDDEN flag to hide the header bar */
6941 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
,
6942 GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
) | HDS_HIDDEN
);
6946 infoPtr
->iconSize
.cx
= GetSystemMetrics(SM_CXSMICON
);
6947 infoPtr
->iconSize
.cy
= GetSystemMetrics(SM_CYSMICON
);
6951 infoPtr
->iconSize
.cx
= GetSystemMetrics(SM_CXSMICON
);
6952 infoPtr
->iconSize
.cy
= GetSystemMetrics(SM_CYSMICON
);
6955 infoPtr
->iconStateSize
.cx
= GetSystemMetrics(SM_CXSMICON
);
6956 infoPtr
->iconStateSize
.cy
= GetSystemMetrics(SM_CYSMICON
);
6958 /* allocate memory for the data structure */
6959 infoPtr
->hdpaItems
= DPA_Create(10);
6960 infoPtr
->hdpaPosX
= DPA_Create(10);
6961 infoPtr
->hdpaPosY
= DPA_Create(10);
6963 /* initialize size of items */
6964 infoPtr
->nItemWidth
= LISTVIEW_CalculateMaxWidth(infoPtr
);
6965 infoPtr
->nItemHeight
= LISTVIEW_CalculateMaxHeight(infoPtr
);
6967 /* initialize the hover time to -1(indicating the default system hover time) */
6968 infoPtr
->dwHoverTime
= -1;
6975 * Erases the background of the listview control.
6978 * [I] infoPtr : valid pointer to the listview structure
6979 * [I] hdc : device context handle
6985 static inline BOOL
LISTVIEW_EraseBkgnd(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
6989 TRACE("(hdc=%p)\n", hdc
);
6991 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
6993 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
6999 * Helper function for LISTVIEW_[HV]Scroll *only*.
7000 * Performs vertical/horizontal scrolling by a give amount.
7003 * [I] infoPtr : valid pointer to the listview structure
7004 * [I] dx : amount of horizontal scroll
7005 * [I] dy : amount of vertical scroll
7007 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7009 /* now we can scroll the list */
7010 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
7011 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
7012 /* if we have focus, adjust rect */
7013 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
7014 UpdateWindow(infoPtr
->hwndSelf
);
7019 * Performs vertical scrolling.
7022 * [I] infoPtr : valid pointer to the listview structure
7023 * [I] nScrollCode : scroll code
7024 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7025 * [I] hScrollWnd : scrollbar control window handle
7031 * SB_LINEUP/SB_LINEDOWN:
7032 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
7033 * for LVS_REPORT is 1 line
7034 * for LVS_LIST cannot occur
7037 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
7038 INT nScrollDiff
, HWND hScrollWnd
)
7040 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7041 INT nOldScrollPos
, nNewScrollPos
;
7042 SCROLLINFO scrollInfo
;
7045 TRACE("(nScrollCode=%d, nScrollDiff=%d)\n", nScrollCode
, nScrollDiff
);
7047 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
7049 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7050 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
7052 is_an_icon
= ((uView
== LVS_ICON
) || (uView
== LVS_SMALLICON
));
7054 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
7056 nOldScrollPos
= scrollInfo
.nPos
;
7057 switch (nScrollCode
)
7063 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
7067 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
7071 nScrollDiff
= -scrollInfo
.nPage
;
7075 nScrollDiff
= scrollInfo
.nPage
;
7078 case SB_THUMBPOSITION
:
7080 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
7087 /* quit right away if pos isn't changing */
7088 if (nScrollDiff
== 0) return 0;
7090 /* calculate new position, and handle overflows */
7091 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
7092 if (nScrollDiff
> 0) {
7093 if (nNewScrollPos
< nOldScrollPos
||
7094 nNewScrollPos
> scrollInfo
.nMax
)
7095 nNewScrollPos
= scrollInfo
.nMax
;
7097 if (nNewScrollPos
> nOldScrollPos
||
7098 nNewScrollPos
< scrollInfo
.nMin
)
7099 nNewScrollPos
= scrollInfo
.nMin
;
7102 /* set the new position, and reread in case it changed */
7103 scrollInfo
.fMask
= SIF_POS
;
7104 scrollInfo
.nPos
= nNewScrollPos
;
7105 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
7107 /* carry on only if it really changed */
7108 if (nNewScrollPos
== nOldScrollPos
) return 0;
7110 /* now adjust to client coordinates */
7111 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
7112 if (uView
== LVS_REPORT
) nScrollDiff
*= infoPtr
->nItemHeight
;
7114 /* and scroll the window */
7115 scroll_list(infoPtr
, 0, nScrollDiff
);
7122 * Performs horizontal scrolling.
7125 * [I] infoPtr : valid pointer to the listview structure
7126 * [I] nScrollCode : scroll code
7127 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7128 * [I] hScrollWnd : scrollbar control window handle
7134 * SB_LINELEFT/SB_LINERIGHT:
7135 * for LVS_ICON, LVS_SMALLICON 1 pixel
7136 * for LVS_REPORT is 1 pixel
7137 * for LVS_LIST is 1 column --> which is a 1 because the
7138 * scroll is based on columns not pixels
7141 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
7142 INT nScrollDiff
, HWND hScrollWnd
)
7144 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7145 INT nOldScrollPos
, nNewScrollPos
;
7146 SCROLLINFO scrollInfo
;
7148 TRACE("(nScrollCode=%d, nScrollDiff=%d)\n", nScrollCode
, nScrollDiff
);
7150 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
7152 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7153 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
7155 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
7157 nOldScrollPos
= scrollInfo
.nPos
;
7159 switch (nScrollCode
)
7173 nScrollDiff
= -scrollInfo
.nPage
;
7177 nScrollDiff
= scrollInfo
.nPage
;
7180 case SB_THUMBPOSITION
:
7182 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
7189 /* quit right away if pos isn't changing */
7190 if (nScrollDiff
== 0) return 0;
7192 /* calculate new position, and handle overflows */
7193 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
7194 if (nScrollDiff
> 0) {
7195 if (nNewScrollPos
< nOldScrollPos
||
7196 nNewScrollPos
> scrollInfo
.nMax
)
7197 nNewScrollPos
= scrollInfo
.nMax
;
7199 if (nNewScrollPos
> nOldScrollPos
||
7200 nNewScrollPos
< scrollInfo
.nMin
)
7201 nNewScrollPos
= scrollInfo
.nMin
;
7204 /* set the new position, and reread in case it changed */
7205 scrollInfo
.fMask
= SIF_POS
;
7206 scrollInfo
.nPos
= nNewScrollPos
;
7207 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
7209 /* carry on only if it really changed */
7210 if (nNewScrollPos
== nOldScrollPos
) return 0;
7212 if(uView
== LVS_REPORT
)
7213 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
7215 /* now adjust to client coordinates */
7216 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
7217 if (uView
== LVS_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
7219 /* and scroll the window */
7220 scroll_list(infoPtr
, nScrollDiff
, 0);
7225 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
7227 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7228 INT gcWheelDelta
= 0;
7229 UINT pulScrollLines
= 3;
7230 SCROLLINFO scrollInfo
;
7232 TRACE("(wheelDelta=%d)\n", wheelDelta
);
7234 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
7235 gcWheelDelta
-= wheelDelta
;
7237 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7238 scrollInfo
.fMask
= SIF_POS
;
7245 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
7246 * should be fixed in the future.
7248 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7249 LISTVIEW_VScroll(infoPtr
, SB_THUMBPOSITION
,
7250 scrollInfo
.nPos
+ (gcWheelDelta
< 0) ?
7251 LISTVIEW_SCROLL_ICON_LINE_SIZE
:
7252 -LISTVIEW_SCROLL_ICON_LINE_SIZE
, 0);
7256 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
7258 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7260 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
7261 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
7262 LISTVIEW_VScroll(infoPtr
, SB_THUMBPOSITION
, scrollInfo
.nPos
+ cLineScroll
, 0);
7268 LISTVIEW_HScroll(infoPtr
, (gcWheelDelta
< 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0, 0);
7279 * [I] infoPtr : valid pointer to the listview structure
7280 * [I] nVirtualKey : virtual key
7281 * [I] lKeyData : key data
7286 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
7288 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7290 NMLVKEYDOWN nmKeyDown
;
7292 TRACE("(nVirtualKey=%d, lKeyData=%ld)\n", nVirtualKey
, lKeyData
);
7294 /* send LVN_KEYDOWN notification */
7295 nmKeyDown
.wVKey
= nVirtualKey
;
7296 nmKeyDown
.flags
= 0;
7297 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
7299 switch (nVirtualKey
)
7302 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
7304 notify(infoPtr
, NM_RETURN
);
7305 notify(infoPtr
, LVN_ITEMACTIVATE
);
7310 if (infoPtr
->nItemCount
> 0)
7315 if (infoPtr
->nItemCount
> 0)
7316 nItem
= infoPtr
->nItemCount
- 1;
7320 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
7324 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
7328 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
7332 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
7336 if (uView
== LVS_REPORT
)
7337 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
);
7339 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
7340 * LISTVIEW_GetCountPerRow(infoPtr
);
7341 if(nItem
< 0) nItem
= 0;
7345 if (uView
== LVS_REPORT
)
7346 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
);
7348 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
7349 * LISTVIEW_GetCountPerRow(infoPtr
);
7350 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
7354 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
))
7355 LISTVIEW_KeySelection(infoPtr
, nItem
);
7365 * [I] infoPtr : valid pointer to the listview structure
7370 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
7374 /* if we did not have the focus, there's nothing to do */
7375 if (!infoPtr
->bFocus
) return 0;
7377 /* send NM_KILLFOCUS notification */
7378 notify(infoPtr
, NM_KILLFOCUS
);
7380 /* if we have a focus rectagle, get rid of it */
7381 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
7383 /* set window focus flag */
7384 infoPtr
->bFocus
= FALSE
;
7386 /* invalidate the selected items before reseting focus flag */
7387 LISTVIEW_InvalidateSelectedItems(infoPtr
);
7394 * Processes double click messages (left mouse button).
7397 * [I] infoPtr : valid pointer to the listview structure
7398 * [I] wKey : key flag
7399 * [I] pts : mouse coordinate
7404 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7406 LVHITTESTINFO htInfo
;
7408 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7410 /* send NM_RELEASEDCAPTURE notification */
7411 notify(infoPtr
, NM_RELEASEDCAPTURE
);
7413 htInfo
.pt
.x
= pts
.x
;
7414 htInfo
.pt
.y
= pts
.y
;
7416 /* send NM_DBLCLK notification */
7417 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
7418 notify_click(infoPtr
, NM_DBLCLK
, &htInfo
);
7420 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
7421 if(htInfo
.iItem
!= -1) notify(infoPtr
, LVN_ITEMACTIVATE
);
7428 * Processes mouse down messages (left mouse button).
7431 * [I] infoPtr : valid pointer to the listview structure
7432 * [I] wKey : key flag
7433 * [I] pts : mouse coordinate
7438 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7440 LVHITTESTINFO lvHitTestInfo
;
7441 static BOOL bGroupSelect
= TRUE
;
7442 POINT pt
= { pts
.x
, pts
.y
};
7445 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7447 /* send NM_RELEASEDCAPTURE notification */
7448 notify(infoPtr
, NM_RELEASEDCAPTURE
);
7450 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
7452 /* set left button down flag */
7453 infoPtr
->bLButtonDown
= TRUE
;
7455 lvHitTestInfo
.pt
.x
= pts
.x
;
7456 lvHitTestInfo
.pt
.y
= pts
.y
;
7458 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
7459 TRACE("at %s, nItem=%d\n", debugpoint(&pt
), nItem
);
7460 infoPtr
->nEditLabelItem
= -1;
7461 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
7463 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
7465 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
7466 infoPtr
->nEditLabelItem
= nItem
;
7468 LISTVIEW_SetSelection(infoPtr
, nItem
);
7472 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
7476 LISTVIEW_AddGroupSelection(infoPtr
, nItem
);
7477 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
7478 infoPtr
->nSelectionMark
= nItem
;
7484 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
7485 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
7487 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
7488 infoPtr
->nSelectionMark
= nItem
;
7491 else if (wKey
& MK_CONTROL
)
7495 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
7497 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
7498 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
7499 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
7500 infoPtr
->nSelectionMark
= nItem
;
7502 else if (wKey
& MK_SHIFT
)
7504 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
7508 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
7509 infoPtr
->nEditLabelItem
= nItem
;
7511 /* set selection (clears other pre-existing selections) */
7512 LISTVIEW_SetSelection(infoPtr
, nItem
);
7518 /* remove all selections */
7519 LISTVIEW_DeselectAll(infoPtr
);
7527 * Processes mouse up messages (left mouse button).
7530 * [I] infoPtr : valid pointer to the listview structure
7531 * [I] wKey : key flag
7532 * [I] pts : mouse coordinate
7537 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7539 LVHITTESTINFO lvHitTestInfo
;
7541 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7543 if (!infoPtr
->bLButtonDown
) return 0;
7545 lvHitTestInfo
.pt
.x
= pts
.x
;
7546 lvHitTestInfo
.pt
.y
= pts
.y
;
7548 /* send NM_CLICK notification */
7549 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
7550 notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
);
7552 /* set left button flag */
7553 infoPtr
->bLButtonDown
= FALSE
;
7555 /* if we clicked on a selected item, edit the label */
7556 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
7557 LISTVIEW_EditLabelT(infoPtr
, lvHitTestInfo
.iItem
, TRUE
);
7564 * Destroys the listview control (called after WM_DESTROY).
7567 * [I] infoPtr : valid pointer to the listview structure
7572 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
7576 /* delete all items */
7577 LISTVIEW_DeleteAllItems(infoPtr
);
7579 /* destroy data structure */
7580 DPA_Destroy(infoPtr
->hdpaItems
);
7581 if (infoPtr
->selectionRanges
) ranges_destroy(infoPtr
->selectionRanges
);
7583 /* destroy image lists */
7584 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
7586 if (infoPtr
->himlNormal
)
7587 ImageList_Destroy(infoPtr
->himlNormal
);
7588 if (infoPtr
->himlSmall
)
7589 ImageList_Destroy(infoPtr
->himlSmall
);
7590 if (infoPtr
->himlState
)
7591 ImageList_Destroy(infoPtr
->himlState
);
7594 /* destroy font, bkgnd brush */
7596 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
7597 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7599 /* free listview info pointer*/
7600 COMCTL32_Free(infoPtr
);
7602 SetWindowLongW(infoPtr
->hwndSelf
, 0, 0);
7608 * Handles notifications from header.
7611 * [I] infoPtr : valid pointer to the listview structure
7612 * [I] nCtrlId : control identifier
7613 * [I] lpnmh : notification information
7618 static LRESULT
LISTVIEW_HeaderNotification(LISTVIEW_INFO
*infoPtr
, LPNMHEADERW lpnmh
)
7620 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7622 TRACE("(lpnmh=%p)\n", lpnmh
);
7624 if (!lpnmh
|| lpnmh
->iItem
< 0 || lpnmh
->iItem
>= infoPtr
->hdpaColumns
->nItemCount
) return 0;
7626 switch (lpnmh
->hdr
.code
)
7630 case HDN_ITEMCHANGEDW
:
7631 case HDN_ITEMCHANGEDA
:
7633 COLUMN_INFO
*lpColumnInfo
;
7636 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
7640 hdi
.mask
= HDI_WIDTH
;
7641 if (!Header_GetItemW(infoPtr
->hwndHeader
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
7645 cxy
= lpnmh
->pitem
->cxy
;
7647 /* determine how much we change since the last know position */
7648 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
7649 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
7652 lpColumnInfo
->rcHeader
.right
+= dx
;
7653 LISTVIEW_ScrollColumns(infoPtr
, lpnmh
->iItem
+ 1, dx
);
7654 if (uView
== LVS_REPORT
) LISTVIEW_InvalidateColumn(infoPtr
, lpnmh
->iItem
);
7659 case HDN_ITEMCLICKW
:
7660 case HDN_ITEMCLICKA
:
7662 /* Handle sorting by Header Column */
7665 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
7667 nmlv
.iSubItem
= lpnmh
->iItem
;
7668 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
7678 * Determines the type of structure to use.
7681 * [I] infoPtr : valid pointer to the listview structureof the sender
7682 * [I] hwndFrom : listview window handle
7683 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
7688 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
7690 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
7692 if (nCommand
== NF_REQUERY
)
7693 infoPtr
->notifyFormat
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
,
7694 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
7700 * Paints/Repaints the listview control.
7703 * [I] infoPtr : valid pointer to the listview structure
7704 * [I] hdc : device context handle
7709 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
7711 TRACE("(hdc=%p)\n", hdc
);
7714 LISTVIEW_Refresh(infoPtr
, hdc
);
7719 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
7721 if (ps
.fErase
) LISTVIEW_FillBkgnd(infoPtr
, hdc
, &ps
.rcPaint
);
7722 LISTVIEW_Refresh(infoPtr
, hdc
);
7723 EndPaint(infoPtr
->hwndSelf
, &ps
);
7731 * Processes double click messages (right mouse button).
7734 * [I] infoPtr : valid pointer to the listview structure
7735 * [I] wKey : key flag
7736 * [I] pts : mouse coordinate
7741 static LRESULT
LISTVIEW_RButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7743 LVHITTESTINFO lvHitTestInfo
;
7745 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7747 /* send NM_RELEASEDCAPTURE notification */
7748 notify(infoPtr
, NM_RELEASEDCAPTURE
);
7750 /* send NM_RDBLCLK notification */
7751 lvHitTestInfo
.pt
.x
= pts
.x
;
7752 lvHitTestInfo
.pt
.y
= pts
.y
;
7753 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
7754 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
7761 * Processes mouse down messages (right mouse button).
7764 * [I] infoPtr : valid pointer to the listview structure
7765 * [I] wKey : key flag
7766 * [I] pts : mouse coordinate
7771 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7773 LVHITTESTINFO lvHitTestInfo
;
7776 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7778 /* send NM_RELEASEDCAPTURE notification */
7779 notify(infoPtr
, NM_RELEASEDCAPTURE
);
7781 /* make sure the listview control window has the focus */
7782 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
7784 /* set right button down flag */
7785 infoPtr
->bRButtonDown
= TRUE
;
7787 /* determine the index of the selected item */
7788 lvHitTestInfo
.pt
.x
= pts
.x
;
7789 lvHitTestInfo
.pt
.y
= pts
.y
;
7790 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
7792 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
7794 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
7795 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
7796 !LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
7797 LISTVIEW_SetSelection(infoPtr
, nItem
);
7801 LISTVIEW_DeselectAll(infoPtr
);
7809 * Processes mouse up messages (right mouse button).
7812 * [I] infoPtr : valid pointer to the listview structure
7813 * [I] wKey : key flag
7814 * [I] pts : mouse coordinate
7819 static LRESULT
LISTVIEW_RButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, POINTS pts
)
7821 LVHITTESTINFO lvHitTestInfo
;
7824 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, pts
.x
, pts
.y
);
7826 if (!infoPtr
->bRButtonDown
) return 0;
7828 /* set button flag */
7829 infoPtr
->bRButtonDown
= FALSE
;
7831 /* Send NM_RClICK notification */
7832 lvHitTestInfo
.pt
.x
= pts
.x
;
7833 lvHitTestInfo
.pt
.y
= pts
.y
;
7834 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
7835 notify_click(infoPtr
, NM_RCLICK
, &lvHitTestInfo
);
7837 /* Change to screen coordinate for WM_CONTEXTMENU */
7838 pt
= lvHitTestInfo
.pt
;
7839 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
7841 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
7842 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
7843 (WPARAM
)infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
7854 * [I] infoPtr : valid pointer to the listview structure
7855 * [I] hwnd : window handle of window containing the cursor
7856 * [I] nHittest : hit-test code
7857 * [I] wMouseMsg : ideintifier of the mouse message
7860 * TRUE if cursor is set
7863 static BOOL
LISTVIEW_SetCursor(LISTVIEW_INFO
*infoPtr
, HWND hwnd
, UINT nHittest
, UINT wMouseMsg
)
7865 LVHITTESTINFO lvHitTestInfo
;
7867 if(!(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)) return FALSE
;
7869 if(!infoPtr
->hHotCursor
) return FALSE
;
7871 GetCursorPos(&lvHitTestInfo
.pt
);
7872 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) return FALSE
;
7874 SetCursor(infoPtr
->hHotCursor
);
7884 * [I] infoPtr : valid pointer to the listview structure
7885 * [I] hwndLoseFocus : handle of previously focused window
7890 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
7892 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
7894 /* if we have the focus already, there's nothing to do */
7895 if (infoPtr
->bFocus
) return 0;
7897 /* send NM_SETFOCUS notification */
7898 notify(infoPtr
, NM_SETFOCUS
);
7900 /* set window focus flag */
7901 infoPtr
->bFocus
= TRUE
;
7903 /* put the focus rect back on */
7904 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
7906 /* redraw all visible selected items */
7907 LISTVIEW_InvalidateSelectedItems(infoPtr
);
7917 * [I] infoPtr : valid pointer to the listview structure
7918 * [I] fRedraw : font handle
7919 * [I] fRedraw : redraw flag
7924 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
7926 HFONT oldFont
= infoPtr
->hFont
;
7928 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
7930 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
7931 if (infoPtr
->hFont
== oldFont
) return 0;
7933 LISTVIEW_SaveTextMetrics(infoPtr
);
7935 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
7936 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
7938 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
7945 * Message handling for WM_SETREDRAW.
7946 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
7949 * [I] infoPtr : valid pointer to the listview structure
7950 * [I] bRedraw: state of redraw flag
7953 * DefWinProc return value
7955 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
7957 infoPtr
->bRedraw
= bRedraw
;
7959 RedrawWindow(infoPtr
->hwndSelf
, NULL
, 0,
7960 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
| RDW_ERASENOW
);
7966 * Resizes the listview control. This function processes WM_SIZE
7967 * messages. At this time, the width and height are not used.
7970 * [I] infoPtr : valid pointer to the listview structure
7971 * [I] Width : new width
7972 * [I] Height : new height
7977 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
7979 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7981 TRACE("(width=%d, height=%d)\n", Width
, Height
);
7983 if (!LISTVIEW_UpdateSize(infoPtr
)) return 0;
7985 if ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) && (uView
== LVS_SMALLICON
|| uView
== LVS_ICON
))
7986 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
7988 LISTVIEW_UpdateScroll(infoPtr
);
7990 LISTVIEW_InvalidateList(infoPtr
);
7997 * Sets the size information.
8000 * [I] infoPtr : valid pointer to the listview structure
8003 * Zero if no size change
8006 static BOOL
LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
8008 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
8012 GetClientRect(infoPtr
->hwndSelf
, &rcList
);
8013 CopyRect(&rcOld
,&(infoPtr
->rcList
));
8014 infoPtr
->rcList
.left
= 0;
8015 infoPtr
->rcList
.right
= max(rcList
.right
- rcList
.left
, 1);
8016 infoPtr
->rcList
.top
= 0;
8017 infoPtr
->rcList
.bottom
= max(rcList
.bottom
- rcList
.top
, 1);
8019 if (uView
== LVS_LIST
)
8021 /* Apparently the "LIST" style is supposed to have the same
8022 * number of items in a column even if there is no scroll bar.
8023 * Since if a scroll bar already exists then the bottom is already
8024 * reduced, only reduce if the scroll bar does not currently exist.
8025 * The "2" is there to mimic the native control. I think it may be
8026 * related to either padding or edges. (GLA 7/2002)
8028 if (!(infoPtr
->dwStyle
& WS_HSCROLL
))
8030 INT nHScrollHeight
= GetSystemMetrics(SM_CYHSCROLL
);
8031 if (infoPtr
->rcList
.bottom
> nHScrollHeight
)
8032 infoPtr
->rcList
.bottom
-= (nHScrollHeight
+ 2);
8036 if (infoPtr
->rcList
.bottom
> 2)
8037 infoPtr
->rcList
.bottom
-= 2;
8040 else if (uView
== LVS_REPORT
)
8047 Header_Layout(infoPtr
->hwndHeader
, &hl
);
8049 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
8051 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
8052 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
8054 return (EqualRect(&rcOld
,&(infoPtr
->rcList
)));
8059 * Processes WM_STYLECHANGED messages.
8062 * [I] infoPtr : valid pointer to the listview structure
8063 * [I] wStyleType : window style type (normal or extended)
8064 * [I] lpss : window style information
8069 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
8072 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
8073 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
8075 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
8076 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
8078 if (wStyleType
!= GWL_STYLE
) return 0;
8080 /* FIXME: if LVS_NOSORTHEADER changed, update header */
8081 /* what if LVS_OWNERDATA changed? */
8082 /* or LVS_SINGLESEL */
8083 /* or LVS_SORT{AS,DES}CENDING */
8085 infoPtr
->dwStyle
= lpss
->styleNew
;
8087 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
8088 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
8089 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
8091 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
8092 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
8093 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
8095 if (uNewView
!= uOldView
)
8097 SIZE oldIconSize
= infoPtr
->iconSize
;
8100 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8101 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8103 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
8104 SetRectEmpty(&infoPtr
->rcFocus
);
8106 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
8107 update_icon_size(himl
, uNewView
!= LVS_ICON
, &infoPtr
->iconSize
);
8109 if (uNewView
== LVS_ICON
)
8111 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
8113 TRACE("icon old size=(%ld,%ld), new size=(%ld,%ld)\n",
8114 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
8115 LISTVIEW_SetIconSpacing(infoPtr
, 0);
8118 else if (uNewView
== LVS_REPORT
)
8123 hl
.prc
= &infoPtr
->rcList
;
8125 Header_Layout(infoPtr
->hwndHeader
, &hl
);
8126 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
8129 infoPtr
->nItemWidth
= LISTVIEW_CalculateMaxWidth(infoPtr
);
8130 infoPtr
->nItemHeight
= LISTVIEW_CalculateMaxHeight(infoPtr
);
8133 if (uNewView
== LVS_REPORT
)
8134 ShowWindow(infoPtr
->hwndHeader
, (LVS_NOCOLUMNHEADER
& lpss
->styleNew
) ? SW_HIDE
: SW_SHOWNORMAL
);
8136 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
8137 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
8138 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8140 /* update the size of the client area */
8141 LISTVIEW_UpdateSize(infoPtr
);
8143 /* add scrollbars if needed */
8144 LISTVIEW_UpdateScroll(infoPtr
);
8146 /* invalidate client area + erase background */
8147 LISTVIEW_InvalidateList(infoPtr
);
8154 * Window procedure of the listview control.
8157 static LRESULT WINAPI
8158 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
8160 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongW(hwnd
, 0);
8162 TRACE("(uMsg=%x wParam=%x lParam=%lx)\n", uMsg
, wParam
, lParam
);
8164 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
8165 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
8169 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
8174 case LVM_APPROXIMATEVIEWRECT
:
8175 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
8176 LOWORD(lParam
), HIWORD(lParam
));
8178 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
8180 /* case LVM_CANCELEDITLABEL: */
8182 /* case LVM_CREATEDRAGIMAGE: */
8184 case LVM_DELETEALLITEMS
:
8185 return LISTVIEW_DeleteAllItems(infoPtr
);
8187 case LVM_DELETECOLUMN
:
8188 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
8190 case LVM_DELETEITEM
:
8191 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
8193 case LVM_EDITLABELW
:
8194 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, TRUE
);
8196 case LVM_EDITLABELA
:
8197 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, FALSE
);
8199 /* case LVM_ENABLEGROUPVIEW: */
8201 case LVM_ENSUREVISIBLE
:
8202 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
8205 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
8208 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
8210 case LVM_GETBKCOLOR
:
8211 return infoPtr
->clrBk
;
8213 /* case LVM_GETBKIMAGE: */
8215 case LVM_GETCALLBACKMASK
:
8216 return infoPtr
->uCallbackMask
;
8218 case LVM_GETCOLUMNA
:
8219 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
8221 case LVM_GETCOLUMNW
:
8222 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
8224 case LVM_GETCOLUMNORDERARRAY
:
8225 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
8227 case LVM_GETCOLUMNWIDTH
:
8228 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
8230 case LVM_GETCOUNTPERPAGE
:
8231 return LISTVIEW_GetCountPerPage(infoPtr
);
8233 case LVM_GETEDITCONTROL
:
8234 return (LRESULT
)infoPtr
->hwndEdit
;
8236 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
8237 return infoPtr
->dwLvExStyle
;
8239 /* case LVM_GETGROUPINFO: */
8241 /* case LVM_GETGROUPMETRICS: */
8244 return (LRESULT
)infoPtr
->hwndHeader
;
8246 case LVM_GETHOTCURSOR
:
8247 return (LRESULT
)infoPtr
->hHotCursor
;
8249 case LVM_GETHOTITEM
:
8250 return infoPtr
->nHotItem
;
8252 case LVM_GETHOVERTIME
:
8253 return infoPtr
->dwHoverTime
;
8255 case LVM_GETIMAGELIST
:
8256 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
8258 /* case LVM_GETINSERTMARK: */
8260 /* case LVM_GETINSERTMARKCOLOR: */
8262 /* case LVM_GETINSERTMARKRECT: */
8264 case LVM_GETISEARCHSTRINGA
:
8265 case LVM_GETISEARCHSTRINGW
:
8266 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
8270 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
8273 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
8275 case LVM_GETITEMCOUNT
:
8276 return infoPtr
->nItemCount
;
8278 case LVM_GETITEMPOSITION
:
8279 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
8281 case LVM_GETITEMRECT
:
8282 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
8284 case LVM_GETITEMSPACING
:
8285 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
8287 case LVM_GETITEMSTATE
:
8288 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
8290 case LVM_GETITEMTEXTA
:
8291 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
8293 case LVM_GETITEMTEXTW
:
8294 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
8296 case LVM_GETNEXTITEM
:
8297 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
8299 case LVM_GETNUMBEROFWORKAREAS
:
8300 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
8304 if (!lParam
) return FALSE
;
8305 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
8308 /* case LVM_GETOUTLINECOLOR: */
8310 /* case LVM_GETSELECTEDCOLUMN: */
8312 case LVM_GETSELECTEDCOUNT
:
8313 return LISTVIEW_GetSelectedCount(infoPtr
);
8315 case LVM_GETSELECTIONMARK
:
8316 return infoPtr
->nSelectionMark
;
8318 case LVM_GETSTRINGWIDTHA
:
8319 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, FALSE
);
8321 case LVM_GETSTRINGWIDTHW
:
8322 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, TRUE
);
8324 case LVM_GETSUBITEMRECT
:
8325 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
8327 case LVM_GETTEXTBKCOLOR
:
8328 return infoPtr
->clrTextBk
;
8330 case LVM_GETTEXTCOLOR
:
8331 return infoPtr
->clrText
;
8333 /* case LVM_GETTILEINFO: */
8335 /* case LVM_GETTILEVIEWINFO: */
8337 case LVM_GETTOOLTIPS
:
8338 FIXME("LVM_GETTOOLTIPS: unimplemented\n");
8341 case LVM_GETTOPINDEX
:
8342 return LISTVIEW_GetTopIndex(infoPtr
);
8344 /*case LVM_GETUNICODEFORMAT:
8345 FIXME("LVM_GETUNICODEFORMAT: unimplemented\n");
8348 /* case LVM_GETVIEW: */
8350 case LVM_GETVIEWRECT
:
8351 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
8353 case LVM_GETWORKAREAS
:
8354 FIXME("LVM_GETWORKAREAS: unimplemented\n");
8357 /* case LVM_HASGROUP: */
8360 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, FALSE
);
8362 case LVM_INSERTCOLUMNA
:
8363 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
8365 case LVM_INSERTCOLUMNW
:
8366 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
8368 /* case LVM_INSERTGROUP: */
8370 /* case LVM_INSERTGROUPSORTED: */
8372 case LVM_INSERTITEMA
:
8373 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
8375 case LVM_INSERTITEMW
:
8376 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
8378 /* case LVM_INSERTMARKHITTEST: */
8380 /* case LVM_ISGROUPVIEWENABLED: */
8382 /* case LVM_MAPIDTOINDEX: */
8384 /* case LVM_MAPINDEXTOID: */
8386 /* case LVM_MOVEGROUP: */
8388 /* case LVM_MOVEITEMTOGROUP: */
8390 case LVM_REDRAWITEMS
:
8391 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
8393 /* case LVM_REMOVEALLGROUPS: */
8395 /* case LVM_REMOVEGROUP: */
8398 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
8400 case LVM_SETBKCOLOR
:
8401 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
8403 /* case LVM_SETBKIMAGE: */
8405 case LVM_SETCALLBACKMASK
:
8406 infoPtr
->uCallbackMask
= (UINT
)wParam
;
8409 case LVM_SETCOLUMNA
:
8410 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
8412 case LVM_SETCOLUMNW
:
8413 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
8415 case LVM_SETCOLUMNORDERARRAY
:
8416 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
8418 case LVM_SETCOLUMNWIDTH
:
8419 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, SLOWORD(lParam
));
8421 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
8422 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
8424 /* case LVM_SETGROUPINFO: */
8426 /* case LVM_SETGROUPMETRICS: */
8428 case LVM_SETHOTCURSOR
:
8429 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
8431 case LVM_SETHOTITEM
:
8432 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
8434 case LVM_SETHOVERTIME
:
8435 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)wParam
);
8437 case LVM_SETICONSPACING
:
8438 return LISTVIEW_SetIconSpacing(infoPtr
, (DWORD
)lParam
);
8440 case LVM_SETIMAGELIST
:
8441 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
8443 /* case LVM_SETINFOTIP: */
8445 /* case LVM_SETINSERTMARK: */
8447 /* case LVM_SETINSERTMARKCOLOR: */
8450 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
8453 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
8455 case LVM_SETITEMCOUNT
:
8456 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
8458 case LVM_SETITEMPOSITION
:
8460 POINT pt
= { SLOWORD(lParam
), SHIWORD(lParam
) };
8461 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, pt
);
8464 case LVM_SETITEMPOSITION32
:
8465 if (lParam
== 0) return FALSE
;
8466 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, *((POINT
*)lParam
));
8468 case LVM_SETITEMSTATE
:
8469 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
8471 case LVM_SETITEMTEXTA
:
8472 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
8474 case LVM_SETITEMTEXTW
:
8475 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
8477 /* case LVM_SETOUTLINECOLOR: */
8479 /* case LVM_SETSELECTEDCOLUMN: */
8481 case LVM_SETSELECTIONMARK
:
8482 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
8484 case LVM_SETTEXTBKCOLOR
:
8485 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
8487 case LVM_SETTEXTCOLOR
:
8488 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
8490 /* case LVM_SETTILEINFO: */
8492 /* case LVM_SETTILEVIEWINFO: */
8494 /* case LVM_SETTILEWIDTH: */
8496 /* case LVM_SETTOOLTIPS: */
8498 /* case LVM_SETUNICODEFORMAT: */
8500 /* case LVM_SETVIEW: */
8502 /* case LVM_SETWORKAREAS: */
8504 /* case LVM_SORTGROUPS: */
8507 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, (LPARAM
)wParam
);
8509 /* LVM_SORTITEMSEX: */
8511 case LVM_SUBITEMHITTEST
:
8512 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
8515 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
8518 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
8521 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
8524 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
8527 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
8530 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
8533 return (LRESULT
)infoPtr
->hFont
;
8536 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
8539 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
8542 return LISTVIEW_KillFocus(infoPtr
);
8544 case WM_LBUTTONDBLCLK
:
8545 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8547 case WM_LBUTTONDOWN
:
8548 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8551 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8554 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8557 return LISTVIEW_MouseHover(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8560 return LISTVIEW_NCDestroy(infoPtr
);
8563 if (lParam
&& ((LPNMHDR
)lParam
)->hwndFrom
== infoPtr
->hwndHeader
)
8564 return LISTVIEW_HeaderNotification(infoPtr
, (LPNMHEADERW
)lParam
);
8567 case WM_NOTIFYFORMAT
:
8568 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
8571 return LISTVIEW_Paint(infoPtr
, (HDC
)wParam
);
8573 case WM_RBUTTONDBLCLK
:
8574 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8576 case WM_RBUTTONDOWN
:
8577 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8580 return LISTVIEW_RButtonUp(infoPtr
, (WORD
)wParam
, MAKEPOINTS(lParam
));
8583 if(LISTVIEW_SetCursor(infoPtr
, (HWND
)wParam
, LOWORD(lParam
), HIWORD(lParam
)))
8588 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
8591 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
8594 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
8597 return LISTVIEW_Size(infoPtr
, (int)SLOWORD(lParam
), (int)SHIWORD(lParam
));
8599 case WM_STYLECHANGED
:
8600 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
8602 case WM_SYSCOLORCHANGE
:
8603 COMCTL32_RefreshSysColors();
8606 /* case WM_TIMER: */
8609 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
8612 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
8613 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
8614 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
8616 case WM_WINDOWPOSCHANGED
:
8617 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
)) {
8618 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
8619 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
8620 LISTVIEW_UpdateSize(infoPtr
);
8621 LISTVIEW_UpdateScroll(infoPtr
);
8623 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
8625 /* case WM_WININICHANGE: */
8628 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
8629 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
8632 /* call default window procedure */
8633 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
8641 * Registers the window class.
8649 void LISTVIEW_Register(void)
8653 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
8654 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
8655 wndClass
.lpfnWndProc
= (WNDPROC
)LISTVIEW_WindowProc
;
8656 wndClass
.cbClsExtra
= 0;
8657 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
8658 wndClass
.hCursor
= LoadCursorW(0, IDC_ARROWW
);
8659 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
8660 wndClass
.lpszClassName
= WC_LISTVIEWW
;
8661 RegisterClassW(&wndClass
);
8666 * Unregisters the window class.
8674 void LISTVIEW_Unregister(void)
8676 UnregisterClassW(WC_LISTVIEWW
, (HINSTANCE
)NULL
);
8681 * Handle any WM_COMMAND messages
8684 * [I] infoPtr : valid pointer to the listview structure
8685 * [I] wParam : the first message parameter
8686 * [I] lParam : the second message parameter
8691 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
8693 switch (HIWORD(wParam
))
8698 * Adjust the edit window size
8701 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
8702 HFONT hFont
, hOldFont
= 0;
8707 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
8708 len
= GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
8709 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
8711 /* Select font to get the right dimension of the string */
8712 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
8715 hOldFont
= SelectObject(hdc
, hFont
);
8718 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
8720 TEXTMETRICW textMetric
;
8722 /* Add Extra spacing for the next character */
8723 GetTextMetricsW(hdc
, &textMetric
);
8724 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
8732 rect
.bottom
- rect
.top
,
8733 SWP_DRAWFRAME
|SWP_NOMOVE
);
8736 SelectObject(hdc
, hOldFont
);
8738 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8744 return SendMessageW (GetParent (infoPtr
->hwndSelf
), WM_COMMAND
, wParam
, lParam
);
8753 * Subclassed edit control windproc function
8756 * [I] hwnd : the edit window handle
8757 * [I] uMsg : the message that is to be processed
8758 * [I] wParam : first message parameter
8759 * [I] lParam : second message parameter
8760 * [I] isW : TRUE if input is Unicode
8765 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
8767 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongW(GetParent(hwnd
), 0);
8768 BOOL cancel
= FALSE
;
8770 TRACE("(hwnd=%p, uMsg=%x, wParam=%x, lParam=%lx, isW=%d)\n",
8771 hwnd
, uMsg
, wParam
, lParam
, isW
);
8776 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
8783 WNDPROC editProc
= infoPtr
->EditWndProc
;
8784 infoPtr
->EditWndProc
= 0;
8785 SetWindowLongW(hwnd
, GWL_WNDPROC
, (LONG
)editProc
);
8786 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
8790 if (VK_ESCAPE
== (INT
)wParam
)
8795 else if (VK_RETURN
== (INT
)wParam
)
8799 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
8803 if (infoPtr
->hwndEdit
)
8805 LPWSTR buffer
= NULL
;
8807 infoPtr
->hwndEdit
= 0;
8810 DWORD len
= isW
? GetWindowTextLengthW(hwnd
) : GetWindowTextLengthA(hwnd
);
8814 if ( (buffer
= COMCTL32_Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))) )
8816 if (isW
) GetWindowTextW(hwnd
, buffer
, len
+1);
8817 else GetWindowTextA(hwnd
, (CHAR
*)buffer
, len
+1);
8821 LISTVIEW_EndEditLabelT(infoPtr
, buffer
, isW
);
8823 if (buffer
) COMCTL32_Free(buffer
);
8827 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
8833 * Subclassed edit control Unicode windproc function
8836 * [I] hwnd : the edit window handle
8837 * [I] uMsg : the message that is to be processed
8838 * [I] wParam : first message parameter
8839 * [I] lParam : second message parameter
8843 LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
8845 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
8850 * Subclassed edit control ANSI windproc function
8853 * [I] hwnd : the edit window handle
8854 * [I] uMsg : the message that is to be processed
8855 * [I] wParam : first message parameter
8856 * [I] lParam : second message parameter
8860 LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
8862 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
8867 * Creates a subclassed edit cotrol
8870 * [I] infoPtr : valid pointer to the listview structure
8871 * [I] text : initial text for the edit
8872 * [I] style : the window style
8873 * [I] isW : TRUE if input is Unicode
8877 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, DWORD style
,
8878 INT x
, INT y
, INT width
, INT height
, BOOL isW
)
8880 WCHAR editName
[5] = { 'E', 'd', 'i', 't', '\0' };
8885 TEXTMETRICW textMetric
;
8886 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongW(infoPtr
->hwndSelf
, GWL_HINSTANCE
);
8888 TRACE("(text=%s, ..., isW=%d)\n", debugtext_t(text
, isW
), isW
);
8890 style
|= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|WS_BORDER
;
8891 hdc
= GetDC(infoPtr
->hwndSelf
);
8893 /* Select the font to get appropriate metric dimensions */
8894 if(infoPtr
->hFont
!= 0)
8895 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
8897 /*Get String Lenght in pixels */
8898 GetTextExtentPoint32W(hdc
, text
, lstrlenW(text
), &sz
);
8900 /*Add Extra spacing for the next character */
8901 GetTextMetricsW(hdc
, &textMetric
);
8902 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
8904 if(infoPtr
->hFont
!= 0)
8905 SelectObject(hdc
, hOldFont
);
8907 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8909 hedit
= CreateWindowW(editName
, text
, style
, x
, y
, sz
.cx
, height
, infoPtr
->hwndSelf
, 0, hinst
, 0);
8911 hedit
= CreateWindowA("Edit", (LPCSTR
)text
, style
, x
, y
, sz
.cx
, height
, infoPtr
->hwndSelf
, 0, hinst
, 0);
8913 if (!hedit
) return 0;
8915 infoPtr
->EditWndProc
= (WNDPROC
)
8916 (isW
? SetWindowLongW(hedit
, GWL_WNDPROC
, (LONG
)EditLblWndProcW
) :
8917 SetWindowLongA(hedit
, GWL_WNDPROC
, (LONG
)EditLblWndProcA
) );
8919 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);