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 believe this code to be complete, as per
30 * the specification mentioned above.
31 * If you discover missing features, or bugs, please note them below.
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, we would send LVN_ODSTATECHANGED
45 * -- LVA_SNAPTOGRID not implemented
46 * -- LISTVIEW_ApproximateViewRect partially implemented
47 * -- LISTVIEW_[GS]etColumnOrderArray stubs
48 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
49 * -- LISTVIEW_SetIconSpacing is incomplete
50 * -- LISTVIEW_SortItems is broken
51 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
54 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
55 * linear in the number of items in the list, and this is
56 * unacceptable for large lists.
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
69 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
76 * -- LVS_NOSCROLL (see Q137520)
77 * -- LVS_SORTASCENDING, LVS_SORTDESCENDING
80 * -- LVS_EX_BORDERSELECT
83 * -- LVS_EX_HEADERDRAGDROP
86 * -- LVS_EX_MULTIWORKAREAS
87 * -- LVS_EX_ONECLICKACTIVATE
89 * -- LVS_EX_SIMPLESELECT
90 * -- LVS_EX_TRACKSELECT
91 * -- LVS_EX_TWOCLICKACTIVATE
92 * -- LVS_EX_UNDERLINECOLD
93 * -- LVS_EX_UNDERLINEHOT
96 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
101 * -- LVN_ODSTATECHANGED
106 * -- LVM_CANCELEDITLABEL
107 * -- LVM_ENABLEGROUPVIEW
108 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
109 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
110 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
111 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
112 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
113 * -- LVM_GETINSERTMARKRECT
114 * -- LVM_GETNUMBEROFWORKAREAS
115 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
116 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
117 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
118 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
119 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
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"
160 #include "commctrl.h"
161 #include "comctl32.h"
163 #include "wine/debug.h"
164 #include "wine/unicode.h"
166 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
168 /* make sure you set this to 0 for production use! */
169 #define DEBUG_RANGES 1
171 typedef struct tagCOLUMN_INFO
173 RECT rcHeader
; /* tracks the header's rectangle */
174 int fmt
; /* same as LVCOLUMN.fmt */
177 typedef struct tagITEMHDR
181 } ITEMHDR
, *LPITEMHDR
;
183 typedef struct tagSUBITEM_INFO
189 typedef struct tagITEM_INFO
197 typedef struct tagRANGE
203 typedef struct tagRANGES
208 typedef struct tagITERATOR
217 typedef struct tagLISTVIEW_INFO
224 COLORREF clrTextBkDefault
;
225 HIMAGELIST himlNormal
;
226 HIMAGELIST himlSmall
;
227 HIMAGELIST himlState
;
230 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
233 RANGES selectionRanges
;
238 RECT rcList
; /* This rectangle is really the window
239 * client rectangle possibly reduced by the
240 * horizontal scroll bar and/or header - see
241 * LISTVIEW_UpdateSize. This rectangle offset
242 * by the LISTVIEW_GetOrigin value is in
243 * client coordinates */
252 INT ntmHeight
; /* Some cached metrics of the font used */
253 INT ntmAveCharWidth
; /* by the listview to draw items */
254 BOOL bRedraw
; /* Turns on/off repaints & invalidations */
255 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
257 BOOL bDoChangeNotify
; /* send change notification messages? */
260 DWORD dwStyle
; /* the cached window GWL_STYLE */
261 DWORD dwLvExStyle
; /* extended listview style */
262 INT nItemCount
; /* the number of items in the list */
263 HDPA hdpaItems
; /* array ITEM_INFO pointers */
264 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
265 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
266 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
267 POINT currIconPos
; /* this is the position next icon will be placed */
268 PFNLVCOMPARE pfnCompare
;
276 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
278 DWORD lastKeyPressTimestamp
;
280 INT nSearchParamLength
;
281 WCHAR szSearchParam
[ MAX_PATH
];
288 /* How many we debug buffer to allocate */
289 #define DEBUG_BUFFERS 20
290 /* The size of a single debug bbuffer */
291 #define DEBUG_BUFFER_SIZE 256
293 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
294 #define SB_INTERNAL -1
296 /* maximum size of a label */
297 #define DISP_TEXT_SIZE 512
299 /* padding for items in list and small icon display modes */
300 #define WIDTH_PADDING 12
302 /* padding for items in list, report and small icon display modes */
303 #define HEIGHT_PADDING 1
305 /* offset of items in report display mode */
306 #define REPORT_MARGINX 2
308 /* padding for icon in large icon display mode
309 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
310 * that HITTEST will see.
311 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
312 * ICON_TOP_PADDING - sum of the two above.
313 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
314 * LABEL_HOR_PADDING - between text and sides of box
315 * LABEL_VERT_PADDING - between bottom of text and end of box
317 * ICON_LR_PADDING - additional width above icon size.
318 * ICON_LR_HALF - half of the above value
320 #define ICON_TOP_PADDING_NOTHITABLE 2
321 #define ICON_TOP_PADDING_HITABLE 2
322 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
323 #define ICON_BOTTOM_PADDING 4
324 #define LABEL_HOR_PADDING 5
325 #define LABEL_VERT_PADDING 7
326 #define ICON_LR_PADDING 16
327 #define ICON_LR_HALF (ICON_LR_PADDING/2)
329 /* default label width for items in list and small icon display modes */
330 #define DEFAULT_LABEL_WIDTH 40
332 /* default column width for items in list display mode */
333 #define DEFAULT_COLUMN_WIDTH 128
335 /* Size of "line" scroll for V & H scrolls */
336 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
338 /* Padding betwen image and label */
339 #define IMAGE_PADDING 2
341 /* Padding behind the label */
342 #define TRAILING_LABEL_PADDING 12
343 #define TRAILING_HEADER_PADDING 11
345 /* Border for the icon caption */
346 #define CAPTION_BORDER 2
348 /* Standard DrawText flags */
349 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
350 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
351 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
353 /* The time in milliseconds to reset the search in the list */
354 #define KEY_DELAY 450
356 /* Dump the LISTVIEW_INFO structure to the debug channel */
357 #define LISTVIEW_DUMP(iP) do { \
358 TRACE("hwndSelf=%p, clrBk=0x%06lx, clrText=0x%06lx, clrTextBk=0x%06lx, ItemHeight=%d, ItemWidth=%d, Style=0x%08lx\n", \
359 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
360 iP->nItemHeight, iP->nItemWidth, infoPtr->dwStyle); \
361 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08lx, Focus=%d\n", \
362 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
363 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
364 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%ld, icSz.cy=%ld, icSp.cx=%ld, icSp.cy=%ld, notifyFmt=%d\n", \
365 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
366 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
367 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, debugrect(&iP->rcList)); \
371 * forward declarations
373 static BOOL
LISTVIEW_GetItemT(LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
374 static void LISTVIEW_GetItemBox(LISTVIEW_INFO
*, INT
, LPRECT
);
375 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO
*, INT
, LPPOINT
);
376 static BOOL
LISTVIEW_GetItemPosition(LISTVIEW_INFO
*, INT
, LPPOINT
);
377 static BOOL
LISTVIEW_GetItemRect(LISTVIEW_INFO
*, INT
, LPRECT
);
378 static INT
LISTVIEW_GetLabelWidth(LISTVIEW_INFO
*, INT
);
379 static void LISTVIEW_GetOrigin(LISTVIEW_INFO
*, LPPOINT
);
380 static BOOL
LISTVIEW_GetViewRect(LISTVIEW_INFO
*, LPRECT
);
381 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*, INT
);
382 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*, const LVITEMW
*, BOOL
);
383 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*);
384 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*, INT
);
385 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
386 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*, INT
, BOOL
);
387 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
388 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*, PFNLVCOMPARE
, LPARAM
);
389 static INT
LISTVIEW_GetStringWidthT(LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
390 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
);
391 static UINT
LISTVIEW_GetItemState(LISTVIEW_INFO
*, INT
, UINT
);
392 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
393 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
394 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
395 static INT
LISTVIEW_GetTopIndex(LISTVIEW_INFO
*);
396 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
397 static HWND
CreateEditLabelT(LISTVIEW_INFO
*, LPCWSTR
, DWORD
, INT
, INT
, INT
, INT
, BOOL
);
398 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
400 /******** Text handling functions *************************************/
402 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
403 * text string. The string may be ANSI or Unicode, in which case
404 * the boolean isW tells us the type of the string.
406 * The name of the function tell what type of strings it expects:
407 * W: Unicode, T: ANSI/Unicode - function of isW
410 static inline BOOL
is_textW(LPCWSTR text
)
412 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
415 static inline BOOL
is_textT(LPCWSTR text
, BOOL isW
)
417 /* we can ignore isW since LPSTR_TEXTCALLBACKW == LPSTR_TEXTCALLBACKA */
418 return is_textW(text
);
421 static inline int textlenT(LPCWSTR text
, BOOL isW
)
423 return !is_textT(text
, isW
) ? 0 :
424 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
427 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
430 if (isSrcW
) lstrcpynW(dest
, src
, max
);
431 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
433 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
434 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
437 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
439 LPWSTR wstr
= (LPWSTR
)text
;
441 if (!isW
&& is_textT(text
, isW
))
443 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
444 wstr
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
445 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
447 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
451 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
453 if (!isW
&& is_textT(wstr
, isW
)) HeapFree(GetProcessHeap(), 0, wstr
);
457 * dest is a pointer to a Unicode string
458 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
460 static BOOL
textsetptrT(LPWSTR
*dest
, LPWSTR src
, BOOL isW
)
464 if (src
== LPSTR_TEXTCALLBACKW
)
466 if (is_textW(*dest
)) Free(*dest
);
467 *dest
= LPSTR_TEXTCALLBACKW
;
471 LPWSTR pszText
= textdupTtoW(src
, isW
);
472 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
473 bResult
= Str_SetPtrW(dest
, pszText
);
474 textfreeT(pszText
, isW
);
480 * compares a Unicode to a Unicode/ANSI text string
482 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
484 if (!aw
) return bt
? -1 : 0;
485 if (!bt
) return aw
? 1 : 0;
486 if (aw
== LPSTR_TEXTCALLBACKW
)
487 return bt
== LPSTR_TEXTCALLBACKW
? 0 : -1;
488 if (bt
!= LPSTR_TEXTCALLBACKW
)
490 LPWSTR bw
= textdupTtoW(bt
, isW
);
491 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
499 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
503 n
= min(min(n
, strlenW(s1
)), strlenW(s2
));
504 res
= CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
);
505 return res
? res
- sizeof(WCHAR
) : res
;
508 /******** Debugging functions *****************************************/
510 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
512 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
513 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
516 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
518 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
519 n
= min(textlenT(text
, isW
), n
);
520 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
523 static char* debug_getbuf()
525 static int index
= 0;
526 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
527 return buffers
[index
++ % DEBUG_BUFFERS
];
530 static inline const char* debugrange(const RANGE
*lprng
)
534 char* buf
= debug_getbuf();
535 snprintf(buf
, DEBUG_BUFFER_SIZE
, "[%d, %d)", lprng
->lower
, lprng
->upper
);
537 } else return "(null)";
540 static inline const char* debugpoint(const POINT
*lppt
)
544 char* buf
= debug_getbuf();
545 snprintf(buf
, DEBUG_BUFFER_SIZE
, "(%ld, %ld)", lppt
->x
, lppt
->y
);
547 } else return "(null)";
550 static inline const char* debugrect(const RECT
*rect
)
554 char* buf
= debug_getbuf();
555 snprintf(buf
, DEBUG_BUFFER_SIZE
, "[(%ld, %ld);(%ld, %ld)]",
556 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
558 } else return "(null)";
561 static const char * debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
563 char* buf
= debug_getbuf(), *text
= buf
;
564 int len
, size
= DEBUG_BUFFER_SIZE
;
566 if (pScrollInfo
== NULL
) return "(null)";
567 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
568 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
569 if (pScrollInfo
->fMask
& SIF_RANGE
)
570 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
572 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
573 if (pScrollInfo
->fMask
& SIF_PAGE
)
574 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
576 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
577 if (pScrollInfo
->fMask
& SIF_POS
)
578 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
580 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
581 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
582 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
584 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
587 buf
= text
+ strlen(text
);
589 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
593 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
597 char* buf
= debug_getbuf();
598 snprintf(buf
, DEBUG_BUFFER_SIZE
, "iItem=%d, iSubItem=%d, uNewState=0x%x,"
599 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld\n",
600 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
601 plvnm
->uChanged
, debugpoint(&plvnm
->ptAction
), plvnm
->lParam
);
603 } else return "(null)";
606 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
608 char* buf
= debug_getbuf(), *text
= buf
;
609 int len
, size
= DEBUG_BUFFER_SIZE
;
611 if (lpLVItem
== NULL
) return "(null)";
612 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
613 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
614 if (lpLVItem
->mask
& LVIF_STATE
)
615 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
617 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
618 if (lpLVItem
->mask
& LVIF_TEXT
)
619 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
621 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
622 if (lpLVItem
->mask
& LVIF_IMAGE
)
623 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
625 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
626 if (lpLVItem
->mask
& LVIF_PARAM
)
627 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
629 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
630 if (lpLVItem
->mask
& LVIF_INDENT
)
631 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
633 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
636 buf
= text
+ strlen(text
);
638 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
642 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
644 char* buf
= debug_getbuf(), *text
= buf
;
645 int len
, size
= DEBUG_BUFFER_SIZE
;
647 if (lpColumn
== NULL
) return "(null)";
648 len
= snprintf(buf
, size
, "{");
649 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
650 if (lpColumn
->mask
& LVCF_SUBITEM
)
651 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
653 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
654 if (lpColumn
->mask
& LVCF_FMT
)
655 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
657 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
658 if (lpColumn
->mask
& LVCF_WIDTH
)
659 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
661 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
662 if (lpColumn
->mask
& LVCF_TEXT
)
663 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
665 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
666 if (lpColumn
->mask
& LVCF_IMAGE
)
667 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
669 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
670 if (lpColumn
->mask
& LVCF_ORDER
)
671 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
673 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
676 buf
= text
+ strlen(text
);
678 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
682 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
686 char* buf
= debug_getbuf();
687 snprintf(buf
, DEBUG_BUFFER_SIZE
, "{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
688 debugpoint(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
690 } else return "(null)";
693 /* Return the corresponding text for a given scroll value */
694 static inline LPCSTR
debugscrollcode(int nScrollCode
)
698 case SB_LINELEFT
: return "SB_LINELEFT";
699 case SB_LINERIGHT
: return "SB_LINERIGHT";
700 case SB_PAGELEFT
: return "SB_PAGELEFT";
701 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
702 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
703 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
704 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
705 case SB_INTERNAL
: return "SB_INTERNAL";
706 default: return "unknown";
711 /******** Notification functions i************************************/
713 static LRESULT
notify_hdr(LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
717 TRACE("(code=%d)\n", code
);
719 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
720 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
722 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
723 (WPARAM
)pnmh
->idFrom
, (LPARAM
)pnmh
);
725 TRACE(" <= %ld\n", result
);
730 static inline LRESULT
notify(LISTVIEW_INFO
*infoPtr
, INT code
)
733 return notify_hdr(infoPtr
, code
, &nmh
);
736 static inline void notify_itemactivate(LISTVIEW_INFO
*infoPtr
, LVHITTESTINFO
*htInfo
)
747 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
748 item
.iItem
= htInfo
->iItem
;
750 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
751 nmia
.lParam
= item
.lParam
;
752 nmia
.uOldState
= item
.state
;
753 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
754 nmia
.uChanged
= LVIF_STATE
;
757 nmia
.iItem
= htInfo
->iItem
;
758 nmia
.iSubItem
= htInfo
->iSubItem
;
759 nmia
.ptAction
= htInfo
->pt
;
761 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
762 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
763 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
765 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
768 static inline LRESULT
notify_listview(LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
770 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
771 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
774 static LRESULT
notify_click(LISTVIEW_INFO
*infoPtr
, INT code
, LVHITTESTINFO
*lvht
)
779 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
780 ZeroMemory(&nmlv
, sizeof(nmlv
));
781 nmlv
.iItem
= lvht
->iItem
;
782 nmlv
.iSubItem
= lvht
->iSubItem
;
783 nmlv
.ptAction
= lvht
->pt
;
784 item
.mask
= LVIF_PARAM
;
785 item
.iItem
= lvht
->iItem
;
787 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
788 return notify_listview(infoPtr
, code
, &nmlv
);
791 static void notify_deleteitem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
796 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
798 item
.mask
= LVIF_PARAM
;
801 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
802 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
805 static int get_ansi_notification(INT unicodeNotificationCode
)
807 switch (unicodeNotificationCode
)
809 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
810 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
811 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
812 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
813 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
814 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
816 ERR("unknown notification %x\n", unicodeNotificationCode
);
822 Send notification. depends on dispinfoW having same
823 structure as dispinfoA.
824 infoPtr : listview struct
825 notificationCode : *Unicode* notification code
826 pdi : dispinfo structure (can be unicode or ansi)
827 isW : TRUE if dispinfo is Unicode
829 static BOOL
notify_dispinfoT(LISTVIEW_INFO
*infoPtr
, INT notificationCode
, LPNMLVDISPINFOW pdi
, BOOL isW
)
831 BOOL bResult
= FALSE
;
832 BOOL convertToAnsi
= FALSE
, convertToUnicode
= FALSE
;
833 INT cchTempBufMax
= 0, savCchTextMax
= 0, realNotifCode
;
834 LPWSTR pszTempBuf
= NULL
, savPszText
= NULL
;
836 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_textT(pdi
->item
.pszText
, isW
))
838 convertToAnsi
= (isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
839 convertToUnicode
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
842 if (convertToAnsi
|| convertToUnicode
)
844 if (notificationCode
!= LVN_GETDISPINFOW
)
846 cchTempBufMax
= convertToUnicode
?
847 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
848 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
852 cchTempBufMax
= pdi
->item
.cchTextMax
;
853 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
856 pszTempBuf
= HeapAlloc(GetProcessHeap(), 0,
857 (convertToUnicode
? sizeof(WCHAR
) : sizeof(CHAR
)) * cchTempBufMax
);
858 if (!pszTempBuf
) return FALSE
;
860 if (convertToUnicode
)
861 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
862 pszTempBuf
, cchTempBufMax
);
864 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) pszTempBuf
,
865 cchTempBufMax
, NULL
, NULL
);
867 savCchTextMax
= pdi
->item
.cchTextMax
;
868 savPszText
= pdi
->item
.pszText
;
869 pdi
->item
.pszText
= pszTempBuf
;
870 pdi
->item
.cchTextMax
= cchTempBufMax
;
873 if (infoPtr
->notifyFormat
== NFR_ANSI
)
874 realNotifCode
= get_ansi_notification(notificationCode
);
876 realNotifCode
= notificationCode
;
877 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
878 bResult
= notify_hdr(infoPtr
, realNotifCode
, &pdi
->hdr
);
880 if (convertToUnicode
|| convertToAnsi
)
882 if (convertToUnicode
) /* note : pointer can be changed by app ! */
883 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) savPszText
,
884 savCchTextMax
, NULL
, NULL
);
886 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
887 savPszText
, savCchTextMax
);
888 pdi
->item
.pszText
= savPszText
; /* restores our buffer */
889 pdi
->item
.cchTextMax
= savCchTextMax
;
890 HeapFree(GetProcessHeap(), 0, pszTempBuf
);
895 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, LISTVIEW_INFO
*infoPtr
, HDC hdc
,
896 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
898 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
899 lpnmlvcd
->nmcd
.hdc
= hdc
;
900 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
901 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
902 lpnmlvcd
->clrText
= infoPtr
->clrText
;
903 if (!lplvItem
) return;
904 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
905 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
906 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
907 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
908 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
909 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
912 static inline DWORD
notify_customdraw (LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
914 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
917 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
918 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
919 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
920 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
921 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
922 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
926 static void prepaint_setup (LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
)
928 /* apprently, for selected items, we have to override the returned values */
929 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
933 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
934 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
936 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
938 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
939 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
943 /* Set the text attributes */
944 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
946 SetBkMode(hdc
, OPAQUE
);
947 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
948 SetBkColor(hdc
, infoPtr
->clrTextBkDefault
);
950 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
953 SetBkMode(hdc
, TRANSPARENT
);
954 SetTextColor(hdc
, lpnmlvcd
->clrText
);
957 static inline DWORD
notify_postpaint (LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
959 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
962 /******** Item iterator functions **********************************/
964 static RANGES
ranges_create(int count
);
965 static void ranges_destroy(RANGES ranges
);
966 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
967 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
968 static void ranges_dump(RANGES ranges
);
970 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
972 RANGE range
= { nItem
, nItem
+ 1 };
974 return ranges_add(ranges
, range
);
977 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
979 RANGE range
= { nItem
, nItem
+ 1 };
981 return ranges_del(ranges
, range
);
985 * ITERATOR DOCUMENTATION
987 * The iterator functions allow for easy, and convenient iteration
988 * over items of iterest in the list. Typically, you create a
989 * iterator, use it, and destroy it, as such:
992 * iterator_xxxitems(&i, ...);
993 * while (iterator_{prev,next}(&i)
995 * //code which uses i.nItem
997 * iterator_destroy(&i);
999 * where xxx is either: framed, or visible.
1000 * Note that it is important that the code destroys the iterator
1001 * after it's done with it, as the creation of the iterator may
1002 * allocate memory, which thus needs to be freed.
1004 * You can iterate both forwards, and backwards through the list,
1005 * by using iterator_next or iterator_prev respectively.
1007 * Lower numbered items are draw on top of higher number items in
1008 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1009 * items may overlap). So, to test items, you should use
1011 * which lists the items top to bottom (in Z-order).
1012 * For drawing items, you should use
1014 * which lists the items bottom to top (in Z-order).
1015 * If you keep iterating over the items after the end-of-items
1016 * marker (-1) is returned, the iterator will start from the
1017 * beginning. Typically, you don't need to test for -1,
1018 * because iterator_{next,prev} will return TRUE if more items
1019 * are to be iterated over, or FALSE otherwise.
1021 * Note: the iterator is defined to be bidirectional. That is,
1022 * any number of prev followed by any number of next, or
1023 * five versa, should leave the iterator at the same item:
1024 * prev * n, next * n = next * n, prev * n
1026 * The iterator has a notion of a out-of-order, special item,
1027 * which sits at the start of the list. This is used in
1028 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1029 * which needs to be first, as it may overlap other items.
1031 * The code is a bit messy because we have:
1032 * - a special item to deal with
1033 * - simple range, or composite range
1035 * If you find bugs, or want to add features, please make sure you
1036 * always check/modify *both* iterator_prev, and iterator_next.
1040 * This function iterates through the items in increasing order,
1041 * but prefixed by the special item, then -1. That is:
1042 * special, 1, 2, 3, ..., n, -1.
1043 * Each item is listed only once.
1045 static inline BOOL
iterator_next(ITERATOR
* i
)
1049 i
->nItem
= i
->nSpecial
;
1050 if (i
->nItem
!= -1) return TRUE
;
1052 if (i
->nItem
== i
->nSpecial
)
1054 if (i
->ranges
) i
->index
= 0;
1060 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1061 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1066 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1067 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1070 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1072 i
->nItem
= i
->range
.lower
;
1073 if (i
->nItem
>= 0) goto testitem
;
1080 * This function iterates through the items in decreasing order,
1081 * followed by the special item, then -1. That is:
1082 * n, n-1, ..., 3, 2, 1, special, -1.
1083 * Each item is listed only once.
1085 static inline BOOL
iterator_prev(ITERATOR
* i
)
1092 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1095 if (i
->nItem
== i
->nSpecial
)
1103 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1104 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1110 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1113 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1115 i
->nItem
= i
->range
.upper
;
1116 if (i
->nItem
> 0) goto testitem
;
1118 return (i
->nItem
= i
->nSpecial
) != -1;
1121 static RANGE
iterator_range(ITERATOR
* i
)
1125 if (!i
->ranges
) return i
->range
;
1127 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1129 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1130 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1132 else range
.lower
= range
.upper
= 0;
1138 * Releases resources associated with this ierator.
1140 static inline void iterator_destroy(ITERATOR
* i
)
1142 ranges_destroy(i
->ranges
);
1146 * Create an empty iterator.
1148 static inline BOOL
iterator_empty(ITERATOR
* i
)
1150 ZeroMemory(i
, sizeof(*i
));
1151 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1156 * Create an iterator over a range.
1158 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1166 * Create an iterator over a bunch of ranges.
1167 * Please note that the iterator will take ownership of the ranges,
1168 * and will free them upon destruction.
1170 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1178 * Creates an iterator over the items which intersect lprc.
1180 static BOOL
iterator_frameditems(ITERATOR
* i
, LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1182 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1183 RECT frame
= *lprc
, rcItem
, rcTemp
;
1186 /* in case we fail, we want to return an empty iterator */
1187 if (!iterator_empty(i
)) return FALSE
;
1189 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1191 TRACE("(lprc=%s)\n", debugrect(lprc
));
1192 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1194 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)
1198 if (uView
== LVS_ICON
&& infoPtr
->nFocusedItem
!= -1)
1200 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1201 if (IntersectRect(&rcTemp
, &rcItem
, lprc
))
1202 i
->nSpecial
= infoPtr
->nFocusedItem
;
1204 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1205 /* to do better here, we need to have PosX, and PosY sorted */
1206 TRACE("building icon ranges:\n");
1207 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1209 rcItem
.left
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1210 rcItem
.top
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1211 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1212 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1213 if (IntersectRect(&rcTemp
, &rcItem
, &frame
))
1214 ranges_additem(i
->ranges
, nItem
);
1218 else if (uView
== LVS_REPORT
)
1222 if (frame
.left
>= infoPtr
->nItemWidth
) return TRUE
;
1223 if (frame
.top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1225 range
.lower
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1226 range
.upper
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1227 if (range
.upper
<= range
.lower
) return TRUE
;
1228 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1229 TRACE(" report=%s\n", debugrange(&i
->range
));
1233 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1234 INT nFirstRow
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1235 INT nLastRow
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1236 INT nFirstCol
= max(frame
.left
/ infoPtr
->nItemWidth
, 0);
1237 INT nLastCol
= min((frame
.right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1238 INT lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1242 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1243 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1245 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1247 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1248 TRACE("building list ranges:\n");
1249 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1251 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1252 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1253 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1254 TRACE(" list=%s\n", debugrange(&item_range
));
1255 ranges_add(i
->ranges
, item_range
);
1263 * Creates an iterator over the items which intersect the visible region of hdc.
1265 static BOOL
iterator_visibleitems(ITERATOR
*i
, LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1267 POINT Origin
, Position
;
1268 RECT rcItem
, rcClip
;
1271 rgntype
= GetClipBox(hdc
, &rcClip
);
1272 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1273 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1274 if (rgntype
== SIMPLEREGION
) return TRUE
;
1276 /* first deal with the special item */
1277 if (i
->nSpecial
!= -1)
1279 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1280 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1283 /* if we can't deal with the region, we'll just go with the simple range */
1284 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1285 TRACE("building visible range:\n");
1286 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1288 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1289 if (!ranges_add(i
->ranges
, i
->range
))
1291 ranges_destroy(i
->ranges
);
1297 /* now delete the invisible items from the list */
1298 while(iterator_next(i
))
1300 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1301 rcItem
.left
= Position
.x
+ Origin
.x
;
1302 rcItem
.top
= Position
.y
+ Origin
.y
;
1303 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1304 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1305 if (!RectVisible(hdc
, &rcItem
))
1306 ranges_delitem(i
->ranges
, i
->nItem
);
1308 /* the iterator should restart on the next iterator_next */
1314 /******** Misc helper functions ************************************/
1316 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1317 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1319 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1320 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1323 static inline BOOL
is_autoarrange(LISTVIEW_INFO
*infoPtr
)
1325 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1327 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1328 (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
);
1331 /******** Internal API functions ************************************/
1333 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1335 static COLUMN_INFO mainItem
;
1337 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1338 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1339 return (COLUMN_INFO
*)DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1342 static inline void LISTVIEW_GetHeaderRect(LISTVIEW_INFO
*infoPtr
, INT nSubItem
, RECT
*lprc
)
1344 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1347 static inline BOOL
LISTVIEW_GetItemW(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1349 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1352 /* Listview invalidation functions: use _only_ these functions to invalidate */
1354 static inline BOOL
is_redrawing(LISTVIEW_INFO
*infoPtr
)
1356 return infoPtr
->bRedraw
;
1359 static inline void LISTVIEW_InvalidateRect(LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1361 if(!is_redrawing(infoPtr
)) return;
1362 TRACE(" invalidating rect=%s\n", debugrect(rect
));
1363 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1366 static inline void LISTVIEW_InvalidateItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1370 if(!is_redrawing(infoPtr
)) return;
1371 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1372 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1375 static inline void LISTVIEW_InvalidateSubItem(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1377 POINT Origin
, Position
;
1380 if(!is_redrawing(infoPtr
)) return;
1381 assert ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_REPORT
);
1382 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1383 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1384 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1386 rcBox
.bottom
= infoPtr
->nItemHeight
;
1387 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1388 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1391 static inline void LISTVIEW_InvalidateList(LISTVIEW_INFO
*infoPtr
)
1393 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1396 static inline void LISTVIEW_InvalidateColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1400 if(!is_redrawing(infoPtr
)) return;
1401 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1402 rcCol
.top
= infoPtr
->rcList
.top
;
1403 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1404 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1409 * Retrieves the number of items that can fit vertically in the client area.
1412 * [I] infoPtr : valid pointer to the listview structure
1415 * Number of items per row.
1417 static inline INT
LISTVIEW_GetCountPerRow(LISTVIEW_INFO
*infoPtr
)
1419 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1421 return max(nListWidth
/infoPtr
->nItemWidth
, 1);
1426 * Retrieves the number of items that can fit horizontally in the client
1430 * [I] infoPtr : valid pointer to the listview structure
1433 * Number of items per column.
1435 static inline INT
LISTVIEW_GetCountPerColumn(LISTVIEW_INFO
*infoPtr
)
1437 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1439 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1443 /*************************************************************************
1444 * LISTVIEW_ProcessLetterKeys
1446 * Processes keyboard messages generated by pressing the letter keys
1448 * What this does is perform a case insensitive search from the
1449 * current position with the following quirks:
1450 * - If two chars or more are pressed in quick succession we search
1451 * for the corresponding string (e.g. 'abc').
1452 * - If there is a delay we wipe away the current search string and
1453 * restart with just that char.
1454 * - If the user keeps pressing the same character, whether slowly or
1455 * fast, so that the search string is entirely composed of this
1456 * character ('aaaaa' for instance), then we search for first item
1457 * that starting with that character.
1458 * - If the user types the above character in quick succession, then
1459 * we must also search for the corresponding string ('aaaaa'), and
1460 * go to that string if there is a match.
1463 * [I] hwnd : handle to the window
1464 * [I] charCode : the character code, the actual character
1465 * [I] keyData : key data
1473 * - The current implementation has a list of characters it will
1474 * accept and it ignores averything else. In particular it will
1475 * ignore accentuated characters which seems to match what
1476 * Windows does. But I'm not sure it makes sense to follow
1478 * - We don't sound a beep when the search fails.
1482 * TREEVIEW_ProcessLetterKeys
1484 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1489 WCHAR buffer
[MAX_PATH
];
1490 DWORD lastKeyPressTimestamp
= infoPtr
->lastKeyPressTimestamp
;
1492 /* simple parameter checking */
1493 if (!charCode
|| !keyData
) return 0;
1495 /* only allow the valid WM_CHARs through */
1496 if (!isalnum(charCode
) &&
1497 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1498 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1499 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1500 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1501 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1502 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1503 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1504 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1505 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1508 /* if there's one item or less, there is no where to go */
1509 if (infoPtr
->nItemCount
<= 1) return 0;
1511 /* update the search parameters */
1512 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1513 if (infoPtr
->lastKeyPressTimestamp
- lastKeyPressTimestamp
< KEY_DELAY
) {
1514 if (infoPtr
->nSearchParamLength
< MAX_PATH
)
1515 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
1516 if (infoPtr
->charCode
!= charCode
)
1517 infoPtr
->charCode
= charCode
= 0;
1519 infoPtr
->charCode
=charCode
;
1520 infoPtr
->szSearchParam
[0]=charCode
;
1521 infoPtr
->nSearchParamLength
=1;
1522 /* Redundant with the 1 char string */
1526 /* and search from the current position */
1528 if (infoPtr
->nFocusedItem
>= 0) {
1529 endidx
=infoPtr
->nFocusedItem
;
1531 /* if looking for single character match,
1532 * then we must always move forward
1534 if (infoPtr
->nSearchParamLength
== 1)
1537 endidx
=infoPtr
->nItemCount
;
1541 if (idx
== infoPtr
->nItemCount
) {
1542 if (endidx
== infoPtr
->nItemCount
|| endidx
== 0)
1548 item
.mask
= LVIF_TEXT
;
1551 item
.pszText
= buffer
;
1552 item
.cchTextMax
= MAX_PATH
;
1553 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1555 /* check for a match */
1556 if (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
1559 } else if ( (charCode
!= 0) && (nItem
== -1) && (nItem
!= infoPtr
->nFocusedItem
) &&
1560 (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
1561 /* This would work but we must keep looking for a longer match */
1565 } while (idx
!= endidx
);
1568 LISTVIEW_KeySelection(infoPtr
, nItem
);
1573 /*************************************************************************
1574 * LISTVIEW_UpdateHeaderSize [Internal]
1576 * Function to resize the header control
1579 * [I] hwnd : handle to a window
1580 * [I] nNewScrollPos : scroll pos to set
1585 static void LISTVIEW_UpdateHeaderSize(LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1590 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1592 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1593 point
[0].x
= winRect
.left
;
1594 point
[0].y
= winRect
.top
;
1595 point
[1].x
= winRect
.right
;
1596 point
[1].y
= winRect
.bottom
;
1598 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1599 point
[0].x
= -nNewScrollPos
;
1600 point
[1].x
+= nNewScrollPos
;
1602 SetWindowPos(infoPtr
->hwndHeader
,0,
1603 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1604 SWP_NOZORDER
| SWP_NOACTIVATE
);
1609 * Update the scrollbars. This functions should be called whenever
1610 * the content, size or view changes.
1613 * [I] infoPtr : valid pointer to the listview structure
1618 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*infoPtr
)
1620 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1621 SCROLLINFO horzInfo
, vertInfo
;
1623 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
1625 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
1626 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
1627 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1629 /* for now, we'll set info.nMax to the _count_, and adjust it later */
1630 if (uView
== LVS_LIST
)
1632 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
1633 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
1635 /* scroll by at least one column per page */
1636 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
1637 horzInfo
.nPage
= infoPtr
->nItemWidth
;
1639 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
1641 else if (uView
== LVS_REPORT
)
1643 horzInfo
.nMax
= infoPtr
->nItemWidth
;
1645 else /* LVS_ICON, or LVS_SMALLICON */
1649 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
1652 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1653 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
1654 SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
1655 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
1657 /* Setting the horizontal scroll can change the listview size
1658 * (and potentially everything else) so we need to recompute
1659 * everything again for the vertical scroll
1662 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
1663 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
1664 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1666 if (uView
== LVS_REPORT
)
1668 vertInfo
.nMax
= infoPtr
->nItemCount
;
1670 /* scroll by at least one page */
1671 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
1672 vertInfo
.nPage
= infoPtr
->nItemHeight
;
1674 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
1676 else if (uView
!= LVS_LIST
) /* LVS_ICON, or LVS_SMALLICON */
1680 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
1683 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1684 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
1685 SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
1686 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
1688 /* Update the Header Control */
1689 if (uView
== LVS_REPORT
)
1691 horzInfo
.fMask
= SIF_POS
;
1692 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
1693 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
1700 * Shows/hides the focus rectangle.
1703 * [I] infoPtr : valid pointer to the listview structure
1704 * [I] fShow : TRUE to show the focus, FALSE to hide it.
1709 static void LISTVIEW_ShowFocusRect(LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
1711 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1714 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
1716 if (infoPtr
->nFocusedItem
< 0) return;
1718 /* we need some gymnastics in ICON mode to handle large items */
1719 if ( (infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_ICON
)
1723 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
1724 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
1726 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1731 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
1733 /* for some reason, owner draw should work only in report mode */
1734 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (uView
== LVS_REPORT
))
1739 item
.iItem
= infoPtr
->nFocusedItem
;
1741 item
.mask
= LVIF_PARAM
;
1742 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
1744 ZeroMemory(&dis
, sizeof(dis
));
1745 dis
.CtlType
= ODT_LISTVIEW
;
1746 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1747 dis
.itemID
= item
.iItem
;
1748 dis
.itemAction
= ODA_FOCUS
;
1749 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
1750 dis
.hwndItem
= infoPtr
->hwndSelf
;
1752 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
1753 dis
.itemData
= item
.lParam
;
1755 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
1759 DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1762 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1766 * Invalidates all visible selected items.
1768 static void LISTVIEW_InvalidateSelectedItems(LISTVIEW_INFO
*infoPtr
)
1772 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
1773 while(iterator_next(&i
))
1775 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
1776 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
1778 iterator_destroy(&i
);
1783 * DESCRIPTION: [INTERNAL]
1784 * Computes an item's (left,top) corner, relative to rcView.
1785 * That is, the position has NOT been made relative to the Origin.
1786 * This is deliberate, to avoid computing the Origin over, and
1787 * over again, when this function is call in a loop. Instead,
1788 * one ca factor the computation of the Origin before the loop,
1789 * and offset the value retured by this function, on every iteration.
1792 * [I] infoPtr : valid pointer to the listview structure
1793 * [I] nItem : item number
1794 * [O] lpptOrig : item top, left corner
1799 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
1801 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1803 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
1805 if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
1807 lpptPosition
->x
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1808 lpptPosition
->y
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1810 else if (uView
== LVS_LIST
)
1812 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
1813 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
1814 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
1816 else /* LVS_REPORT */
1818 lpptPosition
->x
= 0;
1819 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
1824 * DESCRIPTION: [INTERNAL]
1825 * Compute the rectangles of an item. This is to localize all
1826 * the computations in one place. If you are not interested in some
1827 * of these values, simply pass in a NULL -- the fucntion is smart
1828 * enough to compute only what's necessary. The function computes
1829 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
1830 * one, the BOX rectangle. This rectangle is very cheap to compute,
1831 * and is guaranteed to contain all the other rectangles. Computing
1832 * the ICON rect is also cheap, but all the others are potentaily
1833 * expensive. This gives an easy and effective optimization when
1834 * searching (like point inclusion, or rectangle intersection):
1835 * first test against the BOX, and if TRUE, test agains the desired
1837 * If the function does not have all the necessary information
1838 * to computed the requested rectangles, will crash with a
1839 * failed assertion. This is done so we catch all programming
1840 * errors, given that the function is called only from our code.
1842 * We have the following 'special' meanings for a few fields:
1843 * * If LVIS_FOCUSED is set, we assume the item has the focus
1844 * This is important in ICON mode, where it might get a larger
1845 * then usual rectange
1847 * Please note that subitem support works only in REPORT mode.
1850 * [I] infoPtr : valid pointer to the listview structure
1851 * [I] lpLVItem : item to compute the measures for
1852 * [O] lprcBox : ptr to Box rectangle
1853 * The internal LVIR_BOX rectangle
1854 * [0] lprcState : ptr to State icon rectangle
1855 * The internal LVIR_STATE rectangle
1856 * [O] lprcIcon : ptr to Icon rectangle
1857 * Same as LVM_GETITEMRECT with LVIR_ICON
1858 * [O] lprcLabel : ptr to Label rectangle
1859 * Same as LVM_GETITEMRECT with LVIR_LABEL
1864 static void LISTVIEW_GetItemMetrics(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
1865 LPRECT lprcBox
, LPRECT lprcState
,
1866 LPRECT lprcIcon
, LPRECT lprcLabel
)
1868 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1869 BOOL doState
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
1870 RECT Box
, State
, Icon
, Label
;
1871 COLUMN_INFO
*lpColumnInfo
= NULL
;
1873 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
1875 /* Be smart and try to figure out the minimum we have to do */
1876 if (lpLVItem
->iSubItem
) assert(uView
== LVS_REPORT
);
1877 if (uView
== LVS_ICON
&& (lprcBox
|| lprcLabel
))
1879 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
1880 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
1882 if (lprcLabel
) doLabel
= TRUE
;
1883 if (doLabel
|| lprcIcon
) doIcon
= TRUE
;
1884 if (doIcon
|| lprcState
) doState
= TRUE
;
1886 /************************************************************/
1887 /* compute the box rectangle (it should be cheap to do) */
1888 /************************************************************/
1889 if (lpLVItem
->iSubItem
|| uView
== LVS_REPORT
)
1890 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
1892 if (lpLVItem
->iSubItem
)
1894 Box
= lpColumnInfo
->rcHeader
;
1899 Box
.right
= infoPtr
->nItemWidth
;
1902 Box
.bottom
= infoPtr
->nItemHeight
;
1904 /************************************************************/
1905 /* compute STATEICON bounding box */
1906 /************************************************************/
1909 if (uView
== LVS_ICON
)
1911 State
.left
= Box
.left
- infoPtr
->iconStateSize
.cx
- 2;
1912 if (infoPtr
->himlNormal
)
1913 State
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
1914 State
.top
= Box
.top
+ infoPtr
->iconSize
.cy
- infoPtr
->iconStateSize
.cy
+ 4;
1918 /* we need the ident in report mode, if we don't have it, we fail */
1919 State
.left
= Box
.left
;
1920 if (uView
== LVS_REPORT
)
1922 if (lpLVItem
->iSubItem
== 0)
1924 State
.left
+= REPORT_MARGINX
;
1925 assert(lpLVItem
->mask
& LVIF_INDENT
);
1926 State
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
;
1929 State
.top
= Box
.top
;
1931 State
.right
= State
.left
;
1932 State
.bottom
= State
.top
;
1933 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
1935 State
.right
+= infoPtr
->iconStateSize
.cx
;
1936 State
.bottom
+= infoPtr
->iconStateSize
.cy
;
1938 if (lprcState
) *lprcState
= State
;
1939 TRACE(" - state=%s\n", debugrect(&State
));
1942 /************************************************************/
1943 /* compute ICON bounding box (ala LVM_GETITEMRECT) */
1944 /************************************************************/
1947 if (uView
== LVS_ICON
)
1949 Icon
.left
= Box
.left
;
1950 if (infoPtr
->himlNormal
)
1951 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
1952 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
1953 Icon
.right
= Icon
.left
;
1954 Icon
.bottom
= Icon
.top
;
1955 if (infoPtr
->himlNormal
)
1957 Icon
.right
+= infoPtr
->iconSize
.cx
;
1958 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
1961 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
1963 Icon
.left
= State
.right
;
1965 Icon
.right
= Icon
.left
;
1966 if (infoPtr
->himlSmall
&&
1967 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 || (lpColumnInfo
->fmt
& LVCFMT_IMAGE
) ||
1968 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
1969 Icon
.right
+= infoPtr
->iconSize
.cx
;
1970 Icon
.bottom
= Icon
.top
+ infoPtr
->nItemHeight
;
1972 if(lprcIcon
) *lprcIcon
= Icon
;
1973 TRACE(" - icon=%s\n", debugrect(&Icon
));
1976 /************************************************************/
1977 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
1978 /************************************************************/
1981 SIZE labelSize
= { 0, 0 };
1983 /* calculate how far to the right can the label strech */
1984 Label
.right
= Box
.right
;
1985 if (uView
== LVS_REPORT
)
1987 if (lpLVItem
->iSubItem
== 0) Label
= lpColumnInfo
->rcHeader
;
1990 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && uView
== LVS_REPORT
))
1992 labelSize
.cx
= infoPtr
->nItemWidth
;
1993 labelSize
.cy
= infoPtr
->nItemHeight
;
1997 /* we need the text in non owner draw mode */
1998 assert(lpLVItem
->mask
& LVIF_TEXT
);
1999 if (is_textT(lpLVItem
->pszText
, TRUE
))
2001 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2002 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2003 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2007 /* compute rough rectangle where the label will go */
2008 SetRectEmpty(&rcText
);
2009 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2010 rcText
.bottom
= infoPtr
->nItemHeight
;
2011 if (uView
== LVS_ICON
)
2012 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2014 /* now figure out the flags */
2015 if (uView
== LVS_ICON
)
2016 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2018 uFormat
= LV_SL_DT_FLAGS
;
2020 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2022 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2023 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2025 SelectObject(hdc
, hOldFont
);
2026 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2030 if (uView
== LVS_ICON
)
2032 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2033 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2034 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2035 Label
.right
= Label
.left
+ labelSize
.cx
;
2036 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2037 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
&&
2040 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2041 labelSize
.cy
/= infoPtr
->ntmHeight
;
2042 labelSize
.cy
= max(labelSize
.cy
, 1);
2043 labelSize
.cy
*= infoPtr
->ntmHeight
;
2045 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2047 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
2049 Label
.left
= Icon
.right
;
2050 Label
.top
= Box
.top
;
2051 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2052 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2055 if (lprcLabel
) *lprcLabel
= Label
;
2056 TRACE(" - label=%s\n", debugrect(&Label
));
2059 /* Fix the Box if necessary */
2062 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2063 else *lprcBox
= Box
;
2065 TRACE(" - box=%s\n", debugrect(&Box
));
2069 * DESCRIPTION: [INTERNAL]
2072 * [I] infoPtr : valid pointer to the listview structure
2073 * [I] nItem : item number
2074 * [O] lprcBox : ptr to Box rectangle
2079 static void LISTVIEW_GetItemBox(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2081 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2082 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2083 POINT Position
, Origin
;
2086 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2087 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2089 /* Be smart and try to figure out the minimum we have to do */
2091 if (uView
== LVS_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2092 lvItem
.mask
|= LVIF_TEXT
;
2093 lvItem
.iItem
= nItem
;
2094 lvItem
.iSubItem
= 0;
2095 lvItem
.pszText
= szDispText
;
2096 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2097 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2098 if (uView
== LVS_ICON
)
2100 lvItem
.mask
|= LVIF_STATE
;
2101 lvItem
.stateMask
= LVIS_FOCUSED
;
2102 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2104 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0);
2106 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2112 * Returns the current icon position, and advances it along the top.
2113 * The returned position is not offset by Origin.
2116 * [I] infoPtr : valid pointer to the listview structure
2117 * [O] lpPos : will get the current icon position
2122 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2124 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2126 *lpPos
= infoPtr
->currIconPos
;
2128 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2129 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2131 infoPtr
->currIconPos
.x
= 0;
2132 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2138 * Returns the current icon position, and advances it down the left edge.
2139 * The returned position is not offset by Origin.
2142 * [I] infoPtr : valid pointer to the listview structure
2143 * [O] lpPos : will get the current icon position
2148 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2150 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2152 *lpPos
= infoPtr
->currIconPos
;
2154 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2155 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2157 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2158 infoPtr
->currIconPos
.y
= 0;
2164 * Moves an icon to the specified position.
2165 * It takes care of invalidating the item, etc.
2168 * [I] infoPtr : valid pointer to the listview structure
2169 * [I] nItem : the item to move
2170 * [I] lpPos : the new icon position
2171 * [I] isNew : flags the item as being new
2177 static BOOL
LISTVIEW_MoveIconTo(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2183 old
.x
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2184 old
.y
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2186 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2187 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2190 /* Allocating a POINTER for every item is too resource intensive,
2191 * so we'll keep the (x,y) in different arrays */
2192 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)lppt
->x
)) return FALSE
;
2193 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)lppt
->y
)) return FALSE
;
2195 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2202 * Arranges listview items in icon display mode.
2205 * [I] infoPtr : valid pointer to the listview structure
2206 * [I] nAlignCode : alignment code
2212 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2214 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2215 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2219 if (uView
!= LVS_ICON
&& uView
!= LVS_SMALLICON
) return FALSE
;
2221 TRACE("nAlignCode=%d\n", nAlignCode
);
2223 if (nAlignCode
== LVA_DEFAULT
)
2225 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2226 else nAlignCode
= LVA_ALIGNTOP
;
2231 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2232 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2233 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2234 default: return FALSE
;
2237 infoPtr
->bAutoarrange
= TRUE
;
2238 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2239 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2241 next_pos(infoPtr
, &pos
);
2242 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2250 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2253 * [I] infoPtr : valid pointer to the listview structure
2254 * [O] lprcView : bounding rectangle
2260 static void LISTVIEW_GetAreaRect(LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2264 SetRectEmpty(lprcView
);
2266 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
2270 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2272 x
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2273 y
= (LONG
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2274 lprcView
->right
= max(lprcView
->right
, x
);
2275 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2277 if (infoPtr
->nItemCount
> 0)
2279 lprcView
->right
+= infoPtr
->nItemWidth
;
2280 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2285 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2286 x
= infoPtr
->nItemCount
/ y
;
2287 if (infoPtr
->nItemCount
% y
) x
++;
2288 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2289 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2293 lprcView
->right
= infoPtr
->nItemWidth
;
2294 lprcView
->bottom
= infoPtr
->nItemCount
* infoPtr
->nItemHeight
;
2301 * Retrieves the bounding rectangle of all the items.
2304 * [I] infoPtr : valid pointer to the listview structure
2305 * [O] lprcView : bounding rectangle
2311 static BOOL
LISTVIEW_GetViewRect(LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2315 TRACE("(lprcView=%p)\n", lprcView
);
2317 if (!lprcView
) return FALSE
;
2319 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2320 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2321 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2323 TRACE("lprcView=%s\n", debugrect(lprcView
));
2330 * Retrieves the subitem pointer associated with the subitem index.
2333 * [I] hdpaSubItems : DPA handle for a specific item
2334 * [I] nSubItem : index of subitem
2337 * SUCCESS : subitem pointer
2340 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2342 SUBITEM_INFO
*lpSubItem
;
2345 /* we should binary search here if need be */
2346 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2348 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
2349 if (lpSubItem
->iSubItem
== nSubItem
)
2359 * Caclulates the desired item width.
2362 * [I] infoPtr : valid pointer to the listview structure
2365 * The desired item width.
2367 static INT
LISTVIEW_CalculateItemWidth(LISTVIEW_INFO
*infoPtr
)
2369 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2372 TRACE("uView=%d\n", uView
);
2374 if (uView
== LVS_ICON
)
2375 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2376 else if (uView
== LVS_REPORT
)
2380 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2382 LISTVIEW_GetHeaderRect(infoPtr
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, &rcHeader
);
2383 nItemWidth
= rcHeader
.right
;
2386 else /* LVS_SMALLICON, or LVS_LIST */
2390 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2391 nItemWidth
= max(LISTVIEW_GetLabelWidth(infoPtr
, i
), nItemWidth
);
2393 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2394 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2396 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2399 return max(nItemWidth
, 1);
2404 * Caclulates the desired item height.
2407 * [I] infoPtr : valid pointer to the listview structure
2410 * The desired item height.
2412 static INT
LISTVIEW_CalculateItemHeight(LISTVIEW_INFO
*infoPtr
)
2414 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2417 TRACE("uView=%d\n", uView
);
2419 if (uView
== LVS_ICON
)
2420 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2423 nItemHeight
= infoPtr
->ntmHeight
;
2424 if (infoPtr
->himlState
)
2425 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2426 if (infoPtr
->himlSmall
)
2427 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2428 if (infoPtr
->himlState
|| infoPtr
->himlSmall
)
2429 nItemHeight
+= HEIGHT_PADDING
;
2432 return max(nItemHeight
, 1);
2437 * Updates the width, and height of an item.
2440 * [I] infoPtr : valid pointer to the listview structure
2445 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2447 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2448 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2454 * Retrieves and saves important text metrics info for the current
2458 * [I] infoPtr : valid pointer to the listview structure
2461 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2463 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2464 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2465 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2468 if (GetTextMetricsW(hdc
, &tm
))
2470 infoPtr
->ntmHeight
= tm
.tmHeight
;
2471 infoPtr
->ntmAveCharWidth
= tm
.tmAveCharWidth
;
2473 SelectObject(hdc
, hOldFont
);
2474 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2476 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
2481 * A compare function for ranges
2484 * [I] range1 : pointer to range 1;
2485 * [I] range2 : pointer to range 2;
2489 * > 0 : if range 1 > range 2
2490 * < 0 : if range 2 > range 1
2491 * = 0 : if range intersects range 2
2493 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
2497 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
2499 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
2504 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange((RANGE
*)range1
), debugrange((RANGE
*)range2
), cmp
);
2510 #define ranges_check(ranges, desc) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
2512 #define ranges_check(ranges, desc) do { } while(0)
2515 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *func
, int line
)
2520 TRACE("*** Checking %s:%d:%s ***\n", func
, line
, desc
);
2522 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
2523 ranges_dump(ranges
);
2524 prev
= (RANGE
*)DPA_GetPtr(ranges
->hdpa
, 0);
2525 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
2526 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
2527 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2529 curr
= (RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
);
2530 assert (prev
->upper
<= curr
->lower
);
2531 assert (curr
->lower
< curr
->upper
);
2534 TRACE("--- Done checking---\n");
2537 static RANGES
ranges_create(int count
)
2539 RANGES ranges
= (RANGES
)Alloc(sizeof(struct tagRANGES
));
2540 if (!ranges
) return NULL
;
2541 ranges
->hdpa
= DPA_Create(count
);
2542 if (ranges
->hdpa
) return ranges
;
2547 static void ranges_clear(RANGES ranges
)
2551 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2552 Free(DPA_GetPtr(ranges
->hdpa
, i
));
2553 DPA_DeleteAllPtrs(ranges
->hdpa
);
2557 static void ranges_destroy(RANGES ranges
)
2559 if (!ranges
) return;
2560 ranges_clear(ranges
);
2561 DPA_Destroy(ranges
->hdpa
);
2565 static RANGES
ranges_clone(RANGES ranges
)
2570 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
2572 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2574 RANGE
*newrng
= (RANGE
*)Alloc(sizeof(RANGE
));
2575 if (!newrng
) goto fail
;
2576 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
2577 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
2582 TRACE ("clone failed\n");
2583 ranges_destroy(clone
);
2587 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
2591 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
2592 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
2597 static void ranges_dump(RANGES ranges
)
2601 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2602 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
2605 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
2607 RANGE srchrng
= { nItem
, nItem
+ 1 };
2609 TRACE("(nItem=%d)\n", nItem
);
2610 ranges_check(ranges
, "before contain");
2611 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
2614 static INT
ranges_itemcount(RANGES ranges
)
2618 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2620 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
2621 count
+= sel
->upper
- sel
->lower
;
2627 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
2629 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
2632 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2633 if (index
== -1) return TRUE
;
2635 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
2637 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
2638 if (chkrng
->lower
>= nItem
)
2639 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
2640 if (chkrng
->upper
> nItem
)
2641 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
2646 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
2651 TRACE("(%s)\n", debugrange(&range
));
2652 ranges_check(ranges
, "before add");
2654 /* try find overlapping regions first */
2655 srchrgn
.lower
= range
.lower
- 1;
2656 srchrgn
.upper
= range
.upper
+ 1;
2657 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
2663 TRACE("Adding new range\n");
2665 /* create the brand new range to insert */
2666 newrgn
= (RANGE
*)Alloc(sizeof(RANGE
));
2667 if(!newrgn
) goto fail
;
2670 /* figure out where to insert it */
2671 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2672 TRACE("index=%d\n", index
);
2673 if (index
== -1) index
= 0;
2675 /* and get it over with */
2676 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
2684 RANGE
*chkrgn
, *mrgrgn
;
2685 INT fromindex
, mergeindex
;
2687 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
2688 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
2690 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
2691 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
2693 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
2695 /* merge now common anges */
2697 srchrgn
.lower
= chkrgn
->lower
- 1;
2698 srchrgn
.upper
= chkrgn
->upper
+ 1;
2702 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
2703 if (mergeindex
== -1) break;
2704 if (mergeindex
== index
)
2706 fromindex
= index
+ 1;
2710 TRACE("Merge with index %i\n", mergeindex
);
2712 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
2713 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
2714 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
2716 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
2717 if (mergeindex
< index
) index
--;
2721 ranges_check(ranges
, "after add");
2725 ranges_check(ranges
, "failed add");
2729 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
2734 TRACE("(%s)\n", debugrange(&range
));
2735 ranges_check(ranges
, "before del");
2737 /* we don't use DPAS_SORTED here, since we need *
2738 * to find the first overlapping range */
2739 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
2742 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
2744 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
2746 /* case 1: Same range */
2747 if ( (chkrgn
->upper
== range
.upper
) &&
2748 (chkrgn
->lower
== range
.lower
) )
2750 DPA_DeletePtr(ranges
->hdpa
, index
);
2753 /* case 2: engulf */
2754 else if ( (chkrgn
->upper
<= range
.upper
) &&
2755 (chkrgn
->lower
>= range
.lower
) )
2757 DPA_DeletePtr(ranges
->hdpa
, index
);
2759 /* case 3: overlap upper */
2760 else if ( (chkrgn
->upper
<= range
.upper
) &&
2761 (chkrgn
->lower
< range
.lower
) )
2763 chkrgn
->upper
= range
.lower
;
2765 /* case 4: overlap lower */
2766 else if ( (chkrgn
->upper
> range
.upper
) &&
2767 (chkrgn
->lower
>= range
.lower
) )
2769 chkrgn
->lower
= range
.upper
;
2772 /* case 5: fully internal */
2775 RANGE tmprgn
= *chkrgn
, *newrgn
;
2777 if (!(newrgn
= (RANGE
*)Alloc(sizeof(RANGE
)))) goto fail
;
2778 newrgn
->lower
= chkrgn
->lower
;
2779 newrgn
->upper
= range
.lower
;
2780 chkrgn
->lower
= range
.upper
;
2781 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
2790 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
2793 ranges_check(ranges
, "after del");
2797 ranges_check(ranges
, "failed del");
2803 * Removes all selection ranges
2806 * [I] infoPtr : valid pointer to the listview structure
2807 * [I] toSkip : item range to skip removing the selection
2813 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
2822 lvItem
.stateMask
= LVIS_SELECTED
;
2824 /* need to clone the DPA because callbacks can change it */
2825 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
2826 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
2827 while(iterator_next(&i
))
2828 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
2829 /* note that the iterator destructor will free the cloned range */
2830 iterator_destroy(&i
);
2835 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2839 if (!(toSkip
= ranges_create(1))) return FALSE
;
2840 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
2841 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
2842 ranges_destroy(toSkip
);
2846 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
2848 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
2853 * Retrieves the number of items that are marked as selected.
2856 * [I] infoPtr : valid pointer to the listview structure
2859 * Number of items selected.
2861 static INT
LISTVIEW_GetSelectedCount(LISTVIEW_INFO
*infoPtr
)
2863 INT nSelectedCount
= 0;
2865 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
2868 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2870 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
2875 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
2877 TRACE("nSelectedCount=%d\n", nSelectedCount
);
2878 return nSelectedCount
;
2883 * Manages the item focus.
2886 * [I] infoPtr : valid pointer to the listview structure
2887 * [I] nItem : item index
2890 * TRUE : focused item changed
2891 * FALSE : focused item has NOT changed
2893 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2895 INT oldFocus
= infoPtr
->nFocusedItem
;
2898 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
2900 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
2901 lvItem
.stateMask
= LVIS_FOCUSED
;
2902 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
2904 return oldFocus
!= infoPtr
->nFocusedItem
;
2907 /* Helper function for LISTVIEW_ShiftIndices *only* */
2908 static INT
shift_item(LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
2910 if (nShiftItem
< nItem
) return nShiftItem
;
2912 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
2914 if (direction
> 0) return nShiftItem
+ direction
;
2916 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
2921 * Updates the various indices after an item has been inserted or deleted.
2924 * [I] infoPtr : valid pointer to the listview structure
2925 * [I] nItem : item index
2926 * [I] direction : Direction of shift, +1 or -1.
2931 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
2936 /* temporarily disable change notification while shifting items */
2937 bOldChange
= infoPtr
->bDoChangeNotify
;
2938 infoPtr
->bDoChangeNotify
= FALSE
;
2940 TRACE("Shifting %iu, %i steps\n", nItem
, direction
);
2942 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
2944 assert(abs(direction
) == 1);
2946 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
2948 nNewFocus
= shift_item(infoPtr
, infoPtr
->nFocusedItem
, nItem
, direction
);
2949 if (nNewFocus
!= infoPtr
->nFocusedItem
)
2950 LISTVIEW_SetItemFocus(infoPtr
, nNewFocus
);
2952 /* But we are not supposed to modify nHotItem! */
2954 infoPtr
->bDoChangeNotify
= bOldChange
;
2960 * Adds a block of selections.
2963 * [I] infoPtr : valid pointer to the listview structure
2964 * [I] nItem : item index
2969 static void LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2971 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
2972 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
2976 if (nFirst
== -1) nFirst
= nItem
;
2978 item
.state
= LVIS_SELECTED
;
2979 item
.stateMask
= LVIS_SELECTED
;
2981 /* FIXME: this is not correct LVS_OWNERDATA
2982 * setting the item states individually will generate
2983 * a LVN_ITEMCHANGED notification for each one. Instead,
2984 * we have to send a LVN_ODSTATECHANGED notification.
2985 * See MSDN documentation for LVN_ITEMCHANGED.
2987 for (i
= nFirst
; i
<= nLast
; i
++)
2988 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
2994 * Sets a single group selection.
2997 * [I] infoPtr : valid pointer to the listview structure
2998 * [I] nItem : item index
3003 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3005 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3010 if (!(selection
= ranges_create(100))) return;
3012 item
.state
= LVIS_SELECTED
;
3013 item
.stateMask
= LVIS_SELECTED
;
3015 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
3017 if (infoPtr
->nSelectionMark
== -1)
3019 infoPtr
->nSelectionMark
= nItem
;
3020 ranges_additem(selection
, nItem
);
3026 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3027 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3028 ranges_add(selection
, sel
);
3033 RECT rcItem
, rcSel
, rcSelMark
;
3036 rcItem
.left
= LVIR_BOUNDS
;
3037 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return;
3038 rcSelMark
.left
= LVIR_BOUNDS
;
3039 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) return;
3040 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3041 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3042 while(iterator_next(&i
))
3044 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3045 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3047 iterator_destroy(&i
);
3050 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3051 iterator_rangesitems(&i
, selection
);
3052 while(iterator_next(&i
))
3053 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3054 /* this will also destroy the selection */
3055 iterator_destroy(&i
);
3057 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3062 * Sets a single selection.
3065 * [I] infoPtr : valid pointer to the listview structure
3066 * [I] nItem : item index
3071 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3075 TRACE("nItem=%d\n", nItem
);
3077 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3079 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3080 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3081 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3083 infoPtr
->nSelectionMark
= nItem
;
3088 * Set selection(s) with keyboard.
3091 * [I] infoPtr : valid pointer to the listview structure
3092 * [I] nItem : item index
3095 * SUCCESS : TRUE (needs to be repainted)
3096 * FAILURE : FALSE (nothing has changed)
3098 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3100 /* FIXME: pass in the state */
3101 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3102 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3103 BOOL bResult
= FALSE
;
3105 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3107 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
3110 LISTVIEW_SetSelection(infoPtr
, nItem
);
3117 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3121 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3126 LISTVIEW_SetSelection(infoPtr
, nItem
);
3129 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3132 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3139 * Called when the mouse is being actively tracked and has hovered for a specified
3143 * [I] infoPtr : valid pointer to the listview structure
3144 * [I] fwKeys : key indicator
3145 * [I] x,y : mouse position
3148 * 0 if the message was processed, non-zero if there was an error
3151 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3152 * over the item for a certain period of time.
3155 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, WORD fwKyes
, INT x
, INT y
)
3157 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
3158 /* FIXME: select the item!!! */
3159 /*LISTVIEW_GetItemAtPt(infoPtr, pt)*/;
3166 * Called whenever WM_MOUSEMOVE is received.
3169 * [I] infoPtr : valid pointer to the listview structure
3170 * [I] fwKeys : key indicator
3171 * [I] x,y : mouse position
3174 * 0 if the message is processed, non-zero if there was an error
3176 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3178 TRACKMOUSEEVENT trackinfo
;
3180 /* see if we are supposed to be tracking mouse hovering */
3181 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) {
3182 /* fill in the trackinfo struct */
3183 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
3184 trackinfo
.dwFlags
= TME_QUERY
;
3185 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
3186 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
3188 /* see if we are already tracking this hwnd */
3189 _TrackMouseEvent(&trackinfo
);
3191 if(!(trackinfo
.dwFlags
& TME_HOVER
)) {
3192 trackinfo
.dwFlags
= TME_HOVER
;
3194 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
3195 _TrackMouseEvent(&trackinfo
);
3204 * Tests wheather the item is assignable to a list with style lStyle
3206 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
3208 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
3209 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
3210 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
3218 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
3221 * [I] infoPtr : valid pointer to the listview structure
3222 * [I] lpLVItem : valid pointer to new item atttributes
3223 * [I] isNew : the item being set is being inserted
3224 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3225 * [O] bChanged : will be set to TRUE if the item really changed
3231 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
3233 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3241 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
3243 if (lpLVItem
->mask
== 0) return TRUE
;
3245 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3247 /* a virtual listview we stores only selection and focus */
3248 if (lpLVItem
->mask
& ~LVIF_STATE
)
3254 HDPA hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3255 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
3259 /* we need to get the lParam and state of the item */
3260 item
.iItem
= lpLVItem
->iItem
;
3261 item
.iSubItem
= lpLVItem
->iSubItem
;
3262 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
3263 item
.stateMask
= ~0;
3266 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
3268 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
3269 /* determine what fields will change */
3270 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
))
3271 uChanged
|= LVIF_STATE
;
3273 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
3274 uChanged
|= LVIF_IMAGE
;
3276 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
3277 uChanged
|= LVIF_PARAM
;
3279 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
3280 uChanged
|= LVIF_INDENT
;
3282 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
3283 uChanged
|= LVIF_TEXT
;
3285 TRACE("uChanged=0x%x\n", uChanged
);
3286 if (!uChanged
) return TRUE
;
3289 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
3290 nmlv
.iItem
= lpLVItem
->iItem
;
3291 nmlv
.uNewState
= (item
.state
& ~lpLVItem
->stateMask
) | (lpLVItem
->state
& lpLVItem
->stateMask
);
3292 nmlv
.uOldState
= item
.state
;
3293 nmlv
.uChanged
= uChanged
;
3294 nmlv
.lParam
= item
.lParam
;
3296 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
3297 /* and we are _NOT_ virtual (LVS_OWERNDATA), and change notifications */
3299 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
&&
3300 notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
3303 /* copy information */
3304 if (lpLVItem
->mask
& LVIF_TEXT
)
3305 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3307 if (lpLVItem
->mask
& LVIF_IMAGE
)
3308 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
3310 if (lpLVItem
->mask
& LVIF_PARAM
)
3311 lpItem
->lParam
= lpLVItem
->lParam
;
3313 if (lpLVItem
->mask
& LVIF_INDENT
)
3314 lpItem
->iIndent
= lpLVItem
->iIndent
;
3316 if (uChanged
& LVIF_STATE
)
3318 if (lpItem
&& (lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& ~(LVIS_FOCUSED
| LVIS_SELECTED
)))
3320 lpItem
->state
&= ~lpLVItem
->stateMask
;
3321 lpItem
->state
|= (lpLVItem
->state
& lpLVItem
->stateMask
);
3323 if (lpLVItem
->state
& lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3325 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
3326 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3328 else if (lpLVItem
->stateMask
& LVIS_SELECTED
)
3329 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3331 /* if we are asked to change focus, and we manage it, do it */
3332 if (lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
3334 if (lpLVItem
->state
& LVIS_FOCUSED
)
3336 LISTVIEW_SetItemFocus(infoPtr
, -1);
3337 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
3338 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, uView
== LVS_LIST
);
3340 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
3341 infoPtr
->nFocusedItem
= -1;
3345 /* if we're inserting the item, we're done */
3346 if (isNew
) return TRUE
;
3348 /* send LVN_ITEMCHANGED notification */
3349 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
3350 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
3357 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
3360 * [I] infoPtr : valid pointer to the listview structure
3361 * [I] lpLVItem : valid pointer to new subitem atttributes
3362 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3363 * [O] bChanged : will be set to TRUE if the item really changed
3369 static BOOL
set_sub_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
3372 SUBITEM_INFO
*lpSubItem
;
3374 /* we do not support subitems for virtual listviews */
3375 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
3377 /* set subitem only if column is present */
3378 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
3380 /* First do some sanity checks */
3381 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
)) return FALSE
;
3382 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
))) return TRUE
;
3384 /* get the subitem structure, and create it if not there */
3385 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3386 assert (hdpaSubItems
);
3388 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
3391 SUBITEM_INFO
*tmpSubItem
;
3394 lpSubItem
= (SUBITEM_INFO
*)Alloc(sizeof(SUBITEM_INFO
));
3395 if (!lpSubItem
) return FALSE
;
3396 /* we could binary search here, if need be...*/
3397 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
3399 tmpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
3400 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
3402 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
3407 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
3408 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
3412 if (lpLVItem
->mask
& LVIF_IMAGE
)
3413 if (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
)
3415 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
3419 if (lpLVItem
->mask
& LVIF_TEXT
)
3420 if (lpSubItem
->hdr
.pszText
!= lpLVItem
->pszText
)
3422 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3431 * Sets item attributes.
3434 * [I] infoPtr : valid pointer to the listview structure
3435 * [I] lpLVItem : new item atttributes
3436 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3442 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
3444 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3445 LPWSTR pszText
= NULL
;
3446 BOOL bResult
, bChanged
= FALSE
;
3448 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
3450 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
3453 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
3454 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_textW(lpLVItem
->pszText
))
3456 pszText
= lpLVItem
->pszText
;
3457 ((LVITEMW
*)lpLVItem
)->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
3460 /* actually set the fields */
3461 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
3463 if (lpLVItem
->iSubItem
)
3464 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
3466 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
3468 /* redraw item, if necessary */
3469 if (bChanged
&& !infoPtr
->bIsDrawing
)
3471 /* this little optimization eliminates some nasty flicker */
3472 if ( uView
== LVS_REPORT
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
3473 (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || lpLVItem
->iSubItem
) )
3474 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
3476 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
3481 textfreeT(lpLVItem
->pszText
, isW
);
3482 ((LVITEMW
*)lpLVItem
)->pszText
= pszText
;
3490 * Retrieves the index of the item at coordinate (0, 0) of the client area.
3493 * [I] infoPtr : valid pointer to the listview structure
3498 static INT
LISTVIEW_GetTopIndex(LISTVIEW_INFO
*infoPtr
)
3500 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3502 SCROLLINFO scrollInfo
;
3504 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3505 scrollInfo
.fMask
= SIF_POS
;
3507 if (uView
== LVS_LIST
)
3509 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3510 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
3512 else if (uView
== LVS_REPORT
)
3514 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3515 nItem
= scrollInfo
.nPos
;
3519 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3520 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
3523 TRACE("nItem=%d\n", nItem
);
3531 * Erases the background of the given rectangle
3534 * [I] infoPtr : valid pointer to the listview structure
3535 * [I] hdc : device context handle
3536 * [I] lprcBox : clipping rectangle
3542 static inline BOOL
LISTVIEW_FillBkgnd(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
3544 if (!infoPtr
->hBkBrush
) return FALSE
;
3546 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, debugrect(lprcBox
), infoPtr
->hBkBrush
);
3548 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
3556 * [I] infoPtr : valid pointer to the listview structure
3557 * [I] hdc : device context handle
3558 * [I] nItem : item index
3559 * [I] nSubItem : subitem index
3560 * [I] pos : item position in client coordinates
3561 * [I] cdmode : custom draw mode
3567 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
3569 UINT uFormat
, uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3570 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
3571 static const WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
3572 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
3573 RECT
* lprcFocus
, rcSelect
, rcBox
, rcState
, rcIcon
, rcLabel
;
3574 NMLVCUSTOMDRAW nmlvcd
;
3578 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, debugpoint(&pos
));
3580 /* get information needed for drawing the item */
3581 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
3582 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
| LVIF_PARAM
;
3583 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
3584 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
;
3585 lvItem
.iItem
= nItem
;
3586 lvItem
.iSubItem
= nSubItem
;
3589 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
3590 lvItem
.pszText
= szDispText
;
3591 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
3592 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3593 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3594 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= (LPWSTR
)szCallback
;
3595 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
3597 /* now check if we need to update the focus rectangle */
3598 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
3600 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
3601 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcState
, &rcIcon
, &rcLabel
);
3602 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
3603 OffsetRect(&rcState
, pos
.x
, pos
.y
);
3604 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
3605 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
3606 TRACE(" rcBox=%s, rcState=%s, rcIcon=%s. rcLabel=%s\n",
3607 debugrect(&rcBox
), debugrect(&rcState
), debugrect(&rcIcon
), debugrect(&rcLabel
));
3609 /* fill in the custom draw structure */
3610 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
3612 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
3613 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
3614 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
3615 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
3616 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
3617 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
3618 if (nSubItem
== 0 && cdsubitemmode
== CDRF_NOTIFYITEMDRAW
)
3620 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
3621 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
3623 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
3624 prepaint_setup(infoPtr
, hdc
, &nmlvcd
);
3626 /* in full row select, subitems, will just use main item's colors */
3627 if (nSubItem
&& uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3628 nmlvcd
.clrTextBk
= CLR_NONE
;
3631 if (infoPtr
->himlState
&& !IsRectEmpty(&rcState
))
3633 UINT uStateImage
= (lvItem
.state
& LVIS_STATEIMAGEMASK
) >> 12;
3636 TRACE("uStateImage=%d\n", uStateImage
);
3637 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
, rcState
.left
, rcState
.top
, ILD_NORMAL
);
3642 himl
= (uView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
3643 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
3645 TRACE("iImage=%d\n", lvItem
.iImage
);
3646 ImageList_Draw(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
3647 (lvItem
.state
& LVIS_SELECTED
) && (infoPtr
->bFocus
) ? ILD_SELECTED
: ILD_NORMAL
);
3650 /* Don't bother painting item being edited */
3651 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
3653 /* draw the selection background, if we're drawing the main item */
3657 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3658 rcSelect
.right
= rcBox
.right
;
3660 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
3661 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, 0, 0, 0);
3662 if(lprcFocus
) *lprcFocus
= rcSelect
;
3665 /* figure out the text drawing flags */
3666 uFormat
= (uView
== LVS_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
3667 if (uView
== LVS_ICON
)
3668 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
3671 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
3673 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
3674 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
3675 default: uFormat
|= DT_LEFT
;
3678 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
3680 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
3681 else rcLabel
.left
+= LABEL_HOR_PADDING
;
3683 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
3684 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
3687 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
3688 notify_postpaint(infoPtr
, &nmlvcd
);
3694 * Draws listview items when in owner draw mode.
3697 * [I] infoPtr : valid pointer to the listview structure
3698 * [I] hdc : device context handle
3703 static void LISTVIEW_RefreshOwnerDraw(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
3705 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
3706 DWORD cditemmode
= CDRF_DODEFAULT
;
3707 NMLVCUSTOMDRAW nmlvcd
;
3708 POINT Origin
, Position
;
3714 ZeroMemory(&dis
, sizeof(dis
));
3716 /* Get scroll info once before loop */
3717 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3719 /* iterate through the invalidated rows */
3720 while(iterator_next(i
))
3722 item
.iItem
= i
->nItem
;
3724 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
3725 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
3726 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
3728 dis
.CtlType
= ODT_LISTVIEW
;
3730 dis
.itemID
= item
.iItem
;
3731 dis
.itemAction
= ODA_DRAWENTIRE
;
3733 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
3734 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
3735 dis
.hwndItem
= infoPtr
->hwndSelf
;
3737 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
3738 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
3739 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
3740 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
3741 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
3742 dis
.itemData
= item
.lParam
;
3744 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), debugrect(&dis
.rcItem
));
3747 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
3748 * structure for the rest. of the paint cycle
3750 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
3751 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
3752 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
3754 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
3756 prepaint_setup (infoPtr
, hdc
, &nmlvcd
);
3757 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
3760 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
3761 notify_postpaint(infoPtr
, &nmlvcd
);
3767 * Draws listview items when in report display mode.
3770 * [I] infoPtr : valid pointer to the listview structure
3771 * [I] hdc : device context handle
3772 * [I] cdmode : custom draw mode
3777 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
3780 RECT rcClip
, rcItem
;
3781 POINT Origin
, Position
;
3787 /* figure out what to draw */
3788 rgntype
= GetClipBox(hdc
, &rcClip
);
3789 if (rgntype
== NULLREGION
) return;
3791 /* Get scroll info once before loop */
3792 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3794 /* narrow down the columns we need to paint */
3795 for(colRange
.lower
= 0; colRange
.lower
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); colRange
.lower
++)
3797 LISTVIEW_GetHeaderRect(infoPtr
, colRange
.lower
, &rcItem
);
3798 if (rcItem
.right
+ Origin
.x
>= rcClip
.left
) break;
3800 for(colRange
.upper
= DPA_GetPtrCount(infoPtr
->hdpaColumns
); colRange
.upper
> 0; colRange
.upper
--)
3802 LISTVIEW_GetHeaderRect(infoPtr
, colRange
.upper
- 1, &rcItem
);
3803 if (rcItem
.left
+ Origin
.x
< rcClip
.right
) break;
3805 iterator_rangeitems(&j
, colRange
);
3807 /* in full row select, we _have_ to draw the main item */
3808 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
3811 /* iterate through the invalidated rows */
3812 while(iterator_next(i
))
3814 /* iterate through the invalidated columns */
3815 while(iterator_next(&j
))
3817 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
3818 Position
.x
+= Origin
.x
;
3819 Position
.y
+= Origin
.y
;
3821 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
3823 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
3825 rcItem
.bottom
= infoPtr
->nItemHeight
;
3826 OffsetRect(&rcItem
, Position
.x
, Position
.y
);
3827 if (!RectVisible(hdc
, &rcItem
)) continue;
3830 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
3833 iterator_destroy(&j
);
3838 * Draws listview items when in list display mode.
3841 * [I] infoPtr : valid pointer to the listview structure
3842 * [I] hdc : device context handle
3843 * [I] cdmode : custom draw mode
3848 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
3850 POINT Origin
, Position
;
3852 /* Get scroll info once before loop */
3853 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3855 while(iterator_prev(i
))
3857 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
3858 Position
.x
+= Origin
.x
;
3859 Position
.y
+= Origin
.y
;
3861 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
3868 * Draws listview items.
3871 * [I] infoPtr : valid pointer to the listview structure
3872 * [I] hdc : device context handle
3877 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
3879 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3880 COLORREF oldTextColor
, oldClrTextBk
, oldClrText
;
3881 NMLVCUSTOMDRAW nmlvcd
;
3888 LISTVIEW_DUMP(infoPtr
);
3890 infoPtr
->bIsDrawing
= TRUE
;
3892 /* save dc values we're gonna trash while drawing */
3893 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3894 oldBkMode
= GetBkMode(hdc
);
3895 infoPtr
->clrTextBkDefault
= GetBkColor(hdc
);
3896 oldTextColor
= GetTextColor(hdc
);
3898 oldClrTextBk
= infoPtr
->clrTextBk
;
3899 oldClrText
= infoPtr
->clrText
;
3901 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
3903 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
3904 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
3905 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
3906 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
3907 prepaint_setup(infoPtr
, hdc
, &nmlvcd
);
3909 /* Use these colors to draw the items */
3910 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
3911 infoPtr
->clrText
= nmlvcd
.clrText
;
3913 /* nothing to draw */
3914 if(infoPtr
->nItemCount
== 0) goto enddraw
;
3916 /* figure out what we need to draw */
3917 iterator_visibleitems(&i
, infoPtr
, hdc
);
3919 /* send cache hint notification */
3920 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3922 RANGE range
= iterator_range(&i
);
3925 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
3926 nmlv
.iFrom
= range
.lower
;
3927 nmlv
.iTo
= range
.upper
- 1;
3928 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
3931 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (uView
== LVS_REPORT
))
3932 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
3935 if (uView
== LVS_REPORT
)
3936 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
3937 else /* LVS_LIST, LVS_ICON or LVS_SMALLICON */
3938 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
3940 /* if we have a focus rect, draw it */
3941 if (infoPtr
->bFocus
)
3942 DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
3944 iterator_destroy(&i
);
3947 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
3948 notify_postpaint(infoPtr
, &nmlvcd
);
3950 infoPtr
->clrTextBk
= oldClrTextBk
;
3951 infoPtr
->clrText
= oldClrText
;
3953 SelectObject(hdc
, hOldFont
);
3954 SetBkMode(hdc
, oldBkMode
);
3955 SetBkColor(hdc
, infoPtr
->clrTextBkDefault
);
3956 SetTextColor(hdc
, oldTextColor
);
3957 infoPtr
->bIsDrawing
= FALSE
;
3963 * Calculates the approximate width and height of a given number of items.
3966 * [I] infoPtr : valid pointer to the listview structure
3967 * [I] nItemCount : number of items
3968 * [I] wWidth : width
3969 * [I] wHeight : height
3972 * Returns a DWORD. The width in the low word and the height in high word.
3974 static DWORD
LISTVIEW_ApproximateViewRect(LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
3975 WORD wWidth
, WORD wHeight
)
3977 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3978 INT nItemCountPerColumn
= 1;
3979 INT nColumnCount
= 0;
3980 DWORD dwViewRect
= 0;
3982 if (nItemCount
== -1)
3983 nItemCount
= infoPtr
->nItemCount
;
3985 if (uView
== LVS_LIST
)
3987 if (wHeight
== 0xFFFF)
3989 /* use current height */
3990 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
3993 if (wHeight
< infoPtr
->nItemHeight
)
3994 wHeight
= infoPtr
->nItemHeight
;
3998 if (infoPtr
->nItemHeight
> 0)
4000 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
4001 if (nItemCountPerColumn
== 0)
4002 nItemCountPerColumn
= 1;
4004 if (nItemCount
% nItemCountPerColumn
!= 0)
4005 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
4007 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
4011 /* Microsoft padding magic */
4012 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
4013 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
4015 dwViewRect
= MAKELONG(wWidth
, wHeight
);
4017 else if (uView
== LVS_REPORT
)
4021 if (infoPtr
->nItemCount
> 0)
4023 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
4024 wWidth
= rcBox
.right
- rcBox
.left
;
4025 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
4029 /* use current height and width */
4030 if (wHeight
== 0xffff)
4031 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
4032 if (wWidth
== 0xffff)
4033 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
4036 dwViewRect
= MAKELONG(wWidth
, wHeight
);
4038 else if (uView
== LVS_SMALLICON
)
4039 FIXME("uView == LVS_SMALLICON: not implemented\n");
4040 else if (uView
== LVS_ICON
)
4041 FIXME("uView == LVS_ICON: not implemented\n");
4049 * Create a drag image list for the specified item.
4052 * [I] infoPtr : valid pointer to the listview structure
4053 * [I] iItem : index of item
4054 * [O] lppt : Upperr-left corner of the image
4057 * Returns a handle to the image list if successful, NULL otherwise.
4059 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
4065 HBITMAP hbmp
, hOldbmp
;
4066 HIMAGELIST dragList
= 0;
4067 TRACE("iItem=%d Count=%d \n", iItem
, infoPtr
->nItemCount
);
4069 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
)
4072 rcItem
.left
= LVIR_BOUNDS
;
4073 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
4076 lppt
->x
= rcItem
.left
;
4077 lppt
->y
= rcItem
.top
;
4079 size
.cx
= rcItem
.right
- rcItem
.left
;
4080 size
.cy
= rcItem
.bottom
- rcItem
.top
;
4082 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
4083 hdc
= CreateCompatibleDC(hdcOrig
);
4084 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
4085 hOldbmp
= SelectObject(hdc
, hbmp
);
4087 rcItem
.left
= rcItem
.top
= 0;
4088 rcItem
.right
= size
.cx
;
4089 rcItem
.bottom
= size
.cy
;
4090 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
4093 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
4095 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4096 SelectObject(hdc
, hOldbmp
);
4097 ImageList_Add(dragList
, hbmp
, 0);
4100 SelectObject(hdc
, hOldbmp
);
4104 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
4106 TRACE("ret=%p\n", dragList
);
4114 * Removes all listview items and subitems.
4117 * [I] infoPtr : valid pointer to the listview structure
4123 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
)
4126 HDPA hdpaSubItems
= NULL
;
4133 /* we do it directly, to avoid notifications */
4134 ranges_clear(infoPtr
->selectionRanges
);
4135 infoPtr
->nSelectionMark
= -1;
4136 infoPtr
->nFocusedItem
= -1;
4137 SetRectEmpty(&infoPtr
->rcFocus
);
4138 /* But we are supposed to leave nHotItem as is! */
4141 /* send LVN_DELETEALLITEMS notification */
4142 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
4144 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
4146 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
4148 /* send LVN_DELETEITEM notification, if not suppressed */
4149 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
4150 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4152 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, i
);
4153 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
4155 hdrItem
= (ITEMHDR
*)DPA_GetPtr(hdpaSubItems
, j
);
4156 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
4159 DPA_Destroy(hdpaSubItems
);
4160 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
4162 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
4163 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
4164 infoPtr
->nItemCount
--;
4167 LISTVIEW_UpdateScroll(infoPtr
);
4169 LISTVIEW_InvalidateList(infoPtr
);
4176 * Scrolls, and updates the columns, when a column is changing width.
4179 * [I] infoPtr : valid pointer to the listview structure
4180 * [I] nColumn : column to scroll
4181 * [I] dx : amount of scroll, in pixels
4186 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
4188 COLUMN_INFO
*lpColumnInfo
;
4192 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
4193 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
4194 rcCol
= lpColumnInfo
->rcHeader
;
4195 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
4196 rcCol
.left
= rcCol
.right
;
4198 /* ajust the other columns */
4199 for (nCol
= nColumn
; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
4201 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
4202 lpColumnInfo
->rcHeader
.left
+= dx
;
4203 lpColumnInfo
->rcHeader
.right
+= dx
;
4206 /* do not update screen if not in report mode */
4207 if (!is_redrawing(infoPtr
) || (infoPtr
->dwStyle
& LVS_TYPEMASK
) != LVS_REPORT
) return;
4209 /* if we have a focus, must first erase the focus rect */
4210 if (infoPtr
->bFocus
) LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
4212 /* Need to reset the item width when inserting a new column */
4213 infoPtr
->nItemWidth
+= dx
;
4215 LISTVIEW_UpdateScroll(infoPtr
);
4217 /* scroll to cover the deleted column, and invalidate for redraw */
4218 rcOld
= infoPtr
->rcList
;
4219 rcOld
.left
= rcCol
.left
;
4220 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4222 /* we can restore focus now */
4223 if (infoPtr
->bFocus
) LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
4228 * Removes a column from the listview control.
4231 * [I] infoPtr : valid pointer to the listview structure
4232 * [I] nColumn : column index
4238 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
4242 TRACE("nColumn=%d\n", nColumn
);
4244 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
4245 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4247 /* While the MSDN specifically says that column zero should not be deleted,
4248 what actually happens is that the column itself is deleted but no items or subitems
4252 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
4254 if (!Header_DeleteItem(infoPtr
->hwndHeader
, nColumn
))
4257 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
4258 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
4260 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
4262 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
4264 INT nItem
, nSubItem
, i
;
4266 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
4268 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
4271 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4273 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
4274 if (lpSubItem
->iSubItem
== nColumn
)
4277 lpDelItem
= lpSubItem
;
4279 else if (lpSubItem
->iSubItem
> nColumn
)
4281 lpSubItem
->iSubItem
--;
4285 /* if we found our subitem, zapp it */
4289 if (is_textW(lpDelItem
->hdr
.pszText
))
4290 Free(lpDelItem
->hdr
.pszText
);
4295 /* free dpa memory */
4296 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
4301 /* update the other column info */
4302 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
4303 LISTVIEW_InvalidateList(infoPtr
);
4305 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
4312 * Invalidates the listview after an item's insertion or deletion.
4315 * [I] infoPtr : valid pointer to the listview structure
4316 * [I] nItem : item index
4317 * [I] dir : -1 if deleting, 1 if inserting
4322 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
4324 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4325 INT nPerCol
, nItemCol
, nItemRow
;
4329 /* if we don't refresh, what's the point of scrolling? */
4330 if (!is_redrawing(infoPtr
)) return;
4332 assert (abs(dir
) == 1);
4334 /* arrange icons if autoarrange is on */
4335 if (is_autoarrange(infoPtr
))
4337 BOOL arrange
= TRUE
;
4338 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
4339 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
4340 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
4343 /* scrollbars need updating */
4344 LISTVIEW_UpdateScroll(infoPtr
);
4346 /* figure out the item's position */
4347 if (uView
== LVS_REPORT
)
4348 nPerCol
= infoPtr
->nItemCount
+ 1;
4349 else if (uView
== LVS_LIST
)
4350 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
4351 else /* LVS_ICON, or LVS_SMALLICON */
4354 nItemCol
= nItem
/ nPerCol
;
4355 nItemRow
= nItem
% nPerCol
;
4356 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4358 /* move the items below up a slot */
4359 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
4360 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
4361 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
4362 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
4363 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
4364 TRACE("rcScroll=%s, dx=%d\n", debugrect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
4365 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
4367 TRACE("Scrolling rcScroll=%s, rcList=%s\n", debugrect(&rcScroll
), debugrect(&infoPtr
->rcList
));
4368 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
4369 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4372 /* report has only that column, so we're done */
4373 if (uView
== LVS_REPORT
) return;
4375 /* now for LISTs, we have to deal with the columns to the right */
4376 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
4378 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
4379 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
4380 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
4381 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
4382 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
4383 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4388 * Removes an item from the listview control.
4391 * [I] infoPtr : valid pointer to the listview structure
4392 * [I] nItem : item index
4398 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
4400 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4403 TRACE("(nItem=%d)\n", nItem
);
4405 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
4407 /* remove selection, and focus */
4409 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4410 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
4412 /* send LVN_DELETEITEM notification. */
4413 notify_deleteitem(infoPtr
, nItem
);
4415 /* we need to do this here, because we'll be deleting stuff */
4416 if (uView
== LVS_SMALLICON
|| uView
== LVS_ICON
)
4417 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
4419 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4425 hdpaSubItems
= (HDPA
)DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
4426 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4428 hdrItem
= (ITEMHDR
*)DPA_GetPtr(hdpaSubItems
, i
);
4429 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
4432 DPA_Destroy(hdpaSubItems
);
4435 if (uView
== LVS_SMALLICON
|| uView
== LVS_ICON
)
4437 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
4438 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
4441 infoPtr
->nItemCount
--;
4442 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
4444 /* now is the invalidation fun */
4445 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
4452 * Callback implementation for editlabel control
4455 * [I] infoPtr : valid pointer to the listview structure
4456 * [I] pszText : modified text
4457 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
4463 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, LPWSTR pszText
, BOOL isW
)
4465 NMLVDISPINFOW dispInfo
;
4467 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
4469 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4470 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4471 dispInfo
.item
.iItem
= infoPtr
->nEditLabelItem
;
4472 dispInfo
.item
.iSubItem
= 0;
4473 dispInfo
.item
.stateMask
= ~0;
4474 if (!LISTVIEW_GetItemW(infoPtr
, &dispInfo
.item
)) return FALSE
;
4475 /* add the text from the edit in */
4476 dispInfo
.item
.mask
|= LVIF_TEXT
;
4477 dispInfo
.item
.pszText
= pszText
;
4478 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
4480 /* Do we need to update the Item Text */
4481 if (!notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
)) return FALSE
;
4482 if (!pszText
) return TRUE
;
4484 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4485 dispInfo
.item
.mask
= LVIF_TEXT
;
4486 dispInfo
.item
.iItem
= infoPtr
->nEditLabelItem
;
4487 dispInfo
.item
.iSubItem
= 0;
4488 dispInfo
.item
.pszText
= pszText
;
4489 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
4490 return LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
4495 * Begin in place editing of specified list view item
4498 * [I] infoPtr : valid pointer to the listview structure
4499 * [I] nItem : item index
4500 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
4506 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
4508 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
4509 NMLVDISPINFOW dispInfo
;
4512 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
4514 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
4515 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
4517 infoPtr
->nEditLabelItem
= nItem
;
4519 /* Is the EditBox still there, if so remove it */
4520 if(infoPtr
->hwndEdit
!= 0)
4522 SetFocus(infoPtr
->hwndSelf
);
4523 infoPtr
->hwndEdit
= 0;
4526 LISTVIEW_SetSelection(infoPtr
, nItem
);
4527 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
4528 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
4530 rect
.left
= LVIR_LABEL
;
4531 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
4533 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4534 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
4535 dispInfo
.item
.iItem
= nItem
;
4536 dispInfo
.item
.iSubItem
= 0;
4537 dispInfo
.item
.stateMask
= ~0;
4538 dispInfo
.item
.pszText
= szDispText
;
4539 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
4540 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
4542 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, WS_VISIBLE
,
4543 rect
.left
-2, rect
.top
-1, 0, rect
.bottom
- rect
.top
+2, isW
);
4544 if (!infoPtr
->hwndEdit
) return 0;
4546 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
4548 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
4549 infoPtr
->hwndEdit
= 0;
4553 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
4554 SetFocus(infoPtr
->hwndEdit
);
4555 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
4556 return infoPtr
->hwndEdit
;
4562 * Ensures the specified item is visible, scrolling into view if necessary.
4565 * [I] infoPtr : valid pointer to the listview structure
4566 * [I] nItem : item index
4567 * [I] bPartial : partially or entirely visible
4573 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
4575 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4576 INT nScrollPosHeight
= 0;
4577 INT nScrollPosWidth
= 0;
4578 INT nHorzAdjust
= 0;
4579 INT nVertAdjust
= 0;
4582 RECT rcItem
, rcTemp
;
4584 rcItem
.left
= LVIR_BOUNDS
;
4585 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
4587 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
4589 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
4591 /* scroll left/right, but in LVS_REPORT mode */
4592 if (uView
== LVS_LIST
)
4593 nScrollPosWidth
= infoPtr
->nItemWidth
;
4594 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
4595 nScrollPosWidth
= 1;
4597 if (rcItem
.left
< infoPtr
->rcList
.left
)
4600 if (uView
!= LVS_REPORT
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
4605 if (uView
!= LVS_REPORT
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
4609 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
4611 /* scroll up/down, but not in LVS_LIST mode */
4612 if (uView
== LVS_REPORT
)
4613 nScrollPosHeight
= infoPtr
->nItemHeight
;
4614 else if ((uView
== LVS_ICON
) || (uView
== LVS_SMALLICON
))
4615 nScrollPosHeight
= 1;
4617 if (rcItem
.top
< infoPtr
->rcList
.top
)
4620 if (uView
!= LVS_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
4625 if (uView
!= LVS_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
4629 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
4631 if (nScrollPosWidth
)
4633 INT diff
= nHorzDiff
/ nScrollPosWidth
;
4634 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
4635 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
4638 if (nScrollPosHeight
)
4640 INT diff
= nVertDiff
/ nScrollPosHeight
;
4641 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
4642 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
4650 * Searches for an item with specific characteristics.
4653 * [I] hwnd : window handle
4654 * [I] nStart : base item index
4655 * [I] lpFindInfo : item information to look for
4658 * SUCCESS : index of item
4661 static INT
LISTVIEW_FindItemW(LISTVIEW_INFO
*infoPtr
, INT nStart
,
4662 const LVFINDINFOW
*lpFindInfo
)
4664 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4665 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4666 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
4667 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
4668 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
4669 POINT Position
, Destination
;
4672 if (!lpFindInfo
|| nItem
< 0) return -1;
4675 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
))
4677 lvItem
.mask
|= LVIF_TEXT
;
4678 lvItem
.pszText
= szDispText
;
4679 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4682 if (lpFindInfo
->flags
& LVFI_WRAP
)
4685 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
4686 (uView
== LVS_ICON
|| uView
==LVS_SMALLICON
))
4691 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4692 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
4693 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
4694 switch(lpFindInfo
->vkDirection
)
4696 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
4697 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
4698 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
4699 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
4700 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
4701 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
4702 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
4704 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
4705 Destination
.x
= rcArea
.right
;
4706 Destination
.y
= rcArea
.bottom
;
4708 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
4713 /* if LVFI_PARAM is specified, all other flags are ignored */
4714 if (lpFindInfo
->flags
& LVFI_PARAM
)
4716 lvItem
.mask
|= LVIF_PARAM
;
4718 lvItem
.mask
&= ~LVIF_TEXT
;
4722 for (; nItem
< nLast
; nItem
++)
4724 lvItem
.iItem
= nItem
;
4725 lvItem
.iSubItem
= 0;
4726 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
4728 if (lvItem
.mask
& LVIF_PARAM
)
4730 if (lpFindInfo
->lParam
== lvItem
.lParam
)
4736 if (lvItem
.mask
& LVIF_TEXT
)
4738 if (lpFindInfo
->flags
& LVFI_PARTIAL
)
4740 if (strstrW(lvItem
.pszText
, lpFindInfo
->psz
) == NULL
) continue;
4744 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
4748 if (!bNearest
) return nItem
;
4750 /* This is very inefficient. To do a good job here,
4751 * we need a sorted array of (x,y) item positions */
4752 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
4754 /* compute the distance^2 to the destination */
4755 xdist
= Destination
.x
- Position
.x
;
4756 ydist
= Destination
.y
- Position
.y
;
4757 dist
= xdist
* xdist
+ ydist
* ydist
;
4759 /* remember the distance, and item if it's closer */
4763 nNearestItem
= nItem
;
4770 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
4775 return nNearestItem
;
4780 * Searches for an item with specific characteristics.
4783 * [I] hwnd : window handle
4784 * [I] nStart : base item index
4785 * [I] lpFindInfo : item information to look for
4788 * SUCCESS : index of item
4791 static INT
LISTVIEW_FindItemA(LISTVIEW_INFO
*infoPtr
, INT nStart
,
4792 const LVFINDINFOA
*lpFindInfo
)
4794 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
);
4798 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
4799 if (hasText
) fiw
.psz
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
4800 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
4801 if (hasText
) textfreeT((LPWSTR
)fiw
.psz
, FALSE
);
4807 * Retrieves the background image of the listview control.
4810 * [I] infoPtr : valid pointer to the listview structure
4811 * [O] lpBkImage : background image attributes
4817 /* static BOOL LISTVIEW_GetBkImage(LISTVIEW_INFO *infoPtr, LPLVBKIMAGE lpBkImage) */
4819 /* FIXME (listview, "empty stub!\n"); */
4825 * Retrieves column attributes.
4828 * [I] infoPtr : valid pointer to the listview structure
4829 * [I] nColumn : column index
4830 * [IO] lpColumn : column information
4831 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
4832 * otherwise it is in fact a LPLVCOLUMNA
4838 static BOOL
LISTVIEW_GetColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
4840 COLUMN_INFO
*lpColumnInfo
;
4843 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4844 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
4846 /* initialize memory */
4847 ZeroMemory(&hdi
, sizeof(hdi
));
4849 if (lpColumn
->mask
& LVCF_TEXT
)
4851 hdi
.mask
|= HDI_TEXT
;
4852 hdi
.pszText
= lpColumn
->pszText
;
4853 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
4856 if (lpColumn
->mask
& LVCF_IMAGE
)
4857 hdi
.mask
|= HDI_IMAGE
;
4859 if (lpColumn
->mask
& LVCF_ORDER
)
4860 hdi
.mask
|= HDI_ORDER
;
4862 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
4864 if (lpColumn
->mask
& LVCF_FMT
)
4865 lpColumn
->fmt
= lpColumnInfo
->fmt
;
4867 if (lpColumn
->mask
& LVCF_WIDTH
)
4868 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
4870 if (lpColumn
->mask
& LVCF_IMAGE
)
4871 lpColumn
->iImage
= hdi
.iImage
;
4873 if (lpColumn
->mask
& LVCF_ORDER
)
4874 lpColumn
->iOrder
= hdi
.iOrder
;
4880 static BOOL
LISTVIEW_GetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
4887 /* FIXME: little hack */
4888 for (i
= 0; i
< iCount
; i
++)
4896 * Retrieves the column width.
4899 * [I] infoPtr : valid pointer to the listview structure
4900 * [I] int : column index
4903 * SUCCESS : column width
4906 static INT
LISTVIEW_GetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
4908 INT nColumnWidth
= 0;
4911 TRACE("nColumn=%d\n", nColumn
);
4913 /* we have a 'column' in LIST and REPORT mode only */
4914 switch(infoPtr
->dwStyle
& LVS_TYPEMASK
)
4917 nColumnWidth
= infoPtr
->nItemWidth
;
4920 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
4921 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
4922 nColumnWidth
= rcHeader
.right
- rcHeader
.left
;
4926 TRACE("nColumnWidth=%d\n", nColumnWidth
);
4927 return nColumnWidth
;
4932 * In list or report display mode, retrieves the number of items that can fit
4933 * vertically in the visible area. In icon or small icon display mode,
4934 * retrieves the total number of visible items.
4937 * [I] infoPtr : valid pointer to the listview structure
4940 * Number of fully visible items.
4942 static INT
LISTVIEW_GetCountPerPage(LISTVIEW_INFO
*infoPtr
)
4944 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
4948 return infoPtr
->nItemCount
;
4950 return LISTVIEW_GetCountPerColumn(infoPtr
);
4952 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
4960 * Retrieves an image list handle.
4963 * [I] infoPtr : valid pointer to the listview structure
4964 * [I] nImageList : image list identifier
4967 * SUCCESS : image list handle
4970 static HIMAGELIST
LISTVIEW_GetImageList(LISTVIEW_INFO
*infoPtr
, INT nImageList
)
4974 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
4975 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
4976 case LVSIL_STATE
: return infoPtr
->himlState
;
4981 /* LISTVIEW_GetISearchString */
4985 * Retrieves item attributes.
4988 * [I] hwnd : window handle
4989 * [IO] lpLVItem : item info
4990 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
4991 * if FALSE, the lpLVItem is a LPLVITEMA.
4994 * This is the internal 'GetItem' interface -- it tries to
4995 * be smart, and avoids text copies, if possible, by modifing
4996 * lpLVItem->pszText to point to the text string. Please note
4997 * that this is not always possible (e.g. OWNERDATA), so on
4998 * entry you *must* supply valid values for pszText, and cchTextMax.
4999 * The only difference to the documented interface is that upon
5000 * return, you should use *only* the lpLVItem->pszText, rather than
5001 * the buffer pointer you provided on input. Most code already does
5002 * that, so it's not a problem.
5003 * For the two cases when the text must be copied (that is,
5004 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
5010 static BOOL
LISTVIEW_GetItemT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
5012 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
5013 NMLVDISPINFOW dispInfo
;
5019 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
5021 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
5024 if (lpLVItem
->mask
== 0) return TRUE
;
5026 /* make a local copy */
5027 isubitem
= lpLVItem
->iSubItem
;
5029 /* a quick optimization if all we're asked is the focus state
5030 * these queries are worth optimising since they are common,
5031 * and can be answered in constant time, without the heavy accesses */
5032 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
5033 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
5035 lpLVItem
->state
= 0;
5036 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5037 lpLVItem
->state
|= LVIS_FOCUSED
;
5041 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5043 /* if the app stores all the data, handle it separately */
5044 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5046 dispInfo
.item
.state
= 0;
5048 /* apprently, we should not callback for lParam in LVS_OWNERDATA */
5049 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) || infoPtr
->uCallbackMask
)
5051 /* NOTE: copy only fields which we _know_ are initialized, some apps
5052 * depend on the uninitialized fields being 0 */
5053 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
5054 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
5055 dispInfo
.item
.iSubItem
= isubitem
;
5056 if (lpLVItem
->mask
& LVIF_TEXT
)
5058 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
5059 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
5061 if (lpLVItem
->mask
& LVIF_STATE
)
5062 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
5063 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
5064 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
5065 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
5067 /* full size structure expected - _WIN32IE >= 0x560 */
5068 *lpLVItem
= dispInfo
.item
;
5070 else if (lpLVItem
->mask
& LVIF_INDENT
)
5072 /* indent member expected - _WIN32IE >= 0x300 */
5073 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
5077 /* minimal structure expected */
5078 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
5080 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
5083 /* make sure lParam is zeroed out */
5084 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
5086 /* we store only a little state, so if we're not asked, we're done */
5087 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
5089 /* if focus is handled by us, report it */
5090 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
5092 lpLVItem
->state
&= ~LVIS_FOCUSED
;
5093 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5094 lpLVItem
->state
|= LVIS_FOCUSED
;
5097 /* and do the same for selection, if we handle it */
5098 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
5100 lpLVItem
->state
&= ~LVIS_SELECTED
;
5101 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
5102 lpLVItem
->state
|= LVIS_SELECTED
;
5108 /* find the item and subitem structures before we proceed */
5109 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
5110 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
5115 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
5116 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
5119 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
5124 pItemHdr
= &lpItem
->hdr
;
5126 /* Do we need to query the state from the app? */
5127 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
5129 dispInfo
.item
.mask
|= LVIF_STATE
;
5130 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
5133 /* Do we need to enquire about the image? */
5134 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
5135 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
5137 dispInfo
.item
.mask
|= LVIF_IMAGE
;
5138 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
5141 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
5142 if ((lpLVItem
->mask
& LVIF_TEXT
) && !is_textW(pItemHdr
->pszText
))
5144 dispInfo
.item
.mask
|= LVIF_TEXT
;
5145 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
5146 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
5147 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
5148 *dispInfo
.item
.pszText
= '\0';
5151 /* If we don't have all the requested info, query the application */
5152 if (dispInfo
.item
.mask
!= 0)
5154 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
5155 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
5156 dispInfo
.item
.lParam
= lpItem
->lParam
;
5157 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
5158 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
5161 /* we should not store values for subitems */
5162 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
5164 /* Now, handle the iImage field */
5165 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
5167 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
5168 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
5169 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
5171 else if (lpLVItem
->mask
& LVIF_IMAGE
)
5173 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
5174 lpLVItem
->iImage
= pItemHdr
->iImage
;
5176 lpLVItem
->iImage
= 0;
5179 /* The pszText field */
5180 if (dispInfo
.item
.mask
& LVIF_TEXT
)
5182 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
5183 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
5185 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
5187 else if (lpLVItem
->mask
& LVIF_TEXT
)
5189 if (isW
) lpLVItem
->pszText
= pItemHdr
->pszText
;
5190 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
5193 /* if this is a subitem, we're done */
5194 if (isubitem
) return TRUE
;
5196 /* Next is the lParam field */
5197 if (dispInfo
.item
.mask
& LVIF_PARAM
)
5199 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
5200 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
5201 lpItem
->lParam
= dispInfo
.item
.lParam
;
5203 else if (lpLVItem
->mask
& LVIF_PARAM
)
5204 lpLVItem
->lParam
= lpItem
->lParam
;
5206 /* ... the state field (this one is different due to uCallbackmask) */
5207 if (lpLVItem
->mask
& LVIF_STATE
)
5209 lpLVItem
->state
= lpItem
->state
;
5210 if (dispInfo
.item
.mask
& LVIF_STATE
)
5212 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
5213 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
5215 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
5217 lpLVItem
->state
&= ~LVIS_FOCUSED
;
5218 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5219 lpLVItem
->state
|= LVIS_FOCUSED
;
5221 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
5223 lpLVItem
->state
&= ~LVIS_SELECTED
;
5224 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
5225 lpLVItem
->state
|= LVIS_SELECTED
;
5229 /* and last, but not least, the indent field */
5230 if (lpLVItem
->mask
& LVIF_INDENT
)
5231 lpLVItem
->iIndent
= lpItem
->iIndent
;
5238 * Retrieves item attributes.
5241 * [I] hwnd : window handle
5242 * [IO] lpLVItem : item info
5243 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
5244 * if FALSE, the lpLVItem is a LPLVITEMA.
5247 * This is the external 'GetItem' interface -- it properly copies
5248 * the text in the provided buffer.
5254 static BOOL
LISTVIEW_GetItemExtT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
5259 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
5262 pszText
= lpLVItem
->pszText
;
5263 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
5264 if (bResult
&& lpLVItem
->pszText
!= pszText
)
5265 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
5266 lpLVItem
->pszText
= pszText
;
5274 * Retrieves the position (upper-left) of the listview control item.
5275 * Note that for LVS_ICON style, the upper-left is that of the icon
5276 * and not the bounding box.
5279 * [I] infoPtr : valid pointer to the listview structure
5280 * [I] nItem : item index
5281 * [O] lpptPosition : coordinate information
5287 static BOOL
LISTVIEW_GetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
5289 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5292 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
5294 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5296 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5297 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
5299 if (uView
== LVS_ICON
)
5301 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
5302 lpptPosition
->y
+= ICON_TOP_PADDING
;
5304 lpptPosition
->x
+= Origin
.x
;
5305 lpptPosition
->y
+= Origin
.y
;
5307 TRACE (" lpptPosition=%s\n", debugpoint(lpptPosition
));
5314 * Retrieves the bounding rectangle for a listview control item.
5317 * [I] infoPtr : valid pointer to the listview structure
5318 * [I] nItem : item index
5319 * [IO] lprc : bounding rectangle coordinates
5320 * lprc->left specifies the portion of the item for which the bounding
5321 * rectangle will be retrieved.
5323 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
5324 * including the icon and label.
5327 * * Experiment shows that native control returns:
5328 * * width = min (48, length of text line)
5329 * * .left = position.x - (width - iconsize.cx)/2
5330 * * .right = .left + width
5331 * * height = #lines of text * ntmHeight + icon height + 8
5332 * * .top = position.y - 2
5333 * * .bottom = .top + height
5334 * * separation between items .y = itemSpacing.cy - height
5335 * * .x = itemSpacing.cx - width
5336 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
5339 * * Experiment shows that native control returns:
5340 * * width = iconSize.cx + 16
5341 * * .left = position.x - (width - iconsize.cx)/2
5342 * * .right = .left + width
5343 * * height = iconSize.cy + 4
5344 * * .top = position.y - 2
5345 * * .bottom = .top + height
5346 * * separation between items .y = itemSpacing.cy - height
5347 * * .x = itemSpacing.cx - width
5348 * LVIR_LABEL Returns the bounding rectangle of the item text.
5351 * * Experiment shows that native control returns:
5352 * * width = text length
5353 * * .left = position.x - width/2
5354 * * .right = .left + width
5355 * * height = ntmH * linecount + 2
5356 * * .top = position.y + iconSize.cy + 6
5357 * * .bottom = .top + height
5358 * * separation between items .y = itemSpacing.cy - height
5359 * * .x = itemSpacing.cx - width
5360 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
5361 * rectangles, but excludes columns in report view.
5368 * Note that the bounding rectangle of the label in the LVS_ICON view depends
5369 * upon whether the window has the focus currently and on whether the item
5370 * is the one with the focus. Ensure that the control's record of which
5371 * item has the focus agrees with the items' records.
5373 static BOOL
LISTVIEW_GetItemRect(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
5375 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5376 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5377 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
5378 POINT Position
, Origin
;
5382 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
5384 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5386 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5387 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
5389 /* Be smart and try to figure out the minimum we have to do */
5390 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
5391 if (uView
== LVS_REPORT
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
5392 if (uView
== LVS_ICON
&& lprc
->left
!= LVIR_ICON
&&
5393 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
5394 oversizedBox
= TRUE
;
5396 /* get what we need from the item before hand, so we make
5397 * only one request. This can speed up things, if data
5398 * is stored on the app side */
5400 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
5401 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
5402 lvItem
.iItem
= nItem
;
5403 lvItem
.iSubItem
= 0;
5404 lvItem
.pszText
= szDispText
;
5405 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5406 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
5407 /* we got the state already up, simulate it here, to avoid a reget */
5408 if (uView
== LVS_ICON
&& (lprc
->left
!= LVIR_ICON
))
5410 lvItem
.mask
|= LVIF_STATE
;
5411 lvItem
.stateMask
= LVIS_FOCUSED
;
5412 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
5415 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
5416 lprc
->left
= LVIR_BOUNDS
;
5420 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
);
5424 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, lprc
);
5428 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
);
5431 case LVIR_SELECTBOUNDS
:
5432 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, &label_rect
);
5433 UnionRect(lprc
, lprc
, &label_rect
);
5437 WARN("Unknown value: %ld\n", lprc
->left
);
5441 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
5443 TRACE(" rect=%s\n", debugrect(lprc
));
5450 * Retrieves the spacing between listview control items.
5453 * [I] infoPtr : valid pointer to the listview structure
5454 * [IO] lprc : rectangle to receive the output
5455 * on input, lprc->top = nSubItem
5456 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
5458 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
5459 * not only those of the first column.
5460 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
5466 static BOOL
LISTVIEW_GetSubItemRect(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
5471 if (!lprc
) return FALSE
;
5473 TRACE("(nItem=%d, nSubItem=%ld)\n", nItem
, lprc
->top
);
5474 /* On WinNT, a subitem of '0' calls LISTVIEW_GetItemRect */
5476 return LISTVIEW_GetItemRect(infoPtr
, nItem
, lprc
);
5478 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) != LVS_REPORT
) return FALSE
;
5480 if (!LISTVIEW_GetItemPosition(infoPtr
, nItem
, &Position
)) return FALSE
;
5483 lvItem
.iItem
= nItem
;
5484 lvItem
.iSubItem
= lprc
->top
;
5486 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
5490 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
);
5495 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
);
5499 ERR("Unknown bounds=%ld\n", lprc
->left
);
5503 OffsetRect(lprc
, Position
.x
, Position
.y
);
5510 * Retrieves the width of a label.
5513 * [I] infoPtr : valid pointer to the listview structure
5516 * SUCCESS : string width (in pixels)
5519 static INT
LISTVIEW_GetLabelWidth(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5521 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5524 TRACE("(nItem=%d)\n", nItem
);
5526 lvItem
.mask
= LVIF_TEXT
;
5527 lvItem
.iItem
= nItem
;
5528 lvItem
.iSubItem
= 0;
5529 lvItem
.pszText
= szDispText
;
5530 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5531 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
5533 return LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
5538 * Retrieves the spacing between listview control items.
5541 * [I] infoPtr : valid pointer to the listview structure
5542 * [I] bSmall : flag for small or large icon
5545 * Horizontal + vertical spacing
5547 static LONG
LISTVIEW_GetItemSpacing(LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
5553 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
5557 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_ICON
)
5558 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
5560 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
5567 * Retrieves the state of a listview control item.
5570 * [I] infoPtr : valid pointer to the listview structure
5571 * [I] nItem : item index
5572 * [I] uMask : state mask
5575 * State specified by the mask.
5577 static UINT
LISTVIEW_GetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
5581 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5583 lvItem
.iItem
= nItem
;
5584 lvItem
.iSubItem
= 0;
5585 lvItem
.mask
= LVIF_STATE
;
5586 lvItem
.stateMask
= uMask
;
5587 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
5589 return lvItem
.state
& uMask
;
5594 * Retrieves the text of a listview control item or subitem.
5597 * [I] hwnd : window handle
5598 * [I] nItem : item index
5599 * [IO] lpLVItem : item information
5600 * [I] isW : TRUE if lpLVItem is Unicode
5603 * SUCCESS : string length
5606 static INT
LISTVIEW_GetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
5608 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5610 lpLVItem
->mask
= LVIF_TEXT
;
5611 lpLVItem
->iItem
= nItem
;
5612 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
5614 return textlenT(lpLVItem
->pszText
, isW
);
5619 * Searches for an item based on properties + relationships.
5622 * [I] infoPtr : valid pointer to the listview structure
5623 * [I] nItem : item index
5624 * [I] uFlags : relationship flag
5627 * SUCCESS : item index
5630 static INT
LISTVIEW_GetNextItem(LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
5632 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5634 LVFINDINFOW lvFindInfo
;
5635 INT nCountPerColumn
;
5639 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
5640 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
5642 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
5644 if (uFlags
& LVNI_CUT
)
5647 if (uFlags
& LVNI_DROPHILITED
)
5648 uMask
|= LVIS_DROPHILITED
;
5650 if (uFlags
& LVNI_FOCUSED
)
5651 uMask
|= LVIS_FOCUSED
;
5653 if (uFlags
& LVNI_SELECTED
)
5654 uMask
|= LVIS_SELECTED
;
5656 /* if we're asked for the focused item, that's only one,
5657 * so it's worth optimizing */
5658 if (uFlags
& LVNI_FOCUSED
)
5660 if (!(LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) == uMask
) return -1;
5661 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
5664 if (uFlags
& LVNI_ABOVE
)
5666 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
5671 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5677 /* Special case for autoarrange - move 'til the top of a list */
5678 if (is_autoarrange(infoPtr
))
5680 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
5681 while (nItem
- nCountPerRow
>= 0)
5683 nItem
-= nCountPerRow
;
5684 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5689 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5690 lvFindInfo
.vkDirection
= VK_UP
;
5691 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5692 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5694 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5699 else if (uFlags
& LVNI_BELOW
)
5701 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
5703 while (nItem
< infoPtr
->nItemCount
)
5706 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5712 /* Special case for autoarrange - move 'til the bottom of a list */
5713 if (is_autoarrange(infoPtr
))
5715 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
5716 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
5718 nItem
+= nCountPerRow
;
5719 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5724 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5725 lvFindInfo
.vkDirection
= VK_DOWN
;
5726 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5727 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5729 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5734 else if (uFlags
& LVNI_TOLEFT
)
5736 if (uView
== LVS_LIST
)
5738 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
5739 while (nItem
- nCountPerColumn
>= 0)
5741 nItem
-= nCountPerColumn
;
5742 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5746 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5748 /* Special case for autoarrange - move 'ti the beginning of a row */
5749 if (is_autoarrange(infoPtr
))
5751 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
5752 while (nItem
% nCountPerRow
> 0)
5755 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5760 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5761 lvFindInfo
.vkDirection
= VK_LEFT
;
5762 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5763 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5765 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5770 else if (uFlags
& LVNI_TORIGHT
)
5772 if (uView
== LVS_LIST
)
5774 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
5775 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
5777 nItem
+= nCountPerColumn
;
5778 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5782 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5784 /* Special case for autoarrange - move 'til the end of a row */
5785 if (is_autoarrange(infoPtr
))
5787 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
5788 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
5791 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5796 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5797 lvFindInfo
.vkDirection
= VK_RIGHT
;
5798 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5799 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5801 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5810 /* search by index */
5811 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
5813 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
5821 /* LISTVIEW_GetNumberOfWorkAreas */
5825 * Retrieves the origin coordinates when in icon or small icon display mode.
5828 * [I] infoPtr : valid pointer to the listview structure
5829 * [O] lpptOrigin : coordinate information
5834 static void LISTVIEW_GetOrigin(LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
5836 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5837 INT nHorzPos
= 0, nVertPos
= 0;
5838 SCROLLINFO scrollInfo
;
5840 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
5841 scrollInfo
.fMask
= SIF_POS
;
5843 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
5844 nHorzPos
= scrollInfo
.nPos
;
5845 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
5846 nVertPos
= scrollInfo
.nPos
;
5848 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
5850 lpptOrigin
->x
= infoPtr
->rcList
.left
;
5851 lpptOrigin
->y
= infoPtr
->rcList
.top
;
5852 if (uView
== LVS_LIST
)
5853 nHorzPos
*= infoPtr
->nItemWidth
;
5854 else if (uView
== LVS_REPORT
)
5855 nVertPos
*= infoPtr
->nItemHeight
;
5857 lpptOrigin
->x
-= nHorzPos
;
5858 lpptOrigin
->y
-= nVertPos
;
5860 TRACE(" origin=%s\n", debugpoint(lpptOrigin
));
5865 * Retrieves the width of a string.
5868 * [I] hwnd : window handle
5869 * [I] lpszText : text string to process
5870 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
5873 * SUCCESS : string width (in pixels)
5876 static INT
LISTVIEW_GetStringWidthT(LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
5881 if (is_textT(lpszText
, isW
))
5883 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
5884 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
5885 HFONT hOldFont
= SelectObject(hdc
, hFont
);
5888 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
5890 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
5891 SelectObject(hdc
, hOldFont
);
5892 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
5894 return stringSize
.cx
;
5899 * Determines which listview item is located at the specified position.
5902 * [I] infoPtr : valid pointer to the listview structure
5903 * [IO] lpht : hit test information
5904 * [I] subitem : fill out iSubItem.
5905 * [I] select : return the index only if the hit selects the item
5908 * (mm 20001022): We must not allow iSubItem to be touched, for
5909 * an app might pass only a structure with space up to iItem!
5910 * (MS Office 97 does that for instance in the file open dialog)
5913 * SUCCESS : item index
5916 static INT
LISTVIEW_HitTest(LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
5918 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5919 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5920 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
5921 POINT Origin
, Position
, opt
;
5926 TRACE("(pt=%s, subitem=%d, select=%d)\n", debugpoint(&lpht
->pt
), subitem
, select
);
5930 if (subitem
) lpht
->iSubItem
= 0;
5932 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
5933 lpht
->flags
|= LVHT_TOLEFT
;
5934 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
5935 lpht
->flags
|= LVHT_TORIGHT
;
5937 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
5938 lpht
->flags
|= LVHT_ABOVE
;
5939 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
5940 lpht
->flags
|= LVHT_BELOW
;
5942 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
5943 if (lpht
->flags
) return -1;
5945 lpht
->flags
|= LVHT_NOWHERE
;
5947 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5949 /* first deal with the large items */
5950 rcSearch
.left
= lpht
->pt
.x
;
5951 rcSearch
.top
= lpht
->pt
.y
;
5952 rcSearch
.right
= rcSearch
.left
+ 1;
5953 rcSearch
.bottom
= rcSearch
.top
+ 1;
5955 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
5956 iterator_next(&i
); /* go to first item in the sequence */
5958 iterator_destroy(&i
);
5960 TRACE("lpht->iItem=%d\n", iItem
);
5961 if (iItem
== -1) return -1;
5963 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
5964 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
5965 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
5966 if (uView
== LVS_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
5967 lvItem
.iItem
= iItem
;
5968 lvItem
.iSubItem
= 0;
5969 lvItem
.pszText
= szDispText
;
5970 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5971 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
5972 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
5974 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcState
, &rcIcon
, &rcLabel
);
5975 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
5976 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
5977 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
5979 if (uView
== LVS_REPORT
)
5982 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
5983 TRACE("rcBounds=%s\n", debugrect(&rcBounds
));
5984 if (!PtInRect(&rcBounds
, opt
)) return -1;
5986 if (PtInRect(&rcIcon
, opt
))
5987 lpht
->flags
|= LVHT_ONITEMICON
;
5988 else if (PtInRect(&rcLabel
, opt
))
5989 lpht
->flags
|= LVHT_ONITEMLABEL
;
5990 else if (infoPtr
->himlState
&& ((lvItem
.state
& LVIS_STATEIMAGEMASK
) >> 12) && PtInRect(&rcState
, opt
))
5991 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
5992 if (lpht
->flags
& LVHT_ONITEM
)
5993 lpht
->flags
&= ~LVHT_NOWHERE
;
5995 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
5996 if (uView
== LVS_REPORT
&& subitem
)
6000 rcBounds
.right
= rcBounds
.left
;
6001 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
6003 rcBounds
.left
= rcBounds
.right
;
6004 rcBounds
.right
+= LISTVIEW_GetColumnWidth(infoPtr
, j
);
6005 if (PtInRect(&rcBounds
, opt
))
6013 if (select
&& !(uView
== LVS_REPORT
&&
6014 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
6015 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
6017 if (uView
== LVS_REPORT
)
6019 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
6020 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
6022 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
6024 return lpht
->iItem
= iItem
;
6028 /* LISTVIEW_InsertCompare: callback routine for comparing pszText members of the LV_ITEMS
6029 in a LISTVIEW on insert. Passed to DPA_Sort in LISTVIEW_InsertItem.
6030 This function should only be used for inserting items into a sorted list (LVM_INSERTITEM)
6031 and not during the processing of a LVM_SORTITEMS message. Applications should provide
6032 their own sort proc. when sending LVM_SORTITEMS.
6035 (remarks on LVITEM: LVM_INSERTITEM will insert the new item in the proper sort postion...
6037 LVS_SORTXXX must be specified,
6038 LVS_OWNERDRAW is not set,
6039 <item>.pszText is not LPSTR_TEXTCALLBACK.
6041 (LVS_SORT* flags): "For the LVS_SORTASCENDING... styles, item indices
6042 are sorted based on item text..."
6044 static INT WINAPI
LISTVIEW_InsertCompare( LPVOID first
, LPVOID second
, LPARAM lParam
)
6046 ITEM_INFO
* lv_first
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)first
, 0 );
6047 ITEM_INFO
* lv_second
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)second
, 0 );
6048 INT cmpv
= textcmpWT(lv_first
->hdr
.pszText
, lv_second
->hdr
.pszText
, TRUE
);
6050 /* if we're sorting descending, negate the return value */
6051 return (((LISTVIEW_INFO
*)lParam
)->dwStyle
& LVS_SORTDESCENDING
) ? -cmpv
: cmpv
;
6056 * Inserts a new item in the listview control.
6059 * [I] infoPtr : valid pointer to the listview structure
6060 * [I] lpLVItem : item information
6061 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
6064 * SUCCESS : new item index
6067 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
6069 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6074 BOOL is_sorted
, has_changed
;
6077 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6079 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
6081 /* make sure it's an item, and not a subitem; cannot insert a subitem */
6082 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iSubItem
) return -1;
6084 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
6086 if (!(lpItem
= (ITEM_INFO
*)Alloc(sizeof(ITEM_INFO
)))) return -1;
6088 /* insert item in listview control data structure */
6089 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
6090 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
6092 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
6093 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
6095 nItem
= is_sorted
? infoPtr
->nItemCount
: min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
6096 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
6097 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
6098 if (nItem
== -1) goto fail
;
6099 infoPtr
->nItemCount
++;
6101 /* shift indices first so they don't get tangled */
6102 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
6104 /* set the item attributes */
6105 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6107 /* full size structure expected - _WIN32IE >= 0x560 */
6110 else if (lpLVItem
->mask
& LVIF_INDENT
)
6112 /* indent member expected - _WIN32IE >= 0x300 */
6113 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
6117 /* minimal structure expected */
6118 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
6121 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) item
.state
&= ~LVIS_STATEIMAGEMASK
;
6122 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
6124 /* if we're sorted, sort the list, and update the index */
6127 DPA_Sort( infoPtr
->hdpaItems
, LISTVIEW_InsertCompare
, (LPARAM
)infoPtr
);
6128 nItem
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, hdpaSubItems
);
6129 assert(nItem
!= -1);
6132 /* make room for the position, if we are in the right mode */
6133 if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
6135 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
6137 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
6139 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
6144 /* send LVN_INSERTITEM notification */
6145 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
6147 nmlv
.lParam
= lpItem
->lParam
;
6148 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
6150 /* align items (set position of each item) */
6151 if ((uView
== LVS_SMALLICON
|| uView
== LVS_ICON
))
6155 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
6156 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
6158 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
6160 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
6163 /* now is the invalidation fun */
6164 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
6168 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
6169 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
6170 infoPtr
->nItemCount
--;
6172 DPA_DeletePtr(hdpaSubItems
, 0);
6173 DPA_Destroy (hdpaSubItems
);
6180 * Redraws a range of items.
6183 * [I] infoPtr : valid pointer to the listview structure
6184 * [I] nFirst : first item
6185 * [I] nLast : last item
6191 static BOOL
LISTVIEW_RedrawItems(LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
6195 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
6196 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
6199 for (i
= nFirst
; i
<= nLast
; i
++)
6200 LISTVIEW_InvalidateItem(infoPtr
, i
);
6207 * Scroll the content of a listview.
6210 * [I] infoPtr : valid pointer to the listview structure
6211 * [I] dx : horizontal scroll amount in pixels
6212 * [I] dy : vertical scroll amount in pixels
6219 * If the control is in report mode (LVS_REPORT) the control can
6220 * be scrolled only in line increments. "dy" will be rounded to the
6221 * nearest number of pixels that are a whole line. Ex: if line height
6222 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
6223 * is passed the the scroll will be 0. (per MSDN 7/2002)
6225 * For: (per experimentaion with native control and CSpy ListView)
6226 * LVS_ICON dy=1 = 1 pixel (vertical only)
6228 * LVS_SMALLICON dy=1 = 1 pixel (vertical only)
6230 * LVS_LIST dx=1 = 1 column (horizontal only)
6231 * but will only scroll 1 column per message
6232 * no matter what the value.
6233 * dy must be 0 or FALSE returned.
6234 * LVS_REPORT dx=1 = 1 pixel
6238 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
6240 switch(infoPtr
->dwStyle
& LVS_TYPEMASK
) {
6242 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
6243 dy
/= infoPtr
->nItemHeight
;
6246 if (dy
!= 0) return FALSE
;
6253 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
, 0);
6254 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
, 0);
6261 * Sets the background color.
6264 * [I] infoPtr : valid pointer to the listview structure
6265 * [I] clrBk : background color
6271 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrBk
)
6273 TRACE("(clrBk=%lx)\n", clrBk
);
6275 if(infoPtr
->clrBk
!= clrBk
) {
6276 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
6277 infoPtr
->clrBk
= clrBk
;
6278 if (clrBk
== CLR_NONE
)
6279 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
6281 infoPtr
->hBkBrush
= CreateSolidBrush(clrBk
);
6282 LISTVIEW_InvalidateList(infoPtr
);
6288 /* LISTVIEW_SetBkImage */
6290 /*** Helper for {Insert,Set}ColumnT *only* */
6291 static void column_fill_hditem(LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
, const LVCOLUMNW
*lpColumn
, BOOL isW
)
6293 if (lpColumn
->mask
& LVCF_FMT
)
6295 /* format member is valid */
6296 lphdi
->mask
|= HDI_FORMAT
;
6298 /* set text alignment (leftmost column must be left-aligned) */
6299 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
6300 lphdi
->fmt
|= HDF_LEFT
;
6301 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
6302 lphdi
->fmt
|= HDF_RIGHT
;
6303 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
6304 lphdi
->fmt
|= HDF_CENTER
;
6306 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
6307 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
6309 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
6311 lphdi
->fmt
|= HDF_IMAGE
;
6312 lphdi
->iImage
= I_IMAGECALLBACK
;
6316 if (lpColumn
->mask
& LVCF_WIDTH
)
6318 lphdi
->mask
|= HDI_WIDTH
;
6319 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
6321 /* make it fill the remainder of the controls width */
6325 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
6327 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
6328 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
6331 /* retrieve the layout of the header */
6332 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
6333 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, debugrect(&rcHeader
));
6335 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
6338 lphdi
->cxy
= lpColumn
->cx
;
6341 if (lpColumn
->mask
& LVCF_TEXT
)
6343 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
6344 lphdi
->fmt
|= HDF_STRING
;
6345 lphdi
->pszText
= lpColumn
->pszText
;
6346 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
6349 if (lpColumn
->mask
& LVCF_IMAGE
)
6351 lphdi
->mask
|= HDI_IMAGE
;
6352 lphdi
->iImage
= lpColumn
->iImage
;
6355 if (lpColumn
->mask
& LVCF_ORDER
)
6357 lphdi
->mask
|= HDI_ORDER
;
6358 lphdi
->iOrder
= lpColumn
->iOrder
;
6365 * Inserts a new column.
6368 * [I] infoPtr : valid pointer to the listview structure
6369 * [I] nColumn : column index
6370 * [I] lpColumn : column information
6371 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
6374 * SUCCESS : new column index
6377 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
6378 const LVCOLUMNW
*lpColumn
, BOOL isW
)
6380 COLUMN_INFO
*lpColumnInfo
;
6384 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
6386 if (!lpColumn
|| nColumn
< 0) return -1;
6387 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
6389 ZeroMemory(&hdi
, sizeof(HDITEMW
));
6390 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
6392 /* insert item in header control */
6393 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
6394 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
6395 (WPARAM
)nColumn
, (LPARAM
)&hdi
);
6396 if (nNewColumn
== -1) return -1;
6397 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
6399 /* create our own column info */
6400 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
6401 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
6403 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
6404 if (!Header_GetItemRect(infoPtr
->hwndHeader
, nNewColumn
, &lpColumnInfo
->rcHeader
)) goto fail
;
6406 /* now we have to actually adjust the data */
6407 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
6409 SUBITEM_INFO
*lpSubItem
;
6413 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
6415 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
6416 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
6418 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
6419 if (lpSubItem
->iSubItem
>= nNewColumn
)
6420 lpSubItem
->iSubItem
++;
6425 /* make space for the new column */
6426 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
6431 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
6434 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
6442 * Sets the attributes of a header item.
6445 * [I] infoPtr : valid pointer to the listview structure
6446 * [I] nColumn : column index
6447 * [I] lpColumn : column attributes
6448 * [I] isW: if TRUE, the lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
6454 static BOOL
LISTVIEW_SetColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
6455 const LVCOLUMNW
*lpColumn
, BOOL isW
)
6457 HDITEMW hdi
, hdiget
;
6460 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
6462 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6464 ZeroMemory(&hdi
, sizeof(HDITEMW
));
6465 if (lpColumn
->mask
& LVCF_FMT
)
6467 hdi
.mask
|= HDI_FORMAT
;
6468 hdiget
.mask
= HDI_FORMAT
;
6469 if (Header_GetItemW(infoPtr
->hwndHeader
, nColumn
, &hdiget
))
6470 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
6472 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
6474 /* set header item attributes */
6475 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, (WPARAM
)nColumn
, (LPARAM
)&hdi
);
6476 if (!bResult
) return FALSE
;
6478 if (lpColumn
->mask
& LVCF_FMT
)
6480 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6481 int oldFmt
= lpColumnInfo
->fmt
;
6483 lpColumnInfo
->fmt
= lpColumn
->fmt
;
6484 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
6486 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6487 if (uView
== LVS_REPORT
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
6496 * Sets the column order array
6499 * [I] infoPtr : valid pointer to the listview structure
6500 * [I] iCount : number of elements in column order array
6501 * [I] lpiArray : pointer to column order array
6507 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
6509 FIXME("iCount %d lpiArray %p\n", iCount
, lpiArray
);
6520 * Sets the width of a column
6523 * [I] infoPtr : valid pointer to the listview structure
6524 * [I] nColumn : column index
6525 * [I] cx : column width
6531 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
6533 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6534 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
6538 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
6540 /* set column width only if in report or list mode */
6541 if (uView
!= LVS_REPORT
&& uView
!= LVS_LIST
) return FALSE
;
6543 /* take care of invalid cx values */
6544 if(uView
== LVS_REPORT
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
6545 else if (uView
== LVS_LIST
&& cx
< 1) return FALSE
;
6547 /* resize all columns if in LVS_LIST mode */
6548 if(uView
== LVS_LIST
)
6550 infoPtr
->nItemWidth
= cx
;
6551 LISTVIEW_InvalidateList(infoPtr
);
6555 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6557 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
6562 lvItem
.mask
= LVIF_TEXT
;
6564 lvItem
.iSubItem
= nColumn
;
6565 lvItem
.pszText
= szDispText
;
6566 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6567 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
6569 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6570 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
6571 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
6573 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
6574 max_cx
+= infoPtr
->iconSize
.cx
;
6575 max_cx
+= TRAILING_LABEL_PADDING
;
6578 /* autosize based on listview items width */
6579 if(cx
== LVSCW_AUTOSIZE
)
6581 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
6583 /* if iCol is the last column make it fill the remainder of the controls width */
6584 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
6589 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6590 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
6592 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
6596 /* Despite what the MS docs say, if this is not the last
6597 column, then MS resizes the column to the width of the
6598 largest text string in the column, including headers
6599 and items. This is different from LVSCW_AUTOSIZE in that
6600 LVSCW_AUTOSIZE ignores the header string length. */
6603 /* retrieve header text */
6604 hdi
.mask
= HDI_TEXT
;
6605 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
6606 hdi
.pszText
= szDispText
;
6607 if (Header_GetItemW(infoPtr
->hwndHeader
, nColumn
, (LPARAM
)&hdi
))
6609 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
6610 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
6613 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
6614 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
6615 /* FIXME: Take into account the header image, if one is present */
6616 SelectObject(hdc
, old_font
);
6617 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6619 cx
= max (cx
, max_cx
);
6623 if (cx
< 0) return FALSE
;
6625 /* call header to update the column change */
6626 hdi
.mask
= HDI_WIDTH
;
6628 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
6629 return Header_SetItemW(infoPtr
->hwndHeader
, nColumn
, (LPARAM
)&hdi
);
6633 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
6636 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(LISTVIEW_INFO
*infoPtr
)
6639 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
6641 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
6642 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
6645 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
6646 ILC_COLOR
| ILC_MASK
, 2, 2);
6647 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
6648 hdc
= CreateCompatibleDC(hdc_wnd
);
6649 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
6650 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
6651 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
6653 rc
.left
= rc
.top
= 0;
6654 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
6655 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
6657 hbm_orig
= SelectObject(hdc
, hbm_mask
);
6658 FillRect(hdc
, &rc
, hbr_white
);
6659 InflateRect(&rc
, -3, -3);
6660 FillRect(hdc
, &rc
, hbr_black
);
6662 SelectObject(hdc
, hbm_im
);
6663 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
6664 SelectObject(hdc
, hbm_orig
);
6665 ImageList_Add(himl
, hbm_im
, hbm_mask
);
6667 SelectObject(hdc
, hbm_im
);
6668 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
6669 SelectObject(hdc
, hbm_orig
);
6670 ImageList_Add(himl
, hbm_im
, hbm_mask
);
6672 DeleteObject(hbm_mask
);
6673 DeleteObject(hbm_im
);
6681 * Sets the extended listview style.
6684 * [I] infoPtr : valid pointer to the listview structure
6686 * [I] dwStyle : style
6689 * SUCCESS : previous style
6692 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD dwMask
, DWORD dwStyle
)
6694 DWORD dwOldStyle
= infoPtr
->dwLvExStyle
;
6698 infoPtr
->dwLvExStyle
= (dwOldStyle
& ~dwMask
) | (dwStyle
& dwMask
);
6700 infoPtr
->dwLvExStyle
= dwStyle
;
6702 if((infoPtr
->dwLvExStyle
^ dwOldStyle
) & LVS_EX_CHECKBOXES
)
6704 HIMAGELIST himl
= 0;
6705 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
6706 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
6707 LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
6715 * Sets the new hot cursor used during hot tracking and hover selection.
6718 * [I] infoPtr : valid pointer to the listview structure
6719 * [I} hCurosr : the new hot cursor handle
6722 * Returns the previous hot cursor
6724 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
6726 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
6728 infoPtr
->hHotCursor
= hCursor
;
6736 * Sets the hot item index.
6739 * [I] infoPtr : valid pointer to the listview structure
6740 * [I] iIndex : index
6743 * SUCCESS : previous hot item index
6744 * FAILURE : -1 (no hot item)
6746 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
6748 INT iOldIndex
= infoPtr
->nHotItem
;
6750 infoPtr
->nHotItem
= iIndex
;
6758 * Sets the amount of time the cursor must hover over an item before it is selected.
6761 * [I] infoPtr : valid pointer to the listview structure
6762 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
6765 * Returns the previous hover time
6767 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
6769 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
6771 infoPtr
->dwHoverTime
= dwHoverTime
;
6773 return oldHoverTime
;
6778 * Sets spacing for icons of LVS_ICON style.
6781 * [I] infoPtr : valid pointer to the listview structure
6782 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
6783 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
6786 * MAKELONG(oldcx, oldcy)
6788 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
6790 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
6791 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6793 TRACE("requested=(%d,%d)\n", cx
, cy
);
6795 /* this is supported only for LVS_ICON style */
6796 if (uView
!= LVS_ICON
) return oldspacing
;
6798 /* set to defaults, if instructed to */
6799 if (cx
== -1) cx
= GetSystemMetrics(SM_CXICONSPACING
);
6800 if (cy
== -1) cy
= GetSystemMetrics(SM_CYICONSPACING
);
6802 /* if 0 then compute width
6803 * FIXME: Should scan each item and determine max width of
6804 * icon or label, then make that the width */
6806 cx
= infoPtr
->iconSpacing
.cx
;
6808 /* if 0 then compute height */
6810 cy
= infoPtr
->iconSize
.cy
+ 2 * infoPtr
->ntmHeight
+
6811 ICON_BOTTOM_PADDING
+ ICON_TOP_PADDING
+ LABEL_VERT_PADDING
;
6814 infoPtr
->iconSpacing
.cx
= cx
;
6815 infoPtr
->iconSpacing
.cy
= cy
;
6817 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%ld,%ld), ntmH=%d\n",
6818 LOWORD(oldspacing
), HIWORD(oldspacing
), cx
, cy
,
6819 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
6820 infoPtr
->ntmHeight
);
6822 /* these depend on the iconSpacing */
6823 LISTVIEW_UpdateItemSize(infoPtr
);
6828 inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
6832 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
6839 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
6840 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
6849 * [I] infoPtr : valid pointer to the listview structure
6850 * [I] nType : image list type
6851 * [I] himl : image list handle
6854 * SUCCESS : old image list
6857 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
6859 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6860 INT oldHeight
= infoPtr
->nItemHeight
;
6861 HIMAGELIST himlOld
= 0;
6863 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
6868 himlOld
= infoPtr
->himlNormal
;
6869 infoPtr
->himlNormal
= himl
;
6870 if (uView
== LVS_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
6871 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
6875 himlOld
= infoPtr
->himlSmall
;
6876 infoPtr
->himlSmall
= himl
;
6877 if (uView
!= LVS_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
6881 himlOld
= infoPtr
->himlState
;
6882 infoPtr
->himlState
= himl
;
6883 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
6884 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
6888 ERR("Unknown icon type=%d\n", nType
);
6892 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
6893 if (infoPtr
->nItemHeight
!= oldHeight
)
6894 LISTVIEW_UpdateScroll(infoPtr
);
6901 * Preallocates memory (does *not* set the actual count of items !)
6904 * [I] infoPtr : valid pointer to the listview structure
6905 * [I] nItems : item count (projected number of items to allocate)
6906 * [I] dwFlags : update flags
6912 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
6914 TRACE("(nItems=%d, dwFlags=%lx)\n", nItems
, dwFlags
);
6916 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6918 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6919 INT nOldCount
= infoPtr
->nItemCount
;
6921 if (nItems
< nOldCount
)
6923 RANGE range
= { nItems
, nOldCount
};
6924 ranges_del(infoPtr
->selectionRanges
, range
);
6925 if (infoPtr
->nFocusedItem
>= nItems
)
6927 infoPtr
->nFocusedItem
= -1;
6928 SetRectEmpty(&infoPtr
->rcFocus
);
6932 infoPtr
->nItemCount
= nItems
;
6933 LISTVIEW_UpdateScroll(infoPtr
);
6935 /* the flags are valid only in ownerdata report and list modes */
6936 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
) dwFlags
= 0;
6938 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
6939 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
6941 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
6942 LISTVIEW_InvalidateList(infoPtr
);
6949 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6950 nFrom
= min(nOldCount
, nItems
);
6951 nTo
= max(nOldCount
, nItems
);
6953 if (uView
== LVS_REPORT
)
6956 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
6957 rcErase
.right
= infoPtr
->nItemWidth
;
6958 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
6959 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
6960 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
6961 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
6965 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
6967 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
6968 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
6969 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
6970 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
6971 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
6972 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
6973 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
6975 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
6977 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
6978 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
6979 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
6980 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
6981 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
6987 /* According to MSDN for non-LVS_OWNERDATA this is just
6988 * a performance issue. The control allocates its internal
6989 * data structures for the number of items specified. It
6990 * cuts down on the number of memory allocations. Therefore
6991 * we will just issue a WARN here
6993 WARN("for non-ownerdata performance option not implemented.\n");
7001 * Sets the position of an item.
7004 * [I] infoPtr : valid pointer to the listview structure
7005 * [I] nItem : item index
7006 * [I] pt : coordinate
7012 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, POINT pt
)
7014 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7017 TRACE("(nItem=%d, &pt=%s\n", nItem
, debugpoint(&pt
));
7019 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
7020 !(uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)) return FALSE
;
7022 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7024 /* This point value seems to be an undocumented feature.
7025 * The best guess is that it means either at the origin,
7026 * or at true beginning of the list. I will assume the origin. */
7027 if ((pt
.x
== -1) && (pt
.y
== -1))
7030 if (uView
== LVS_ICON
)
7032 pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
7033 pt
.y
-= ICON_TOP_PADDING
;
7038 infoPtr
->bAutoarrange
= FALSE
;
7040 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, FALSE
);
7045 * Sets the state of one or many items.
7048 * [I] infoPtr : valid pointer to the listview structure
7049 * [I] nItem : item index
7050 * [I] lpLVItem : item or subitem info
7056 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
)
7058 BOOL bResult
= TRUE
;
7061 lvItem
.iItem
= nItem
;
7062 lvItem
.iSubItem
= 0;
7063 lvItem
.mask
= LVIF_STATE
;
7064 lvItem
.state
= lpLVItem
->state
;
7065 lvItem
.stateMask
= lpLVItem
->stateMask
;
7066 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
7070 /* apply to all items */
7071 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
7072 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) bResult
= FALSE
;
7075 bResult
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
7078 *update selection mark
7080 * Investigation on windows 2k showed that selection mark was updated
7081 * whenever a new selection was made, but if the selected item was
7082 * unselected it was not updated.
7084 * we are probably still not 100% accurate, but this at least sets the
7085 * proper selection mark when it is needed
7088 if (bResult
&& (lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) &&
7089 ((infoPtr
->nSelectionMark
== -1) || (lvItem
.iItem
<= infoPtr
->nSelectionMark
)))
7092 infoPtr
->nSelectionMark
= -1;
7093 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
7095 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
7097 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
7099 infoPtr
->nSelectionMark
= i
;
7103 else if (ranges_contain(infoPtr
->selectionRanges
, i
))
7105 infoPtr
->nSelectionMark
= i
;
7116 * Sets the text of an item or subitem.
7119 * [I] hwnd : window handle
7120 * [I] nItem : item index
7121 * [I] lpLVItem : item or subitem info
7122 * [I] isW : TRUE if input is Unicode
7128 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
7132 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
7134 lvItem
.iItem
= nItem
;
7135 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
7136 lvItem
.mask
= LVIF_TEXT
;
7137 lvItem
.pszText
= lpLVItem
->pszText
;
7138 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
7140 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
7142 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
7147 * Set item index that marks the start of a multiple selection.
7150 * [I] infoPtr : valid pointer to the listview structure
7151 * [I] nIndex : index
7154 * Index number or -1 if there is no selection mark.
7156 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
7158 INT nOldIndex
= infoPtr
->nSelectionMark
;
7160 TRACE("(nIndex=%d)\n", nIndex
);
7162 infoPtr
->nSelectionMark
= nIndex
;
7169 * Sets the text background color.
7172 * [I] infoPtr : valid pointer to the listview structure
7173 * [I] clrTextBk : text background color
7179 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrTextBk
)
7181 TRACE("(clrTextBk=%lx)\n", clrTextBk
);
7183 if (infoPtr
->clrTextBk
!= clrTextBk
)
7185 infoPtr
->clrTextBk
= clrTextBk
;
7186 LISTVIEW_InvalidateList(infoPtr
);
7194 * Sets the text foreground color.
7197 * [I] infoPtr : valid pointer to the listview structure
7198 * [I] clrText : text color
7204 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF clrText
)
7206 TRACE("(clrText=%lx)\n", clrText
);
7208 if (infoPtr
->clrText
!= clrText
)
7210 infoPtr
->clrText
= clrText
;
7211 LISTVIEW_InvalidateList(infoPtr
);
7219 * Determines which listview item is located at the specified position.
7222 * [I] infoPtr : valid pointer to the listview structure
7223 * [I] hwndNewToolTip : handle to new ToolTip
7228 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
7230 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
7231 infoPtr
->hwndToolTip
= hwndNewToolTip
;
7232 return hwndOldToolTip
;
7235 /* LISTVIEW_SetUnicodeFormat */
7236 /* LISTVIEW_SetWorkAreas */
7240 * Callback internally used by LISTVIEW_SortItems()
7243 * [I] first : pointer to first ITEM_INFO to compare
7244 * [I] second : pointer to second ITEM_INFO to compare
7245 * [I] lParam : HWND of control
7248 * if first comes before second : negative
7249 * if first comes after second : positive
7250 * if first and second are equivalent : zero
7252 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
7254 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
7255 ITEM_INFO
* lv_first
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)first
, 0 );
7256 ITEM_INFO
* lv_second
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)second
, 0 );
7257 PFNLVCOMPARE CompareFunction
= infoPtr
->pfnCompare
;
7259 /* Forward the call to the client defined callback */
7261 return (CompareFunction
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
7266 * Sorts the listview items.
7269 * [I] infoPtr : valid pointer to the listview structure
7270 * [I] pfnCompare : application-defined value
7271 * [I] lParamSort : pointer to comparision callback
7277 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
, LPARAM lParamSort
)
7279 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7282 LPVOID selectionMarkItem
;
7286 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
7288 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
7290 if (!pfnCompare
) return FALSE
;
7291 if (!infoPtr
->hdpaItems
) return FALSE
;
7293 /* if there are 0 or 1 items, there is no need to sort */
7294 if (infoPtr
->nItemCount
< 2) return TRUE
;
7296 if (infoPtr
->nFocusedItem
>= 0)
7298 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
7299 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
7300 if (lpItem
) lpItem
->state
|= LVIS_FOCUSED
;
7302 /* FIXME: go thorugh selected items and mark them so in lpItem->state */
7303 /* clear the lpItem->state for non-selected ones */
7304 /* remove the selection ranges */
7306 infoPtr
->pfnCompare
= pfnCompare
;
7307 infoPtr
->lParamSort
= lParamSort
;
7308 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
7310 /* Adjust selections and indices so that they are the way they should
7311 * be after the sort (otherwise, the list items move around, but
7312 * whatever is at the item's previous original position will be
7315 selectionMarkItem
=(infoPtr
->nSelectionMark
>=0)?DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
):NULL
;
7316 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
7318 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, i
);
7319 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
7321 if (lpItem
->state
& LVIS_SELECTED
)
7323 item
.state
= LVIS_SELECTED
;
7324 item
.stateMask
= LVIS_SELECTED
;
7325 LISTVIEW_SetItemState(infoPtr
, i
, &item
);
7327 if (lpItem
->state
& LVIS_FOCUSED
)
7329 infoPtr
->nFocusedItem
= i
;
7330 lpItem
->state
&= ~LVIS_FOCUSED
;
7333 if (selectionMarkItem
!= NULL
)
7334 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
7335 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
7337 /* refresh the display */
7338 if (uView
!= LVS_ICON
&& uView
!= LVS_SMALLICON
)
7339 LISTVIEW_InvalidateList(infoPtr
);
7346 * Updates an items or rearranges the listview control.
7349 * [I] infoPtr : valid pointer to the listview structure
7350 * [I] nItem : item index
7356 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
7358 TRACE("(nItem=%d)\n", nItem
);
7360 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7362 /* rearrange with default alignment style */
7363 if (is_autoarrange(infoPtr
))
7364 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
7366 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
7374 * Creates the listview control.
7377 * [I] hwnd : window handle
7378 * [I] lpcs : the create parameters
7384 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
7386 LISTVIEW_INFO
*infoPtr
;
7387 UINT uView
= lpcs
->style
& LVS_TYPEMASK
;
7390 TRACE("(lpcs=%p)\n", lpcs
);
7392 /* initialize info pointer */
7393 infoPtr
= (LISTVIEW_INFO
*)Alloc(sizeof(LISTVIEW_INFO
));
7394 if (!infoPtr
) return -1;
7396 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
7398 infoPtr
->hwndSelf
= hwnd
;
7399 infoPtr
->dwStyle
= lpcs
->style
;
7400 /* determine the type of structures to use */
7401 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
7402 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
7403 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
7405 /* initialize color information */
7406 infoPtr
->clrBk
= CLR_NONE
;
7407 infoPtr
->clrText
= comctl32_color
.clrWindowText
;
7408 infoPtr
->clrTextBk
= CLR_DEFAULT
;
7409 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
7411 /* set default values */
7412 infoPtr
->nFocusedItem
= -1;
7413 infoPtr
->nSelectionMark
= -1;
7414 infoPtr
->nHotItem
= -1;
7415 infoPtr
->bRedraw
= TRUE
;
7416 infoPtr
->bNoItemMetrics
= TRUE
;
7417 infoPtr
->bDoChangeNotify
= TRUE
;
7418 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
);
7419 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
);
7420 infoPtr
->nEditLabelItem
= -1;
7421 infoPtr
->dwHoverTime
= -1; /* default system hover time */
7423 /* get default font (icon title) */
7424 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
7425 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
7426 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
7427 LISTVIEW_SaveTextMetrics(infoPtr
);
7430 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
,
7431 WS_CHILD
| HDS_HORZ
| (DWORD
)((LVS_NOSORTHEADER
& lpcs
->style
)?0:HDS_BUTTONS
),
7432 0, 0, 0, 0, hwnd
, NULL
,
7433 lpcs
->hInstance
, NULL
);
7434 if (!infoPtr
->hwndHeader
) goto fail
;
7436 /* set header unicode format */
7437 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, (WPARAM
)TRUE
, (LPARAM
)NULL
);
7439 /* set header font */
7440 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, (LPARAM
)TRUE
);
7442 /* allocate memory for the data structure */
7443 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
7444 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
7445 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
7446 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
7447 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
7449 /* initialize the icon sizes */
7450 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, uView
!= LVS_ICON
);
7451 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
7453 /* init item size to avoid division by 0 */
7454 LISTVIEW_UpdateItemSize (infoPtr
);
7456 if (uView
== LVS_REPORT
)
7458 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
))
7460 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
7464 /* set HDS_HIDDEN flag to hide the header bar */
7465 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
,
7466 GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
) | HDS_HIDDEN
);
7473 DestroyWindow(infoPtr
->hwndHeader
);
7474 ranges_destroy(infoPtr
->selectionRanges
);
7475 DPA_Destroy(infoPtr
->hdpaItems
);
7476 DPA_Destroy(infoPtr
->hdpaPosX
);
7477 DPA_Destroy(infoPtr
->hdpaPosY
);
7478 DPA_Destroy(infoPtr
->hdpaColumns
);
7485 * Erases the background of the listview control.
7488 * [I] infoPtr : valid pointer to the listview structure
7489 * [I] hdc : device context handle
7495 static inline BOOL
LISTVIEW_EraseBkgnd(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
7499 TRACE("(hdc=%p)\n", hdc
);
7501 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
7503 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
7509 * Helper function for LISTVIEW_[HV]Scroll *only*.
7510 * Performs vertical/horizontal scrolling by a give amount.
7513 * [I] infoPtr : valid pointer to the listview structure
7514 * [I] dx : amount of horizontal scroll
7515 * [I] dy : amount of vertical scroll
7517 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7519 /* now we can scroll the list */
7520 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
7521 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
7522 /* if we have focus, adjust rect */
7523 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
7524 UpdateWindow(infoPtr
->hwndSelf
);
7529 * Performs vertical scrolling.
7532 * [I] infoPtr : valid pointer to the listview structure
7533 * [I] nScrollCode : scroll code
7534 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7535 * [I] hScrollWnd : scrollbar control window handle
7541 * SB_LINEUP/SB_LINEDOWN:
7542 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
7543 * for LVS_REPORT is 1 line
7544 * for LVS_LIST cannot occur
7547 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
7548 INT nScrollDiff
, HWND hScrollWnd
)
7550 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7551 INT nOldScrollPos
, nNewScrollPos
;
7552 SCROLLINFO scrollInfo
;
7555 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
7556 debugscrollcode(nScrollCode
), nScrollDiff
);
7558 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
7560 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7561 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
7563 is_an_icon
= ((uView
== LVS_ICON
) || (uView
== LVS_SMALLICON
));
7565 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
7567 nOldScrollPos
= scrollInfo
.nPos
;
7568 switch (nScrollCode
)
7574 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
7578 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
7582 nScrollDiff
= -scrollInfo
.nPage
;
7586 nScrollDiff
= scrollInfo
.nPage
;
7589 case SB_THUMBPOSITION
:
7591 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
7598 /* quit right away if pos isn't changing */
7599 if (nScrollDiff
== 0) return 0;
7601 /* calculate new position, and handle overflows */
7602 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
7603 if (nScrollDiff
> 0) {
7604 if (nNewScrollPos
< nOldScrollPos
||
7605 nNewScrollPos
> scrollInfo
.nMax
)
7606 nNewScrollPos
= scrollInfo
.nMax
;
7608 if (nNewScrollPos
> nOldScrollPos
||
7609 nNewScrollPos
< scrollInfo
.nMin
)
7610 nNewScrollPos
= scrollInfo
.nMin
;
7613 /* set the new position, and reread in case it changed */
7614 scrollInfo
.fMask
= SIF_POS
;
7615 scrollInfo
.nPos
= nNewScrollPos
;
7616 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
7618 /* carry on only if it really changed */
7619 if (nNewScrollPos
== nOldScrollPos
) return 0;
7621 /* now adjust to client coordinates */
7622 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
7623 if (uView
== LVS_REPORT
) nScrollDiff
*= infoPtr
->nItemHeight
;
7625 /* and scroll the window */
7626 scroll_list(infoPtr
, 0, nScrollDiff
);
7633 * Performs horizontal scrolling.
7636 * [I] infoPtr : valid pointer to the listview structure
7637 * [I] nScrollCode : scroll code
7638 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7639 * [I] hScrollWnd : scrollbar control window handle
7645 * SB_LINELEFT/SB_LINERIGHT:
7646 * for LVS_ICON, LVS_SMALLICON 1 pixel
7647 * for LVS_REPORT is 1 pixel
7648 * for LVS_LIST is 1 column --> which is a 1 because the
7649 * scroll is based on columns not pixels
7652 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
7653 INT nScrollDiff
, HWND hScrollWnd
)
7655 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7656 INT nOldScrollPos
, nNewScrollPos
;
7657 SCROLLINFO scrollInfo
;
7659 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
7660 debugscrollcode(nScrollCode
), nScrollDiff
);
7662 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
7664 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7665 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
7667 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
7669 nOldScrollPos
= scrollInfo
.nPos
;
7671 switch (nScrollCode
)
7685 nScrollDiff
= -scrollInfo
.nPage
;
7689 nScrollDiff
= scrollInfo
.nPage
;
7692 case SB_THUMBPOSITION
:
7694 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
7701 /* quit right away if pos isn't changing */
7702 if (nScrollDiff
== 0) return 0;
7704 /* calculate new position, and handle overflows */
7705 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
7706 if (nScrollDiff
> 0) {
7707 if (nNewScrollPos
< nOldScrollPos
||
7708 nNewScrollPos
> scrollInfo
.nMax
)
7709 nNewScrollPos
= scrollInfo
.nMax
;
7711 if (nNewScrollPos
> nOldScrollPos
||
7712 nNewScrollPos
< scrollInfo
.nMin
)
7713 nNewScrollPos
= scrollInfo
.nMin
;
7716 /* set the new position, and reread in case it changed */
7717 scrollInfo
.fMask
= SIF_POS
;
7718 scrollInfo
.nPos
= nNewScrollPos
;
7719 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
7721 /* carry on only if it really changed */
7722 if (nNewScrollPos
== nOldScrollPos
) return 0;
7724 if(uView
== LVS_REPORT
)
7725 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
7727 /* now adjust to client coordinates */
7728 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
7729 if (uView
== LVS_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
7731 /* and scroll the window */
7732 scroll_list(infoPtr
, nScrollDiff
, 0);
7737 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
7739 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7740 INT gcWheelDelta
= 0;
7741 INT pulScrollLines
= 3;
7742 SCROLLINFO scrollInfo
;
7744 TRACE("(wheelDelta=%d)\n", wheelDelta
);
7746 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
7747 gcWheelDelta
-= wheelDelta
;
7749 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7750 scrollInfo
.fMask
= SIF_POS
;
7757 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
7758 * should be fixed in the future.
7760 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (gcWheelDelta
< 0) ?
7761 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
, 0);
7765 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
7767 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
7768 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
7769 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, cLineScroll
, 0);
7774 LISTVIEW_HScroll(infoPtr
, (gcWheelDelta
< 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0, 0);
7785 * [I] infoPtr : valid pointer to the listview structure
7786 * [I] nVirtualKey : virtual key
7787 * [I] lKeyData : key data
7792 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
7794 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7796 NMLVKEYDOWN nmKeyDown
;
7798 TRACE("(nVirtualKey=%d, lKeyData=%ld)\n", nVirtualKey
, lKeyData
);
7800 /* send LVN_KEYDOWN notification */
7801 nmKeyDown
.wVKey
= nVirtualKey
;
7802 nmKeyDown
.flags
= 0;
7803 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
7805 switch (nVirtualKey
)
7808 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
7810 notify(infoPtr
, NM_RETURN
);
7811 notify(infoPtr
, LVN_ITEMACTIVATE
);
7816 if (infoPtr
->nItemCount
> 0)
7821 if (infoPtr
->nItemCount
> 0)
7822 nItem
= infoPtr
->nItemCount
- 1;
7826 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
7830 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
7834 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
7838 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
7842 if (uView
== LVS_REPORT
)
7843 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
);
7845 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
7846 * LISTVIEW_GetCountPerRow(infoPtr
);
7847 if(nItem
< 0) nItem
= 0;
7851 if (uView
== LVS_REPORT
)
7852 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
);
7854 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
7855 * LISTVIEW_GetCountPerRow(infoPtr
);
7856 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
7860 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
))
7861 LISTVIEW_KeySelection(infoPtr
, nItem
);
7871 * [I] infoPtr : valid pointer to the listview structure
7876 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
7880 /* if we did not have the focus, there's nothing to do */
7881 if (!infoPtr
->bFocus
) return 0;
7883 /* send NM_KILLFOCUS notification */
7884 notify(infoPtr
, NM_KILLFOCUS
);
7886 /* if we have a focus rectagle, get rid of it */
7887 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
7889 /* set window focus flag */
7890 infoPtr
->bFocus
= FALSE
;
7892 /* invalidate the selected items before reseting focus flag */
7893 LISTVIEW_InvalidateSelectedItems(infoPtr
);
7901 * Track mouse/dragging
7904 * [I] infoPtr : valid pointer to the listview structure
7905 * [I] pt : mouse coordinate
7910 static LRESULT
LISTVIEW_TrackMouse(LISTVIEW_INFO
*infoPtr
, POINT pt
)
7912 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
7913 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
7919 r
.top
= pt
.y
- cyDrag
;
7920 r
.left
= pt
.x
- cxDrag
;
7921 r
.bottom
= pt
.y
+ cyDrag
;
7922 r
.right
= pt
.x
+ cxDrag
;
7924 SetCapture(infoPtr
->hwndSelf
);
7928 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
7930 if (msg
.message
== WM_MOUSEMOVE
)
7932 pt
.x
= (short)LOWORD(msg
.lParam
);
7933 pt
.y
= (short)HIWORD(msg
.lParam
);
7934 if (PtInRect(&r
, pt
))
7942 else if (msg
.message
>= WM_LBUTTONDOWN
&&
7943 msg
.message
<= WM_RBUTTONDBLCLK
)
7948 DispatchMessageW(&msg
);
7951 if (GetCapture() != infoPtr
->hwndSelf
)
7962 * Processes double click messages (left mouse button).
7965 * [I] infoPtr : valid pointer to the listview structure
7966 * [I] wKey : key flag
7967 * [I] x,y : mouse coordinate
7972 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
7974 LVHITTESTINFO htInfo
;
7976 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
7978 /* send NM_RELEASEDCAPTURE notification */
7979 notify(infoPtr
, NM_RELEASEDCAPTURE
);
7984 /* send NM_DBLCLK notification */
7985 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
7986 notify_click(infoPtr
, NM_DBLCLK
, &htInfo
);
7988 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
7989 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
7996 * Processes mouse down messages (left mouse button).
7999 * [I] infoPtr : valid pointer to the listview structure
8000 * [I] wKey : key flag
8001 * [I] x,y : mouse coordinate
8006 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8008 LVHITTESTINFO lvHitTestInfo
;
8009 static BOOL bGroupSelect
= TRUE
;
8010 POINT pt
= { x
, y
};
8013 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
8015 /* send NM_RELEASEDCAPTURE notification */
8016 notify(infoPtr
, NM_RELEASEDCAPTURE
);
8018 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
8020 /* set left button down flag */
8021 infoPtr
->bLButtonDown
= TRUE
;
8023 lvHitTestInfo
.pt
.x
= x
;
8024 lvHitTestInfo
.pt
.y
= y
;
8026 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
8027 TRACE("at %s, nItem=%d\n", debugpoint(&pt
), nItem
);
8028 infoPtr
->nEditLabelItem
= -1;
8029 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
8031 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
8033 DWORD state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
) >> 12;
8034 if(state
== 1 || state
== 2)
8038 lvitem
.state
= state
<< 12;
8039 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
8040 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
8044 if (LISTVIEW_TrackMouse(infoPtr
, lvHitTestInfo
.pt
))
8048 ZeroMemory(&nmlv
, sizeof(nmlv
));
8050 nmlv
.ptAction
.x
= lvHitTestInfo
.pt
.x
;
8051 nmlv
.ptAction
.y
= lvHitTestInfo
.pt
.y
;
8053 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
8058 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
8060 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
8061 infoPtr
->nEditLabelItem
= nItem
;
8063 LISTVIEW_SetSelection(infoPtr
, nItem
);
8067 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
8071 LISTVIEW_AddGroupSelection(infoPtr
, nItem
);
8072 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
8073 infoPtr
->nSelectionMark
= nItem
;
8079 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
8080 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
8082 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
8083 infoPtr
->nSelectionMark
= nItem
;
8086 else if (wKey
& MK_CONTROL
)
8090 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
8092 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
8093 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
8094 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
8095 infoPtr
->nSelectionMark
= nItem
;
8097 else if (wKey
& MK_SHIFT
)
8099 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
8103 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
8104 infoPtr
->nEditLabelItem
= nItem
;
8106 /* set selection (clears other pre-existing selections) */
8107 LISTVIEW_SetSelection(infoPtr
, nItem
);
8113 /* remove all selections */
8114 LISTVIEW_DeselectAll(infoPtr
);
8123 * Processes mouse up messages (left mouse button).
8126 * [I] infoPtr : valid pointer to the listview structure
8127 * [I] wKey : key flag
8128 * [I] x,y : mouse coordinate
8133 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8135 LVHITTESTINFO lvHitTestInfo
;
8137 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
8139 if (!infoPtr
->bLButtonDown
) return 0;
8141 lvHitTestInfo
.pt
.x
= x
;
8142 lvHitTestInfo
.pt
.y
= y
;
8144 /* send NM_CLICK notification */
8145 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
8146 notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
);
8148 /* set left button flag */
8149 infoPtr
->bLButtonDown
= FALSE
;
8151 /* if we clicked on a selected item, edit the label */
8152 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
8153 LISTVIEW_EditLabelT(infoPtr
, lvHitTestInfo
.iItem
, TRUE
);
8160 * Destroys the listview control (called after WM_DESTROY).
8163 * [I] infoPtr : valid pointer to the listview structure
8168 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
8172 /* delete all items */
8173 LISTVIEW_DeleteAllItems(infoPtr
);
8175 /* destroy data structure */
8176 DPA_Destroy(infoPtr
->hdpaItems
);
8177 DPA_Destroy(infoPtr
->hdpaPosX
);
8178 DPA_Destroy(infoPtr
->hdpaPosY
);
8179 DPA_Destroy(infoPtr
->hdpaColumns
);
8180 ranges_destroy(infoPtr
->selectionRanges
);
8182 /* destroy image lists */
8183 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8185 if (infoPtr
->himlNormal
)
8186 ImageList_Destroy(infoPtr
->himlNormal
);
8187 if (infoPtr
->himlSmall
)
8188 ImageList_Destroy(infoPtr
->himlSmall
);
8189 if (infoPtr
->himlState
)
8190 ImageList_Destroy(infoPtr
->himlState
);
8193 /* destroy font, bkgnd brush */
8195 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
8196 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8198 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
8200 /* free listview info pointer*/
8208 * Handles notifications from header.
8211 * [I] infoPtr : valid pointer to the listview structure
8212 * [I] nCtrlId : control identifier
8213 * [I] lpnmh : notification information
8218 static LRESULT
LISTVIEW_HeaderNotification(LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
8220 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
8222 TRACE("(lpnmh=%p)\n", lpnmh
);
8224 if (!lpnmh
|| lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
8226 switch (lpnmh
->hdr
.code
)
8230 case HDN_ITEMCHANGEDW
:
8231 case HDN_ITEMCHANGEDA
:
8233 COLUMN_INFO
*lpColumnInfo
;
8236 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
8240 hdi
.mask
= HDI_WIDTH
;
8241 if (!Header_GetItemW(infoPtr
->hwndHeader
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
8245 cxy
= lpnmh
->pitem
->cxy
;
8247 /* determine how much we change since the last know position */
8248 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
8249 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8252 RECT rcCol
= lpColumnInfo
->rcHeader
;
8254 lpColumnInfo
->rcHeader
.right
+= dx
;
8255 LISTVIEW_ScrollColumns(infoPtr
, lpnmh
->iItem
+ 1, dx
);
8256 LISTVIEW_UpdateItemSize(infoPtr
);
8257 if (uView
== LVS_REPORT
&& is_redrawing(infoPtr
))
8259 /* this trick works for left aligned columns only */
8260 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8262 rcCol
.right
= min (rcCol
.right
, lpColumnInfo
->rcHeader
.right
);
8263 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- 3 * infoPtr
->ntmAveCharWidth
);
8265 rcCol
.top
= infoPtr
->rcList
.top
;
8266 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
8267 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
8273 case HDN_ITEMCLICKW
:
8274 case HDN_ITEMCLICKA
:
8276 /* Handle sorting by Header Column */
8279 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
8281 nmlv
.iSubItem
= lpnmh
->iItem
;
8282 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
8292 * Determines the type of structure to use.
8295 * [I] infoPtr : valid pointer to the listview structureof the sender
8296 * [I] hwndFrom : listview window handle
8297 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
8302 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
8304 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
8306 if (nCommand
!= NF_REQUERY
) return 0;
8308 infoPtr
->notifyFormat
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
8315 * Paints/Repaints the listview control.
8318 * [I] infoPtr : valid pointer to the listview structure
8319 * [I] hdc : device context handle
8324 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
8326 TRACE("(hdc=%p)\n", hdc
);
8328 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
8330 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
8332 infoPtr
->bNoItemMetrics
= FALSE
;
8333 LISTVIEW_UpdateItemSize(infoPtr
);
8334 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)
8335 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8336 LISTVIEW_UpdateScroll(infoPtr
);
8339 LISTVIEW_Refresh(infoPtr
, hdc
);
8344 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
8346 if (ps
.fErase
) LISTVIEW_FillBkgnd(infoPtr
, hdc
, &ps
.rcPaint
);
8347 LISTVIEW_Refresh(infoPtr
, hdc
);
8348 EndPaint(infoPtr
->hwndSelf
, &ps
);
8357 * Paints/Repaints the listview control.
8360 * [I] infoPtr : valid pointer to the listview structure
8361 * [I] hdc : device context handle
8362 * [I] options : drawing options
8367 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
8369 FIXME("Partial Stub: (hdc=%p options=0x%08lx)\n", hdc
, options
);
8371 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
8374 if (options
& PRF_ERASEBKGND
)
8375 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
8377 if (options
& PRF_CLIENT
)
8378 LISTVIEW_Paint(infoPtr
, hdc
);
8386 * Processes double click messages (right mouse button).
8389 * [I] infoPtr : valid pointer to the listview structure
8390 * [I] wKey : key flag
8391 * [I] x,y : mouse coordinate
8396 static LRESULT
LISTVIEW_RButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8398 LVHITTESTINFO lvHitTestInfo
;
8400 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
8402 /* send NM_RELEASEDCAPTURE notification */
8403 notify(infoPtr
, NM_RELEASEDCAPTURE
);
8405 /* send NM_RDBLCLK notification */
8406 lvHitTestInfo
.pt
.x
= x
;
8407 lvHitTestInfo
.pt
.y
= y
;
8408 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
8409 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
8416 * Processes mouse down messages (right mouse button).
8419 * [I] infoPtr : valid pointer to the listview structure
8420 * [I] wKey : key flag
8421 * [I] x,y : mouse coordinate
8426 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8428 LVHITTESTINFO lvHitTestInfo
;
8431 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
8433 /* send NM_RELEASEDCAPTURE notification */
8434 notify(infoPtr
, NM_RELEASEDCAPTURE
);
8436 /* make sure the listview control window has the focus */
8437 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
8439 /* set right button down flag */
8440 infoPtr
->bRButtonDown
= TRUE
;
8442 /* determine the index of the selected item */
8443 lvHitTestInfo
.pt
.x
= x
;
8444 lvHitTestInfo
.pt
.y
= y
;
8445 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
8447 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
8449 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
8450 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
8451 !LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
8452 LISTVIEW_SetSelection(infoPtr
, nItem
);
8456 LISTVIEW_DeselectAll(infoPtr
);
8464 * Processes mouse up messages (right mouse button).
8467 * [I] infoPtr : valid pointer to the listview structure
8468 * [I] wKey : key flag
8469 * [I] x,y : mouse coordinate
8474 static LRESULT
LISTVIEW_RButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8476 LVHITTESTINFO lvHitTestInfo
;
8479 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
8481 if (!infoPtr
->bRButtonDown
) return 0;
8483 /* set button flag */
8484 infoPtr
->bRButtonDown
= FALSE
;
8486 /* Send NM_RClICK notification */
8487 lvHitTestInfo
.pt
.x
= x
;
8488 lvHitTestInfo
.pt
.y
= y
;
8489 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
8490 notify_click(infoPtr
, NM_RCLICK
, &lvHitTestInfo
);
8492 /* Change to screen coordinate for WM_CONTEXTMENU */
8493 pt
= lvHitTestInfo
.pt
;
8494 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
8496 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
8497 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
8498 (WPARAM
)infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
8509 * [I] infoPtr : valid pointer to the listview structure
8510 * [I] hwnd : window handle of window containing the cursor
8511 * [I] nHittest : hit-test code
8512 * [I] wMouseMsg : ideintifier of the mouse message
8515 * TRUE if cursor is set
8518 static BOOL
LISTVIEW_SetCursor(LISTVIEW_INFO
*infoPtr
, HWND hwnd
, UINT nHittest
, UINT wMouseMsg
)
8520 LVHITTESTINFO lvHitTestInfo
;
8522 if(!(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)) return FALSE
;
8524 if(!infoPtr
->hHotCursor
) return FALSE
;
8526 GetCursorPos(&lvHitTestInfo
.pt
);
8527 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) return FALSE
;
8529 SetCursor(infoPtr
->hHotCursor
);
8539 * [I] infoPtr : valid pointer to the listview structure
8540 * [I] hwndLoseFocus : handle of previously focused window
8545 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
8547 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
8549 /* if we have the focus already, there's nothing to do */
8550 if (infoPtr
->bFocus
) return 0;
8552 /* send NM_SETFOCUS notification */
8553 notify(infoPtr
, NM_SETFOCUS
);
8555 /* set window focus flag */
8556 infoPtr
->bFocus
= TRUE
;
8558 /* put the focus rect back on */
8559 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
8561 /* redraw all visible selected items */
8562 LISTVIEW_InvalidateSelectedItems(infoPtr
);
8572 * [I] infoPtr : valid pointer to the listview structure
8573 * [I] fRedraw : font handle
8574 * [I] fRedraw : redraw flag
8579 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
8581 HFONT oldFont
= infoPtr
->hFont
;
8583 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
8585 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
8586 if (infoPtr
->hFont
== oldFont
) return 0;
8588 LISTVIEW_SaveTextMetrics(infoPtr
);
8590 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
8591 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
8593 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
8600 * Message handling for WM_SETREDRAW.
8601 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
8604 * [I] infoPtr : valid pointer to the listview structure
8605 * [I] bRedraw: state of redraw flag
8608 * DefWinProc return value
8610 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
8612 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
8614 /* we can not use straight equality here because _any_ non-zero value is TRUE */
8615 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
8617 infoPtr
->bRedraw
= bRedraw
;
8619 if(!bRedraw
) return 0;
8621 if (is_autoarrange(infoPtr
))
8622 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8623 LISTVIEW_UpdateScroll(infoPtr
);
8625 /* despite what the WM_SETREDRAW docs says, apps expect us
8626 * to invalidate the listview here... stupid! */
8627 LISTVIEW_InvalidateList(infoPtr
);
8634 * Resizes the listview control. This function processes WM_SIZE
8635 * messages. At this time, the width and height are not used.
8638 * [I] infoPtr : valid pointer to the listview structure
8639 * [I] Width : new width
8640 * [I] Height : new height
8645 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
8647 RECT rcOld
= infoPtr
->rcList
;
8649 TRACE("(width=%d, height=%d)\n", Width
, Height
);
8651 LISTVIEW_UpdateSize(infoPtr
);
8652 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
8654 /* do not bother with display related stuff if we're not redrawing */
8655 if (!is_redrawing(infoPtr
)) return 0;
8657 if (is_autoarrange(infoPtr
))
8658 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8660 LISTVIEW_UpdateScroll(infoPtr
);
8662 /* refresh all only for lists whose height changed significantly */
8663 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_LIST
&&
8664 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
8665 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
8666 LISTVIEW_InvalidateList(infoPtr
);
8673 * Sets the size information.
8676 * [I] infoPtr : valid pointer to the listview structure
8681 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
8683 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
8685 TRACE("uView=%d, rcList(old)=%s\n", uView
, debugrect(&infoPtr
->rcList
));
8687 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
8689 if (uView
== LVS_LIST
)
8691 /* Apparently the "LIST" style is supposed to have the same
8692 * number of items in a column even if there is no scroll bar.
8693 * Since if a scroll bar already exists then the bottom is already
8694 * reduced, only reduce if the scroll bar does not currently exist.
8695 * The "2" is there to mimic the native control. I think it may be
8696 * related to either padding or edges. (GLA 7/2002)
8698 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
8699 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
8700 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
8702 else if (uView
== LVS_REPORT
&& !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
))
8707 hl
.prc
= &infoPtr
->rcList
;
8709 Header_Layout(infoPtr
->hwndHeader
, &hl
);
8711 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
8713 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
8716 TRACE(" rcList=%s\n", debugrect(&infoPtr
->rcList
));
8721 * Processes WM_STYLECHANGED messages.
8724 * [I] infoPtr : valid pointer to the listview structure
8725 * [I] wStyleType : window style type (normal or extended)
8726 * [I] lpss : window style information
8731 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
8732 const STYLESTRUCT
*lpss
)
8734 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
8735 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
8737 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
8738 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
8740 if (wStyleType
!= GWL_STYLE
) return 0;
8742 /* FIXME: if LVS_NOSORTHEADER changed, update header */
8743 /* what if LVS_OWNERDATA changed? */
8744 /* or LVS_SINGLESEL */
8745 /* or LVS_SORT{AS,DES}CENDING */
8747 infoPtr
->dwStyle
= lpss
->styleNew
;
8749 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
8750 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
8751 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
8753 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
8754 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
8755 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
8757 if (uNewView
!= uOldView
)
8759 SIZE oldIconSize
= infoPtr
->iconSize
;
8762 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8763 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8765 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
8766 SetRectEmpty(&infoPtr
->rcFocus
);
8768 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
8769 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
8771 if (uNewView
== LVS_ICON
)
8773 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
8775 TRACE("icon old size=(%ld,%ld), new size=(%ld,%ld)\n",
8776 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
8777 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
8780 else if (uNewView
== LVS_REPORT
)
8785 hl
.prc
= &infoPtr
->rcList
;
8787 Header_Layout(infoPtr
->hwndHeader
, &hl
);
8788 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
8791 LISTVIEW_UpdateItemSize(infoPtr
);
8794 if (uNewView
== LVS_REPORT
)
8795 ShowWindow(infoPtr
->hwndHeader
, (lpss
->styleNew
& LVS_NOCOLUMNHEADER
) ? SW_HIDE
: SW_SHOWNORMAL
);
8797 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
8798 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
8799 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8801 /* update the size of the client area */
8802 LISTVIEW_UpdateSize(infoPtr
);
8804 /* add scrollbars if needed */
8805 LISTVIEW_UpdateScroll(infoPtr
);
8807 /* invalidate client area + erase background */
8808 LISTVIEW_InvalidateList(infoPtr
);
8815 * Window procedure of the listview control.
8818 static LRESULT WINAPI
8819 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
8821 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
8823 TRACE("(uMsg=%x wParam=%x lParam=%lx)\n", uMsg
, wParam
, lParam
);
8825 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
8826 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
8830 case LVM_APPROXIMATEVIEWRECT
:
8831 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
8832 LOWORD(lParam
), HIWORD(lParam
));
8834 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
8836 /* case LVM_CANCELEDITLABEL: */
8838 case LVM_CREATEDRAGIMAGE
:
8839 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
8841 case LVM_DELETEALLITEMS
:
8842 return LISTVIEW_DeleteAllItems(infoPtr
);
8844 case LVM_DELETECOLUMN
:
8845 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
8847 case LVM_DELETEITEM
:
8848 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
8850 case LVM_EDITLABELW
:
8851 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, TRUE
);
8853 case LVM_EDITLABELA
:
8854 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, FALSE
);
8856 /* case LVM_ENABLEGROUPVIEW: */
8858 case LVM_ENSUREVISIBLE
:
8859 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
8862 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
8865 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
8867 case LVM_GETBKCOLOR
:
8868 return infoPtr
->clrBk
;
8870 /* case LVM_GETBKIMAGE: */
8872 case LVM_GETCALLBACKMASK
:
8873 return infoPtr
->uCallbackMask
;
8875 case LVM_GETCOLUMNA
:
8876 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
8878 case LVM_GETCOLUMNW
:
8879 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
8881 case LVM_GETCOLUMNORDERARRAY
:
8882 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
8884 case LVM_GETCOLUMNWIDTH
:
8885 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
8887 case LVM_GETCOUNTPERPAGE
:
8888 return LISTVIEW_GetCountPerPage(infoPtr
);
8890 case LVM_GETEDITCONTROL
:
8891 return (LRESULT
)infoPtr
->hwndEdit
;
8893 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
8894 return infoPtr
->dwLvExStyle
;
8896 /* case LVM_GETGROUPINFO: */
8898 /* case LVM_GETGROUPMETRICS: */
8901 return (LRESULT
)infoPtr
->hwndHeader
;
8903 case LVM_GETHOTCURSOR
:
8904 return (LRESULT
)infoPtr
->hHotCursor
;
8906 case LVM_GETHOTITEM
:
8907 return infoPtr
->nHotItem
;
8909 case LVM_GETHOVERTIME
:
8910 return infoPtr
->dwHoverTime
;
8912 case LVM_GETIMAGELIST
:
8913 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
8915 /* case LVM_GETINSERTMARK: */
8917 /* case LVM_GETINSERTMARKCOLOR: */
8919 /* case LVM_GETINSERTMARKRECT: */
8921 case LVM_GETISEARCHSTRINGA
:
8922 case LVM_GETISEARCHSTRINGW
:
8923 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
8927 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
8930 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
8932 case LVM_GETITEMCOUNT
:
8933 return infoPtr
->nItemCount
;
8935 case LVM_GETITEMPOSITION
:
8936 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
8938 case LVM_GETITEMRECT
:
8939 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
8941 case LVM_GETITEMSPACING
:
8942 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
8944 case LVM_GETITEMSTATE
:
8945 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
8947 case LVM_GETITEMTEXTA
:
8948 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
8950 case LVM_GETITEMTEXTW
:
8951 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
8953 case LVM_GETNEXTITEM
:
8954 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
8956 case LVM_GETNUMBEROFWORKAREAS
:
8957 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
8961 if (!lParam
) return FALSE
;
8962 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
8965 /* case LVM_GETOUTLINECOLOR: */
8967 /* case LVM_GETSELECTEDCOLUMN: */
8969 case LVM_GETSELECTEDCOUNT
:
8970 return LISTVIEW_GetSelectedCount(infoPtr
);
8972 case LVM_GETSELECTIONMARK
:
8973 return infoPtr
->nSelectionMark
;
8975 case LVM_GETSTRINGWIDTHA
:
8976 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, FALSE
);
8978 case LVM_GETSTRINGWIDTHW
:
8979 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, TRUE
);
8981 case LVM_GETSUBITEMRECT
:
8982 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
8984 case LVM_GETTEXTBKCOLOR
:
8985 return infoPtr
->clrTextBk
;
8987 case LVM_GETTEXTCOLOR
:
8988 return infoPtr
->clrText
;
8990 /* case LVM_GETTILEINFO: */
8992 /* case LVM_GETTILEVIEWINFO: */
8994 case LVM_GETTOOLTIPS
:
8995 if( !infoPtr
->hwndToolTip
)
8996 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
8997 return (LRESULT
)infoPtr
->hwndToolTip
;
8999 case LVM_GETTOPINDEX
:
9000 return LISTVIEW_GetTopIndex(infoPtr
);
9002 /*case LVM_GETUNICODEFORMAT:
9003 FIXME("LVM_GETUNICODEFORMAT: unimplemented\n");
9006 /* case LVM_GETVIEW: */
9008 case LVM_GETVIEWRECT
:
9009 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
9011 case LVM_GETWORKAREAS
:
9012 FIXME("LVM_GETWORKAREAS: unimplemented\n");
9015 /* case LVM_HASGROUP: */
9018 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, FALSE
);
9020 case LVM_INSERTCOLUMNA
:
9021 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
9023 case LVM_INSERTCOLUMNW
:
9024 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
9026 /* case LVM_INSERTGROUP: */
9028 /* case LVM_INSERTGROUPSORTED: */
9030 case LVM_INSERTITEMA
:
9031 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
9033 case LVM_INSERTITEMW
:
9034 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
9036 /* case LVM_INSERTMARKHITTEST: */
9038 /* case LVM_ISGROUPVIEWENABLED: */
9040 /* case LVM_MAPIDTOINDEX: */
9042 /* case LVM_MAPINDEXTOID: */
9044 /* case LVM_MOVEGROUP: */
9046 /* case LVM_MOVEITEMTOGROUP: */
9048 case LVM_REDRAWITEMS
:
9049 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
9051 /* case LVM_REMOVEALLGROUPS: */
9053 /* case LVM_REMOVEGROUP: */
9056 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
9058 case LVM_SETBKCOLOR
:
9059 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
9061 /* case LVM_SETBKIMAGE: */
9063 case LVM_SETCALLBACKMASK
:
9064 infoPtr
->uCallbackMask
= (UINT
)wParam
;
9067 case LVM_SETCOLUMNA
:
9068 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
9070 case LVM_SETCOLUMNW
:
9071 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
9073 case LVM_SETCOLUMNORDERARRAY
:
9074 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
9076 case LVM_SETCOLUMNWIDTH
:
9077 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
9079 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
9080 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
9082 /* case LVM_SETGROUPINFO: */
9084 /* case LVM_SETGROUPMETRICS: */
9086 case LVM_SETHOTCURSOR
:
9087 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
9089 case LVM_SETHOTITEM
:
9090 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
9092 case LVM_SETHOVERTIME
:
9093 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)wParam
);
9095 case LVM_SETICONSPACING
:
9096 return LISTVIEW_SetIconSpacing(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
9098 case LVM_SETIMAGELIST
:
9099 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
9101 /* case LVM_SETINFOTIP: */
9103 /* case LVM_SETINSERTMARK: */
9105 /* case LVM_SETINSERTMARKCOLOR: */
9108 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
9111 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
9113 case LVM_SETITEMCOUNT
:
9114 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
9116 case LVM_SETITEMPOSITION
:
9119 pt
.x
= (short)LOWORD(lParam
);
9120 pt
.y
= (short)HIWORD(lParam
);
9121 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, pt
);
9124 case LVM_SETITEMPOSITION32
:
9125 if (lParam
== 0) return FALSE
;
9126 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, *((POINT
*)lParam
));
9128 case LVM_SETITEMSTATE
:
9129 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
9131 case LVM_SETITEMTEXTA
:
9132 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
9134 case LVM_SETITEMTEXTW
:
9135 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
9137 /* case LVM_SETOUTLINECOLOR: */
9139 /* case LVM_SETSELECTEDCOLUMN: */
9141 case LVM_SETSELECTIONMARK
:
9142 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
9144 case LVM_SETTEXTBKCOLOR
:
9145 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
9147 case LVM_SETTEXTCOLOR
:
9148 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
9150 /* case LVM_SETTILEINFO: */
9152 /* case LVM_SETTILEVIEWINFO: */
9154 /* case LVM_SETTILEWIDTH: */
9156 case LVM_SETTOOLTIPS
:
9157 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
9159 /* case LVM_SETUNICODEFORMAT: */
9161 /* case LVM_SETVIEW: */
9163 /* case LVM_SETWORKAREAS: */
9165 /* case LVM_SORTGROUPS: */
9168 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, (LPARAM
)wParam
);
9170 /* LVM_SORTITEMSEX: */
9172 case LVM_SUBITEMHITTEST
:
9173 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
9176 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
9179 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
9182 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
9185 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
9188 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
9191 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
9194 return (LRESULT
)infoPtr
->hFont
;
9197 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
9200 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
9203 return LISTVIEW_KillFocus(infoPtr
);
9205 case WM_LBUTTONDBLCLK
:
9206 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9208 case WM_LBUTTONDOWN
:
9209 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9212 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9215 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9218 return LISTVIEW_MouseHover(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9221 return LISTVIEW_NCDestroy(infoPtr
);
9224 if (lParam
&& ((LPNMHDR
)lParam
)->hwndFrom
== infoPtr
->hwndHeader
)
9225 return LISTVIEW_HeaderNotification(infoPtr
, (LPNMHEADERW
)lParam
);
9228 case WM_NOTIFYFORMAT
:
9229 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
9231 case WM_PRINTCLIENT
:
9232 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
9235 return LISTVIEW_Paint(infoPtr
, (HDC
)wParam
);
9237 case WM_RBUTTONDBLCLK
:
9238 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9240 case WM_RBUTTONDOWN
:
9241 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9244 return LISTVIEW_RButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9247 if(LISTVIEW_SetCursor(infoPtr
, (HWND
)wParam
, LOWORD(lParam
), HIWORD(lParam
)))
9252 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
9255 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
9258 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
9261 return LISTVIEW_Size(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
9263 case WM_STYLECHANGED
:
9264 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
9266 case WM_SYSCOLORCHANGE
:
9267 COMCTL32_RefreshSysColors();
9270 /* case WM_TIMER: */
9273 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
9276 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
9277 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
9278 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
9280 case WM_WINDOWPOSCHANGED
:
9281 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
9283 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
9284 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
9285 LISTVIEW_UpdateSize(infoPtr
);
9286 LISTVIEW_UpdateScroll(infoPtr
);
9288 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
9290 /* case WM_WININICHANGE: */
9293 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
9294 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
9297 /* call default window procedure */
9298 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
9305 * Registers the window class.
9313 void LISTVIEW_Register(void)
9317 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
9318 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
9319 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
9320 wndClass
.cbClsExtra
= 0;
9321 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
9322 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
9323 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
9324 wndClass
.lpszClassName
= WC_LISTVIEWW
;
9325 RegisterClassW(&wndClass
);
9330 * Unregisters the window class.
9338 void LISTVIEW_Unregister(void)
9340 UnregisterClassW(WC_LISTVIEWW
, NULL
);
9345 * Handle any WM_COMMAND messages
9348 * [I] infoPtr : valid pointer to the listview structure
9349 * [I] wParam : the first message parameter
9350 * [I] lParam : the second message parameter
9355 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
9357 switch (HIWORD(wParam
))
9362 * Adjust the edit window size
9365 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
9366 HFONT hFont
, hOldFont
= 0;
9371 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
9372 len
= GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
9373 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
9375 /* Select font to get the right dimension of the string */
9376 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
9379 hOldFont
= SelectObject(hdc
, hFont
);
9382 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
9384 TEXTMETRICW textMetric
;
9386 /* Add Extra spacing for the next character */
9387 GetTextMetricsW(hdc
, &textMetric
);
9388 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
9396 rect
.bottom
- rect
.top
,
9397 SWP_DRAWFRAME
|SWP_NOMOVE
);
9400 SelectObject(hdc
, hOldFont
);
9402 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9408 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
9417 * Subclassed edit control windproc function
9420 * [I] hwnd : the edit window handle
9421 * [I] uMsg : the message that is to be processed
9422 * [I] wParam : first message parameter
9423 * [I] lParam : second message parameter
9424 * [I] isW : TRUE if input is Unicode
9429 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
9431 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
9432 BOOL cancel
= FALSE
;
9434 TRACE("(hwnd=%p, uMsg=%x, wParam=%x, lParam=%lx, isW=%d)\n",
9435 hwnd
, uMsg
, wParam
, lParam
, isW
);
9440 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
9447 WNDPROC editProc
= infoPtr
->EditWndProc
;
9448 infoPtr
->EditWndProc
= 0;
9449 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
9450 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
9454 if (VK_ESCAPE
== (INT
)wParam
)
9459 else if (VK_RETURN
== (INT
)wParam
)
9463 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
9467 if (infoPtr
->hwndEdit
)
9469 LPWSTR buffer
= NULL
;
9471 infoPtr
->hwndEdit
= 0;
9474 DWORD len
= isW
? GetWindowTextLengthW(hwnd
) : GetWindowTextLengthA(hwnd
);
9478 if ( (buffer
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))) )
9480 if (isW
) GetWindowTextW(hwnd
, buffer
, len
+1);
9481 else GetWindowTextA(hwnd
, (CHAR
*)buffer
, len
+1);
9485 LISTVIEW_EndEditLabelT(infoPtr
, buffer
, isW
);
9487 if (buffer
) Free(buffer
);
9491 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
9497 * Subclassed edit control Unicode windproc function
9500 * [I] hwnd : the edit window handle
9501 * [I] uMsg : the message that is to be processed
9502 * [I] wParam : first message parameter
9503 * [I] lParam : second message parameter
9507 LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
9509 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
9514 * Subclassed edit control ANSI windproc function
9517 * [I] hwnd : the edit window handle
9518 * [I] uMsg : the message that is to be processed
9519 * [I] wParam : first message parameter
9520 * [I] lParam : second message parameter
9524 LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
9526 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
9531 * Creates a subclassed edit cotrol
9534 * [I] infoPtr : valid pointer to the listview structure
9535 * [I] text : initial text for the edit
9536 * [I] style : the window style
9537 * [I] isW : TRUE if input is Unicode
9541 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, DWORD style
,
9542 INT x
, INT y
, INT width
, INT height
, BOOL isW
)
9544 WCHAR editName
[5] = { 'E', 'd', 'i', 't', '\0' };
9549 TEXTMETRICW textMetric
;
9550 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
9552 TRACE("(text=%s, ..., isW=%d)\n", debugtext_t(text
, isW
), isW
);
9554 style
|= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|WS_BORDER
;
9555 hdc
= GetDC(infoPtr
->hwndSelf
);
9557 /* Select the font to get appropriate metric dimensions */
9558 if(infoPtr
->hFont
!= 0)
9559 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
9561 /*Get String Length in pixels */
9562 if(!GetTextExtentPoint32W(hdc
, text
, lstrlenW(text
), &sz
))
9565 /*Add Extra spacing for the next character */
9566 GetTextMetricsW(hdc
, &textMetric
);
9567 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
9569 if(infoPtr
->hFont
!= 0)
9570 SelectObject(hdc
, hOldFont
);
9572 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9574 hedit
= CreateWindowW(editName
, text
, style
, x
, y
, sz
.cx
, height
, infoPtr
->hwndSelf
, 0, hinst
, 0);
9576 hedit
= CreateWindowA("Edit", (LPCSTR
)text
, style
, x
, y
, sz
.cx
, height
, infoPtr
->hwndSelf
, 0, hinst
, 0);
9578 if (!hedit
) return 0;
9580 infoPtr
->EditWndProc
= (WNDPROC
)
9581 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
9582 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
9584 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);