4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1999 Luc Tourangeau
6 * Copyright 2000 Jason Mawdsley
7 * Copyright 2001 CodeWeavers Inc.
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Nikolay Sivov
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on May. 20, 2005, by James Hawkins.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
36 * Default Message Processing
37 * -- WM_CREATE: create the icon and small icon image lists at this point only if
38 * the LVS_SHAREIMAGELISTS style is not specified.
39 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
40 * or small icon and the LVS_AUTOARRANGE style is specified.
45 * -- Hot item handling, mouse hovering
46 * -- Workareas support
51 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
52 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
53 * -- LVA_SNAPTOGRID not implemented
54 * -- LISTVIEW_ApproximateViewRect partially implemented
55 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
56 * -- LISTVIEW_SetIconSpacing is incomplete
57 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
60 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
61 * linear in the number of items in the list, and this is
62 * unacceptable for large lists.
63 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
64 * binary search to calculate item index (e.g. DPA_Search()).
65 * This requires sorted state to be reliably tracked in item modifiers.
66 * -- we should keep an ordered array of coordinates in iconic mode
67 * this would allow to frame items (iterator_frameditems),
68 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
75 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
82 * -- LVS_NOSCROLL (see Q137520)
86 * -- LVS_EX_BORDERSELECT
90 * -- LVS_EX_MULTIWORKAREAS
92 * -- LVS_EX_SIMPLESELECT
93 * -- LVS_EX_TWOCLICKACTIVATE
94 * -- LVS_EX_UNDERLINECOLD
95 * -- LVS_EX_UNDERLINEHOT
98 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
101 * -- LVN_MARQUEEBEGIN
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_GETWORKAREAS, LVM_SETWORKAREAS
121 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
122 * -- LVM_INSERTGROUPSORTED
123 * -- LVM_INSERTMARKHITTEST
124 * -- LVM_ISGROUPVIEWENABLED
126 * -- LVM_MOVEITEMTOGROUP
128 * -- LVM_SETTILEWIDTH
132 * -- ListView_GetHoverTime, ListView_SetHoverTime
133 * -- ListView_GetISearchString
134 * -- ListView_GetNumberOfWorkAreas
135 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
140 * Known differences in message stream from native control (not known if
141 * these differences cause problems):
142 * LVM_INSERTITEM issues LVM_SETITEMSTATE and LVM_SETITEM in certain cases.
143 * LVM_SETITEM does not always issue LVN_ITEMCHANGING/LVN_ITEMCHANGED.
144 * WM_CREATE does not issue WM_QUERYUISTATE and associated registry
145 * processing for "USEDOUBLECLICKTIME".
149 #include "wine/port.h"
164 #include "commctrl.h"
165 #include "comctl32.h"
168 #include "wine/debug.h"
169 #include "wine/unicode.h"
171 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
173 /* make sure you set this to 0 for production use! */
174 #define DEBUG_RANGES 1
176 typedef struct tagCOLUMN_INFO
178 RECT rcHeader
; /* tracks the header's rectangle */
179 INT fmt
; /* same as LVCOLUMN.fmt */
183 typedef struct tagITEMHDR
187 } ITEMHDR
, *LPITEMHDR
;
189 typedef struct tagSUBITEM_INFO
195 typedef struct tagITEM_ID ITEM_ID
;
197 typedef struct tagITEM_INFO
208 UINT id
; /* item id */
209 HDPA item
; /* link to item data */
212 typedef struct tagRANGE
218 typedef struct tagRANGES
223 typedef struct tagITERATOR
232 typedef struct tagDELAYED_ITEM_EDIT
238 typedef struct tagLISTVIEW_INFO
245 HIMAGELIST himlNormal
;
246 HIMAGELIST himlSmall
;
247 HIMAGELIST himlState
;
251 POINT ptClickPos
; /* point where the user clicked */
252 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
255 RANGES selectionRanges
;
260 RECT rcList
; /* This rectangle is really the window
261 * client rectangle possibly reduced by the
262 * horizontal scroll bar and/or header - see
263 * LISTVIEW_UpdateSize. This rectangle offset
264 * by the LISTVIEW_GetOrigin value is in
265 * client coordinates */
274 INT ntmHeight
; /* Some cached metrics of the font used */
275 INT ntmMaxCharWidth
; /* by the listview to draw items */
277 BOOL bRedraw
; /* Turns on/off repaints & invalidations */
278 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
280 BOOL bDoChangeNotify
; /* send change notification messages? */
283 DWORD dwStyle
; /* the cached window GWL_STYLE */
284 DWORD dwLvExStyle
; /* extended listview style */
285 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
286 INT nItemCount
; /* the number of items in the list */
287 HDPA hdpaItems
; /* array ITEM_INFO pointers */
288 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
289 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
290 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
291 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
292 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
293 POINT currIconPos
; /* this is the position next icon will be placed */
294 PFNLVCOMPARE pfnCompare
;
299 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
303 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
305 DWORD lastKeyPressTimestamp
;
307 INT nSearchParamLength
;
308 WCHAR szSearchParam
[ MAX_PATH
];
310 INT nMeasureItemHeight
;
311 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
312 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
314 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
320 /* How many we debug buffer to allocate */
321 #define DEBUG_BUFFERS 20
322 /* The size of a single debug buffer */
323 #define DEBUG_BUFFER_SIZE 256
325 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
326 #define SB_INTERNAL -1
328 /* maximum size of a label */
329 #define DISP_TEXT_SIZE 512
331 /* padding for items in list and small icon display modes */
332 #define WIDTH_PADDING 12
334 /* padding for items in list, report and small icon display modes */
335 #define HEIGHT_PADDING 1
337 /* offset of items in report display mode */
338 #define REPORT_MARGINX 2
340 /* padding for icon in large icon display mode
341 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
342 * that HITTEST will see.
343 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
344 * ICON_TOP_PADDING - sum of the two above.
345 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
346 * LABEL_HOR_PADDING - between text and sides of box
347 * LABEL_VERT_PADDING - between bottom of text and end of box
349 * ICON_LR_PADDING - additional width above icon size.
350 * ICON_LR_HALF - half of the above value
352 #define ICON_TOP_PADDING_NOTHITABLE 2
353 #define ICON_TOP_PADDING_HITABLE 2
354 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
355 #define ICON_BOTTOM_PADDING 4
356 #define LABEL_HOR_PADDING 5
357 #define LABEL_VERT_PADDING 7
358 #define ICON_LR_PADDING 16
359 #define ICON_LR_HALF (ICON_LR_PADDING/2)
361 /* default label width for items in list and small icon display modes */
362 #define DEFAULT_LABEL_WIDTH 40
363 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
364 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
366 /* default column width for items in list display mode */
367 #define DEFAULT_COLUMN_WIDTH 128
369 /* Size of "line" scroll for V & H scrolls */
370 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
372 /* Padding between image and label */
373 #define IMAGE_PADDING 2
375 /* Padding behind the label */
376 #define TRAILING_LABEL_PADDING 12
377 #define TRAILING_HEADER_PADDING 11
379 /* Border for the icon caption */
380 #define CAPTION_BORDER 2
382 /* Standard DrawText flags */
383 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
384 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
385 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
387 /* Image index from state */
388 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
390 /* The time in milliseconds to reset the search in the list */
391 #define KEY_DELAY 450
393 /* Dump the LISTVIEW_INFO structure to the debug channel */
394 #define LISTVIEW_DUMP(iP) do { \
395 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
396 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
397 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
398 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
399 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
400 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
401 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
402 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
403 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
404 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
407 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
410 * forward declarations
412 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
413 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
414 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
415 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
416 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
417 static INT
LISTVIEW_GetLabelWidth(const LISTVIEW_INFO
*, INT
);
418 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
419 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
420 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
421 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
422 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
423 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
424 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
425 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
426 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
427 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
428 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
429 static HWND
CreateEditLabelT(LISTVIEW_INFO
*, LPCWSTR
, DWORD
, BOOL
);
430 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
431 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
432 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
434 /******** Text handling functions *************************************/
436 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
437 * text string. The string may be ANSI or Unicode, in which case
438 * the boolean isW tells us the type of the string.
440 * The name of the function tell what type of strings it expects:
441 * W: Unicode, T: ANSI/Unicode - function of isW
444 static inline BOOL
is_textW(LPCWSTR text
)
446 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
449 static inline BOOL
is_textT(LPCWSTR text
, BOOL isW
)
451 /* we can ignore isW since LPSTR_TEXTCALLBACKW == LPSTR_TEXTCALLBACKA */
452 return is_textW(text
);
455 static inline int textlenT(LPCWSTR text
, BOOL isW
)
457 return !is_textT(text
, isW
) ? 0 :
458 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
461 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
464 if (isSrcW
) lstrcpynW(dest
, src
, max
);
465 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
467 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
468 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
471 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
473 LPWSTR wstr
= (LPWSTR
)text
;
475 if (!isW
&& is_textT(text
, isW
))
477 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
478 wstr
= Alloc(len
* sizeof(WCHAR
));
479 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
481 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
485 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
487 if (!isW
&& is_textT(wstr
, isW
)) Free (wstr
);
491 * dest is a pointer to a Unicode string
492 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
494 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
498 if (src
== LPSTR_TEXTCALLBACKW
)
500 if (is_textW(*dest
)) Free(*dest
);
501 *dest
= LPSTR_TEXTCALLBACKW
;
505 LPWSTR pszText
= textdupTtoW(src
, isW
);
506 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
507 bResult
= Str_SetPtrW(dest
, pszText
);
508 textfreeT(pszText
, isW
);
514 * compares a Unicode to a Unicode/ANSI text string
516 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
518 if (!aw
) return bt
? -1 : 0;
519 if (!bt
) return aw
? 1 : 0;
520 if (aw
== LPSTR_TEXTCALLBACKW
)
521 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
522 if (bt
!= LPSTR_TEXTCALLBACKW
)
524 LPWSTR bw
= textdupTtoW(bt
, isW
);
525 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
533 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
537 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
538 res
= CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
);
539 return res
? res
- sizeof(WCHAR
) : res
;
542 /******** Debugging functions *****************************************/
544 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
546 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
547 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
550 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
552 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
553 n
= min(textlenT(text
, isW
), n
);
554 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
557 static char* debug_getbuf(void)
559 static int index
= 0;
560 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
561 return buffers
[index
++ % DEBUG_BUFFERS
];
564 static inline const char* debugrange(const RANGE
*lprng
)
566 if (!lprng
) return "(null)";
567 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
570 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
572 char* buf
= debug_getbuf(), *text
= buf
;
573 int len
, size
= DEBUG_BUFFER_SIZE
;
575 if (pScrollInfo
== NULL
) return "(null)";
576 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
577 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
578 if (pScrollInfo
->fMask
& SIF_RANGE
)
579 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
581 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
582 if (pScrollInfo
->fMask
& SIF_PAGE
)
583 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
585 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
586 if (pScrollInfo
->fMask
& SIF_POS
)
587 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
589 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
590 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
591 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
593 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
596 buf
= text
+ strlen(text
);
598 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
602 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
604 if (!plvnm
) return "(null)";
605 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
606 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
607 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
608 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
611 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
613 char* buf
= debug_getbuf(), *text
= buf
;
614 int len
, size
= DEBUG_BUFFER_SIZE
;
616 if (lpLVItem
== NULL
) return "(null)";
617 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
618 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
619 if (lpLVItem
->mask
& LVIF_STATE
)
620 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
622 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
623 if (lpLVItem
->mask
& LVIF_TEXT
)
624 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
626 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
627 if (lpLVItem
->mask
& LVIF_IMAGE
)
628 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
630 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
631 if (lpLVItem
->mask
& LVIF_PARAM
)
632 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
634 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
635 if (lpLVItem
->mask
& LVIF_INDENT
)
636 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
638 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
641 buf
= text
+ strlen(text
);
643 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
647 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
649 char* buf
= debug_getbuf(), *text
= buf
;
650 int len
, size
= DEBUG_BUFFER_SIZE
;
652 if (lpColumn
== NULL
) return "(null)";
653 len
= snprintf(buf
, size
, "{");
654 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
655 if (lpColumn
->mask
& LVCF_SUBITEM
)
656 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
658 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
659 if (lpColumn
->mask
& LVCF_FMT
)
660 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
662 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
663 if (lpColumn
->mask
& LVCF_WIDTH
)
664 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
666 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
667 if (lpColumn
->mask
& LVCF_TEXT
)
668 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
670 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
671 if (lpColumn
->mask
& LVCF_IMAGE
)
672 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
674 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
675 if (lpColumn
->mask
& LVCF_ORDER
)
676 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
678 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
681 buf
= text
+ strlen(text
);
683 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
687 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
689 if (!lpht
) return "(null)";
691 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
692 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
695 /* Return the corresponding text for a given scroll value */
696 static inline LPCSTR
debugscrollcode(int nScrollCode
)
700 case SB_LINELEFT
: return "SB_LINELEFT";
701 case SB_LINERIGHT
: return "SB_LINERIGHT";
702 case SB_PAGELEFT
: return "SB_PAGELEFT";
703 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
704 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
705 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
706 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
707 case SB_INTERNAL
: return "SB_INTERNAL";
708 default: return "unknown";
713 /******** Notification functions ************************************/
715 static int get_ansi_notification(UINT unicodeNotificationCode
)
717 switch (unicodeNotificationCode
)
719 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
720 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
721 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
722 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
723 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
724 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
725 /* header forwards */
726 case HDN_TRACKW
: return HDN_TRACKA
;
727 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
728 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
729 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
730 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
731 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
732 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
733 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
735 ERR("unknown notification %x\n", unicodeNotificationCode
);
740 /* forwards header notifications to listview parent */
741 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
745 HD_TEXTFILTERA textfilter
;
746 LPSTR text
= NULL
, filter
= NULL
;
749 /* on unicode format exit earlier */
750 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
751 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
752 (WPARAM
)lpnmh
->hdr
.idFrom
, (LPARAM
)lpnmh
);
754 /* header always supplies unicode notifications,
755 all we have to do is to convert strings to ANSI */
756 nmhA
= *(NMHEADERA
*)lpnmh
;
759 hditema
= *(HDITEMA
*)lpnmh
->pitem
;
760 nmhA
.pitem
= &hditema
;
761 /* convert item text */
762 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
764 hditema
.pszText
= NULL
;
765 Str_SetPtrWtoA(&hditema
.pszText
, lpnmh
->pitem
->pszText
);
766 text
= hditema
.pszText
;
768 /* convert filter text */
769 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
770 lpnmh
->pitem
->pvFilter
)
772 hditema
.pvFilter
= &textfilter
;
773 textfilter
= *(HD_TEXTFILTERA
*)(lpnmh
->pitem
->pvFilter
);
774 textfilter
.pszText
= NULL
;
775 Str_SetPtrWtoA(&textfilter
.pszText
, ((HD_TEXTFILTERW
*)lpnmh
->pitem
->pvFilter
)->pszText
);
776 filter
= textfilter
.pszText
;
779 nmhA
.hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
781 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
782 (WPARAM
)nmhA
.hdr
.idFrom
, (LPARAM
)&nmhA
);
791 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
795 TRACE("(code=%d)\n", code
);
797 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
798 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
800 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
802 TRACE(" <= %ld\n", result
);
807 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
810 HWND hwnd
= infoPtr
->hwndSelf
;
811 notify_hdr(infoPtr
, code
, &nmh
);
812 return IsWindow(hwnd
);
815 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
826 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
827 item
.iItem
= htInfo
->iItem
;
829 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
830 nmia
.lParam
= item
.lParam
;
831 nmia
.uOldState
= item
.state
;
832 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
833 nmia
.uChanged
= LVIF_STATE
;
836 nmia
.iItem
= htInfo
->iItem
;
837 nmia
.iSubItem
= htInfo
->iSubItem
;
838 nmia
.ptAction
= htInfo
->pt
;
840 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
841 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
842 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
844 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
847 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
849 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
850 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
853 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
857 HWND hwnd
= infoPtr
->hwndSelf
;
859 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
860 ZeroMemory(&nmia
, sizeof(nmia
));
861 nmia
.iItem
= lvht
->iItem
;
862 nmia
.iSubItem
= lvht
->iSubItem
;
863 nmia
.ptAction
= lvht
->pt
;
864 item
.mask
= LVIF_PARAM
;
865 item
.iItem
= lvht
->iItem
;
867 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
868 notify_hdr(infoPtr
, code
, (LPNMHDR
)&nmia
);
869 return IsWindow(hwnd
);
872 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
876 HWND hwnd
= infoPtr
->hwndSelf
;
878 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
880 item
.mask
= LVIF_PARAM
;
883 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
884 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
885 return IsWindow(hwnd
);
889 Send notification. depends on dispinfoW having same
890 structure as dispinfoA.
891 infoPtr : listview struct
892 notificationCode : *Unicode* notification code
893 pdi : dispinfo structure (can be unicode or ansi)
894 isW : TRUE if dispinfo is Unicode
896 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT notificationCode
, LPNMLVDISPINFOW pdi
, BOOL isW
)
898 BOOL bResult
= FALSE
;
899 BOOL convertToAnsi
= FALSE
, convertToUnicode
= FALSE
;
900 INT cchTempBufMax
= 0, savCchTextMax
= 0;
902 LPWSTR pszTempBuf
= NULL
, savPszText
= NULL
;
904 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_textT(pdi
->item
.pszText
, isW
))
906 convertToAnsi
= (isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
907 convertToUnicode
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
910 if (convertToAnsi
|| convertToUnicode
)
912 if (notificationCode
!= LVN_GETDISPINFOW
)
914 cchTempBufMax
= convertToUnicode
?
915 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
916 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
920 cchTempBufMax
= pdi
->item
.cchTextMax
;
921 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
924 pszTempBuf
= Alloc( (convertToUnicode
? sizeof(WCHAR
) : sizeof(CHAR
)) * cchTempBufMax
);
925 if (!pszTempBuf
) return FALSE
;
927 if (convertToUnicode
)
928 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
929 pszTempBuf
, cchTempBufMax
);
931 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) pszTempBuf
,
932 cchTempBufMax
, NULL
, NULL
);
934 savCchTextMax
= pdi
->item
.cchTextMax
;
935 savPszText
= pdi
->item
.pszText
;
936 pdi
->item
.pszText
= pszTempBuf
;
937 pdi
->item
.cchTextMax
= cchTempBufMax
;
940 if (infoPtr
->notifyFormat
== NFR_ANSI
)
941 realNotifCode
= get_ansi_notification(notificationCode
);
943 realNotifCode
= notificationCode
;
944 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
945 bResult
= notify_hdr(infoPtr
, realNotifCode
, &pdi
->hdr
);
947 if (convertToUnicode
|| convertToAnsi
)
949 if (convertToUnicode
) /* note : pointer can be changed by app ! */
950 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) savPszText
,
951 savCchTextMax
, NULL
, NULL
);
953 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
954 savPszText
, savCchTextMax
);
955 pdi
->item
.pszText
= savPszText
; /* restores our buffer */
956 pdi
->item
.cchTextMax
= savCchTextMax
;
962 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
963 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
965 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
966 lpnmlvcd
->nmcd
.hdc
= hdc
;
967 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
968 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
969 lpnmlvcd
->clrText
= infoPtr
->clrText
;
970 if (!lplvItem
) return;
971 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
972 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
973 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
974 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
975 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
976 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
979 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
981 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
984 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
985 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
986 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
987 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
988 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
989 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
993 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
995 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
996 lpnmlvcd
->clrTextBk
= comctl32_color
.clrWindow
;
997 if (lpnmlvcd
->clrText
== CLR_DEFAULT
)
998 lpnmlvcd
->clrText
= comctl32_color
.clrWindowText
;
1000 /* apparently, for selected items, we have to override the returned values */
1003 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1005 if (infoPtr
->bFocus
)
1007 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1008 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1010 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1012 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1013 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1018 /* Set the text attributes */
1019 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
1021 SetBkMode(hdc
, OPAQUE
);
1022 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1025 SetBkMode(hdc
, TRANSPARENT
);
1026 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1029 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1031 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1034 /* returns TRUE when repaint needed, FALSE otherwise */
1035 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1037 MEASUREITEMSTRUCT mis
;
1038 mis
.CtlType
= ODT_LISTVIEW
;
1039 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1043 mis
.itemHeight
= infoPtr
->nItemHeight
;
1044 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1045 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1047 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1053 /******** Item iterator functions **********************************/
1055 static RANGES
ranges_create(int count
);
1056 static void ranges_destroy(RANGES ranges
);
1057 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1058 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1059 static void ranges_dump(RANGES ranges
);
1061 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1063 RANGE range
= { nItem
, nItem
+ 1 };
1065 return ranges_add(ranges
, range
);
1068 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1070 RANGE range
= { nItem
, nItem
+ 1 };
1072 return ranges_del(ranges
, range
);
1076 * ITERATOR DOCUMENTATION
1078 * The iterator functions allow for easy, and convenient iteration
1079 * over items of interest in the list. Typically, you create a
1080 * iterator, use it, and destroy it, as such:
1083 * iterator_xxxitems(&i, ...);
1084 * while (iterator_{prev,next}(&i)
1086 * //code which uses i.nItem
1088 * iterator_destroy(&i);
1090 * where xxx is either: framed, or visible.
1091 * Note that it is important that the code destroys the iterator
1092 * after it's done with it, as the creation of the iterator may
1093 * allocate memory, which thus needs to be freed.
1095 * You can iterate both forwards, and backwards through the list,
1096 * by using iterator_next or iterator_prev respectively.
1098 * Lower numbered items are draw on top of higher number items in
1099 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1100 * items may overlap). So, to test items, you should use
1102 * which lists the items top to bottom (in Z-order).
1103 * For drawing items, you should use
1105 * which lists the items bottom to top (in Z-order).
1106 * If you keep iterating over the items after the end-of-items
1107 * marker (-1) is returned, the iterator will start from the
1108 * beginning. Typically, you don't need to test for -1,
1109 * because iterator_{next,prev} will return TRUE if more items
1110 * are to be iterated over, or FALSE otherwise.
1112 * Note: the iterator is defined to be bidirectional. That is,
1113 * any number of prev followed by any number of next, or
1114 * five versa, should leave the iterator at the same item:
1115 * prev * n, next * n = next * n, prev * n
1117 * The iterator has a notion of an out-of-order, special item,
1118 * which sits at the start of the list. This is used in
1119 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1120 * which needs to be first, as it may overlap other items.
1122 * The code is a bit messy because we have:
1123 * - a special item to deal with
1124 * - simple range, or composite range
1126 * If you find bugs, or want to add features, please make sure you
1127 * always check/modify *both* iterator_prev, and iterator_next.
1131 * This function iterates through the items in increasing order,
1132 * but prefixed by the special item, then -1. That is:
1133 * special, 1, 2, 3, ..., n, -1.
1134 * Each item is listed only once.
1136 static inline BOOL
iterator_next(ITERATOR
* i
)
1140 i
->nItem
= i
->nSpecial
;
1141 if (i
->nItem
!= -1) return TRUE
;
1143 if (i
->nItem
== i
->nSpecial
)
1145 if (i
->ranges
) i
->index
= 0;
1151 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1152 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1157 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1158 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1161 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1163 i
->nItem
= i
->range
.lower
;
1164 if (i
->nItem
>= 0) goto testitem
;
1171 * This function iterates through the items in decreasing order,
1172 * followed by the special item, then -1. That is:
1173 * n, n-1, ..., 3, 2, 1, special, -1.
1174 * Each item is listed only once.
1176 static inline BOOL
iterator_prev(ITERATOR
* i
)
1183 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1186 if (i
->nItem
== i
->nSpecial
)
1194 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1195 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1201 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1204 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1206 i
->nItem
= i
->range
.upper
;
1207 if (i
->nItem
> 0) goto testitem
;
1209 return (i
->nItem
= i
->nSpecial
) != -1;
1212 static RANGE
iterator_range(const ITERATOR
*i
)
1216 if (!i
->ranges
) return i
->range
;
1218 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1220 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1221 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1223 else range
.lower
= range
.upper
= 0;
1229 * Releases resources associated with this ierator.
1231 static inline void iterator_destroy(const ITERATOR
*i
)
1233 ranges_destroy(i
->ranges
);
1237 * Create an empty iterator.
1239 static inline BOOL
iterator_empty(ITERATOR
* i
)
1241 ZeroMemory(i
, sizeof(*i
));
1242 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1247 * Create an iterator over a range.
1249 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1257 * Create an iterator over a bunch of ranges.
1258 * Please note that the iterator will take ownership of the ranges,
1259 * and will free them upon destruction.
1261 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1269 * Creates an iterator over the items which intersect lprc.
1271 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1273 RECT frame
= *lprc
, rcItem
, rcTemp
;
1276 /* in case we fail, we want to return an empty iterator */
1277 if (!iterator_empty(i
)) return FALSE
;
1279 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1281 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1282 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1284 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1288 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1290 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1291 if (IntersectRect(&rcTemp
, &rcItem
, lprc
))
1292 i
->nSpecial
= infoPtr
->nFocusedItem
;
1294 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1295 /* to do better here, we need to have PosX, and PosY sorted */
1296 TRACE("building icon ranges:\n");
1297 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1299 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1300 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1301 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1302 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1303 if (IntersectRect(&rcTemp
, &rcItem
, &frame
))
1304 ranges_additem(i
->ranges
, nItem
);
1308 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1312 if (frame
.left
>= infoPtr
->nItemWidth
) return TRUE
;
1313 if (frame
.top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1315 range
.lower
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1316 range
.upper
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1317 if (range
.upper
<= range
.lower
) return TRUE
;
1318 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1319 TRACE(" report=%s\n", debugrange(&i
->range
));
1323 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1324 INT nFirstRow
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1325 INT nLastRow
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1332 if (infoPtr
->nItemWidth
)
1334 nFirstCol
= max(frame
.left
/ infoPtr
->nItemWidth
, 0);
1335 nLastCol
= min((frame
.right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1339 nFirstCol
= max(frame
.left
, 0);
1340 nLastCol
= min(frame
.right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1343 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1345 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1346 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1348 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1350 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1351 TRACE("building list ranges:\n");
1352 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1354 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1355 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1356 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1357 TRACE(" list=%s\n", debugrange(&item_range
));
1358 ranges_add(i
->ranges
, item_range
);
1366 * Creates an iterator over the items which intersect the visible region of hdc.
1368 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1370 POINT Origin
, Position
;
1371 RECT rcItem
, rcClip
;
1374 rgntype
= GetClipBox(hdc
, &rcClip
);
1375 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1376 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1377 if (rgntype
== SIMPLEREGION
) return TRUE
;
1379 /* first deal with the special item */
1380 if (i
->nSpecial
!= -1)
1382 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1383 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1386 /* if we can't deal with the region, we'll just go with the simple range */
1387 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1388 TRACE("building visible range:\n");
1389 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1391 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1392 if (!ranges_add(i
->ranges
, i
->range
))
1394 ranges_destroy(i
->ranges
);
1400 /* now delete the invisible items from the list */
1401 while(iterator_next(i
))
1403 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1404 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1405 rcItem
.top
= Position
.y
+ Origin
.y
;
1406 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1407 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1408 if (!RectVisible(hdc
, &rcItem
))
1409 ranges_delitem(i
->ranges
, i
->nItem
);
1411 /* the iterator should restart on the next iterator_next */
1417 /******** Misc helper functions ************************************/
1419 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1420 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1422 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1423 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1426 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1428 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1429 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1432 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1434 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1435 if(state
== 1 || state
== 2)
1439 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1440 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1441 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1445 /* this should be called after window style got updated,
1446 it used to reset view state to match current window style */
1447 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1449 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1452 infoPtr
->uView
= LV_VIEW_ICON
;
1455 infoPtr
->uView
= LV_VIEW_DETAILS
;
1458 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1461 infoPtr
->uView
= LV_VIEW_LIST
;
1465 /* computes next item id value */
1466 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1468 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1472 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1473 return lpID
->id
+ 1;
1478 /******** Internal API functions ************************************/
1480 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1482 static COLUMN_INFO mainItem
;
1484 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1485 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1487 /* update cached column rectangles */
1488 if (infoPtr
->colRectsDirty
)
1491 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1494 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1495 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1496 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1498 Ptr
->colRectsDirty
= FALSE
;
1501 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1504 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1506 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1509 if (infoPtr
->hwndHeader
) return 0;
1511 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1513 /* setup creation flags */
1514 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1515 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1517 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1520 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1521 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1522 if (!infoPtr
->hwndHeader
) return -1;
1524 /* set header unicode format */
1525 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1527 /* set header font */
1528 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, (LPARAM
)TRUE
);
1530 LISTVIEW_UpdateSize(infoPtr
);
1535 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1537 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1540 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1542 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1545 /* used to handle collapse main item column case */
1546 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1548 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1549 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1552 /* Listview invalidation functions: use _only_ these functions to invalidate */
1554 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1556 return infoPtr
->bRedraw
;
1559 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1561 if(!is_redrawing(infoPtr
)) return;
1562 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1563 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1566 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1570 if(!is_redrawing(infoPtr
)) return;
1571 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1572 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1575 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1577 POINT Origin
, Position
;
1580 if(!is_redrawing(infoPtr
)) return;
1581 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1582 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1583 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1584 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1586 rcBox
.bottom
= infoPtr
->nItemHeight
;
1587 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1588 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1591 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1593 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1596 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1600 if(!is_redrawing(infoPtr
)) return;
1601 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1602 rcCol
.top
= infoPtr
->rcList
.top
;
1603 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1604 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1609 * Retrieves the number of items that can fit vertically in the client area.
1612 * [I] infoPtr : valid pointer to the listview structure
1615 * Number of items per row.
1617 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1619 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1621 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1626 * Retrieves the number of items that can fit horizontally in the client
1630 * [I] infoPtr : valid pointer to the listview structure
1633 * Number of items per column.
1635 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1637 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1639 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1643 /*************************************************************************
1644 * LISTVIEW_ProcessLetterKeys
1646 * Processes keyboard messages generated by pressing the letter keys
1648 * What this does is perform a case insensitive search from the
1649 * current position with the following quirks:
1650 * - If two chars or more are pressed in quick succession we search
1651 * for the corresponding string (e.g. 'abc').
1652 * - If there is a delay we wipe away the current search string and
1653 * restart with just that char.
1654 * - If the user keeps pressing the same character, whether slowly or
1655 * fast, so that the search string is entirely composed of this
1656 * character ('aaaaa' for instance), then we search for first item
1657 * that starting with that character.
1658 * - If the user types the above character in quick succession, then
1659 * we must also search for the corresponding string ('aaaaa'), and
1660 * go to that string if there is a match.
1663 * [I] hwnd : handle to the window
1664 * [I] charCode : the character code, the actual character
1665 * [I] keyData : key data
1673 * - The current implementation has a list of characters it will
1674 * accept and it ignores everything else. In particular it will
1675 * ignore accentuated characters which seems to match what
1676 * Windows does. But I'm not sure it makes sense to follow
1678 * - We don't sound a beep when the search fails.
1682 * TREEVIEW_ProcessLetterKeys
1684 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1689 WCHAR buffer
[MAX_PATH
];
1690 DWORD lastKeyPressTimestamp
= infoPtr
->lastKeyPressTimestamp
;
1692 /* simple parameter checking */
1693 if (!charCode
|| !keyData
) return 0;
1695 /* only allow the valid WM_CHARs through */
1696 if (!isalnumW(charCode
) &&
1697 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1698 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1699 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1700 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1701 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1702 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1703 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1704 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1705 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1708 /* if there's one item or less, there is no where to go */
1709 if (infoPtr
->nItemCount
<= 1) return 0;
1711 /* update the search parameters */
1712 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1713 if (infoPtr
->lastKeyPressTimestamp
- lastKeyPressTimestamp
< KEY_DELAY
) {
1714 if (infoPtr
->nSearchParamLength
< MAX_PATH
-1)
1715 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
1716 if (infoPtr
->charCode
!= charCode
)
1717 infoPtr
->charCode
= charCode
= 0;
1719 infoPtr
->charCode
=charCode
;
1720 infoPtr
->szSearchParam
[0]=charCode
;
1721 infoPtr
->nSearchParamLength
=1;
1722 /* Redundant with the 1 char string */
1726 /* and search from the current position */
1728 if (infoPtr
->nFocusedItem
>= 0) {
1729 endidx
=infoPtr
->nFocusedItem
;
1731 /* if looking for single character match,
1732 * then we must always move forward
1734 if (infoPtr
->nSearchParamLength
== 1)
1737 endidx
=infoPtr
->nItemCount
;
1741 /* Let application handle this for virtual listview */
1742 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1747 ZeroMemory(&lvfi
, sizeof(lvfi
));
1748 lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1749 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = '\0';
1750 lvfi
.psz
= infoPtr
->szSearchParam
;
1754 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1757 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1763 if (idx
== infoPtr
->nItemCount
) {
1764 if (endidx
== infoPtr
->nItemCount
|| endidx
== 0)
1770 item
.mask
= LVIF_TEXT
;
1773 item
.pszText
= buffer
;
1774 item
.cchTextMax
= MAX_PATH
;
1775 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1777 /* check for a match */
1778 if (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
1781 } else if ( (charCode
!= 0) && (nItem
== -1) && (nItem
!= infoPtr
->nFocusedItem
) &&
1782 (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
1783 /* This would work but we must keep looking for a longer match */
1787 } while (idx
!= endidx
);
1790 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1795 /*************************************************************************
1796 * LISTVIEW_UpdateHeaderSize [Internal]
1798 * Function to resize the header control
1801 * [I] hwnd : handle to a window
1802 * [I] nNewScrollPos : scroll pos to set
1807 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1812 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1814 if (!infoPtr
->hwndHeader
) return;
1816 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1817 point
[0].x
= winRect
.left
;
1818 point
[0].y
= winRect
.top
;
1819 point
[1].x
= winRect
.right
;
1820 point
[1].y
= winRect
.bottom
;
1822 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1823 point
[0].x
= -nNewScrollPos
;
1824 point
[1].x
+= nNewScrollPos
;
1826 SetWindowPos(infoPtr
->hwndHeader
,0,
1827 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1828 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1829 SWP_NOZORDER
| SWP_NOACTIVATE
);
1834 * Update the scrollbars. This functions should be called whenever
1835 * the content, size or view changes.
1838 * [I] infoPtr : valid pointer to the listview structure
1843 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
1845 SCROLLINFO horzInfo
, vertInfo
;
1848 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
1850 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
1851 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
1852 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1854 /* for now, we'll set info.nMax to the _count_, and adjust it later */
1855 if (infoPtr
->uView
== LV_VIEW_LIST
)
1857 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
1858 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
1860 /* scroll by at least one column per page */
1861 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
1862 horzInfo
.nPage
= infoPtr
->nItemWidth
;
1864 if (infoPtr
->nItemWidth
)
1865 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
1867 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1869 horzInfo
.nMax
= infoPtr
->nItemWidth
;
1871 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
1875 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
1878 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1879 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
1880 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
1881 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
1882 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
1884 /* Setting the horizontal scroll can change the listview size
1885 * (and potentially everything else) so we need to recompute
1886 * everything again for the vertical scroll
1889 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
1890 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
1891 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1893 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1895 vertInfo
.nMax
= infoPtr
->nItemCount
;
1897 /* scroll by at least one page */
1898 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
1899 vertInfo
.nPage
= infoPtr
->nItemHeight
;
1901 if (infoPtr
->nItemHeight
> 0)
1902 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
1904 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
1908 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
1911 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1912 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
1913 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
1914 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
1915 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
1917 /* Change of the range may have changed the scroll pos. If so move the content */
1918 if (dx
!= 0 || dy
!= 0)
1921 listRect
= infoPtr
->rcList
;
1922 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
1923 SW_ERASE
| SW_INVALIDATE
);
1926 /* Update the Header Control */
1927 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1929 horzInfo
.fMask
= SIF_POS
;
1930 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
1931 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
1938 * Shows/hides the focus rectangle.
1941 * [I] infoPtr : valid pointer to the listview structure
1942 * [I] fShow : TRUE to show the focus, FALSE to hide it.
1947 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
1951 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
1953 if (infoPtr
->nFocusedItem
< 0) return;
1955 /* we need some gymnastics in ICON mode to handle large items */
1956 if (infoPtr
->uView
== LV_VIEW_ICON
)
1960 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
1961 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
1963 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1968 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
1970 /* for some reason, owner draw should work only in report mode */
1971 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
1976 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
1977 HFONT hOldFont
= SelectObject(hdc
, hFont
);
1979 item
.iItem
= infoPtr
->nFocusedItem
;
1981 item
.mask
= LVIF_PARAM
;
1982 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
1984 ZeroMemory(&dis
, sizeof(dis
));
1985 dis
.CtlType
= ODT_LISTVIEW
;
1986 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1987 dis
.itemID
= item
.iItem
;
1988 dis
.itemAction
= ODA_FOCUS
;
1989 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
1990 dis
.hwndItem
= infoPtr
->hwndSelf
;
1992 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
1993 dis
.itemData
= item
.lParam
;
1995 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
1997 SelectObject(hdc
, hOldFont
);
2001 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2004 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2008 * Invalidates all visible selected items.
2010 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2014 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2015 while(iterator_next(&i
))
2017 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2018 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2020 iterator_destroy(&i
);
2025 * DESCRIPTION: [INTERNAL]
2026 * Computes an item's (left,top) corner, relative to rcView.
2027 * That is, the position has NOT been made relative to the Origin.
2028 * This is deliberate, to avoid computing the Origin over, and
2029 * over again, when this function is called in a loop. Instead,
2030 * one can factor the computation of the Origin before the loop,
2031 * and offset the value returned by this function, on every iteration.
2034 * [I] infoPtr : valid pointer to the listview structure
2035 * [I] nItem : item number
2036 * [O] lpptOrig : item top, left corner
2041 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2043 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2045 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2047 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2048 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2050 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2052 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2053 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2054 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2056 else /* LV_VIEW_DETAILS */
2058 lpptPosition
->x
= REPORT_MARGINX
;
2059 /* item is always at zero indexed column */
2060 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2061 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2062 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2067 * DESCRIPTION: [INTERNAL]
2068 * Compute the rectangles of an item. This is to localize all
2069 * the computations in one place. If you are not interested in some
2070 * of these values, simply pass in a NULL -- the function is smart
2071 * enough to compute only what's necessary. The function computes
2072 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2073 * one, the BOX rectangle. This rectangle is very cheap to compute,
2074 * and is guaranteed to contain all the other rectangles. Computing
2075 * the ICON rect is also cheap, but all the others are potentially
2076 * expensive. This gives an easy and effective optimization when
2077 * searching (like point inclusion, or rectangle intersection):
2078 * first test against the BOX, and if TRUE, test against the desired
2080 * If the function does not have all the necessary information
2081 * to computed the requested rectangles, will crash with a
2082 * failed assertion. This is done so we catch all programming
2083 * errors, given that the function is called only from our code.
2085 * We have the following 'special' meanings for a few fields:
2086 * * If LVIS_FOCUSED is set, we assume the item has the focus
2087 * This is important in ICON mode, where it might get a larger
2088 * then usual rectangle
2090 * Please note that subitem support works only in REPORT mode.
2093 * [I] infoPtr : valid pointer to the listview structure
2094 * [I] lpLVItem : item to compute the measures for
2095 * [O] lprcBox : ptr to Box rectangle
2096 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2097 * [0] lprcSelectBox : ptr to select box rectangle
2098 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2099 * [O] lprcIcon : ptr to Icon rectangle
2100 * Same as LVM_GETITEMRECT with LVIR_ICON
2101 * [O] lprcStateIcon: ptr to State Icon rectangle
2102 * [O] lprcLabel : ptr to Label rectangle
2103 * Same as LVM_GETITEMRECT with LVIR_LABEL
2108 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2109 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2110 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2112 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2113 RECT Box
, SelectBox
, Icon
, Label
;
2114 COLUMN_INFO
*lpColumnInfo
= NULL
;
2115 SIZE labelSize
= { 0, 0 };
2117 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2119 /* Be smart and try to figure out the minimum we have to do */
2120 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2121 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2123 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2124 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2126 if (lprcSelectBox
) doSelectBox
= TRUE
;
2127 if (lprcLabel
) doLabel
= TRUE
;
2128 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2135 /************************************************************/
2136 /* compute the box rectangle (it should be cheap to do) */
2137 /************************************************************/
2138 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2139 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2141 if (lpLVItem
->iSubItem
)
2143 Box
= lpColumnInfo
->rcHeader
;
2148 Box
.right
= infoPtr
->nItemWidth
;
2151 Box
.bottom
= infoPtr
->nItemHeight
;
2153 /******************************************************************/
2154 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2155 /******************************************************************/
2158 LONG state_width
= 0;
2160 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2161 state_width
= infoPtr
->iconStateSize
.cx
;
2163 if (infoPtr
->uView
== LV_VIEW_ICON
)
2165 Icon
.left
= Box
.left
+ state_width
;
2166 if (infoPtr
->himlNormal
)
2167 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2168 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2169 Icon
.right
= Icon
.left
;
2170 Icon
.bottom
= Icon
.top
;
2171 if (infoPtr
->himlNormal
)
2173 Icon
.right
+= infoPtr
->iconSize
.cx
;
2174 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2177 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2179 Icon
.left
= Box
.left
+ state_width
;
2181 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2183 /* we need the indent in report mode */
2184 assert(lpLVItem
->mask
& LVIF_INDENT
);
2185 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2189 Icon
.right
= Icon
.left
;
2190 if (infoPtr
->himlSmall
&&
2191 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 || (lpColumnInfo
->fmt
& LVCFMT_IMAGE
) ||
2192 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2193 Icon
.right
+= infoPtr
->iconSize
.cx
;
2194 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2196 if(lprcIcon
) *lprcIcon
= Icon
;
2197 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2199 /* TODO: is this correct? */
2202 lprcStateIcon
->left
= Icon
.left
- state_width
;
2203 lprcStateIcon
->right
= Icon
.left
;
2204 lprcStateIcon
->top
= Icon
.top
;
2205 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2206 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2209 else Icon
.right
= 0;
2211 /************************************************************/
2212 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2213 /************************************************************/
2216 /* calculate how far to the right can the label stretch */
2217 Label
.right
= Box
.right
;
2218 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2220 if (lpLVItem
->iSubItem
== 0)
2222 /* we need a zero based rect here */
2223 Label
= lpColumnInfo
->rcHeader
;
2224 OffsetRect(&Label
, -Label
.left
, 0);
2228 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2230 labelSize
.cx
= infoPtr
->nItemWidth
;
2231 labelSize
.cy
= infoPtr
->nItemHeight
;
2235 /* we need the text in non owner draw mode */
2236 assert(lpLVItem
->mask
& LVIF_TEXT
);
2237 if (is_textT(lpLVItem
->pszText
, TRUE
))
2239 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2240 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2241 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2245 /* compute rough rectangle where the label will go */
2246 SetRectEmpty(&rcText
);
2247 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2248 rcText
.bottom
= infoPtr
->nItemHeight
;
2249 if (infoPtr
->uView
== LV_VIEW_ICON
)
2250 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2252 /* now figure out the flags */
2253 if (infoPtr
->uView
== LV_VIEW_ICON
)
2254 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2256 uFormat
= LV_SL_DT_FLAGS
;
2258 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2260 if (rcText
.right
!= rcText
.left
)
2261 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2263 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2265 SelectObject(hdc
, hOldFont
);
2266 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2270 if (infoPtr
->uView
== LV_VIEW_ICON
)
2272 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2273 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2274 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2275 Label
.right
= Label
.left
+ labelSize
.cx
;
2276 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2277 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2279 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2280 labelSize
.cy
/= infoPtr
->ntmHeight
;
2281 labelSize
.cy
= max(labelSize
.cy
, 1);
2282 labelSize
.cy
*= infoPtr
->ntmHeight
;
2284 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2286 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2288 Label
.left
= Icon
.right
;
2289 Label
.top
= Box
.top
;
2290 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2291 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2292 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2294 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2296 Label
.left
= Icon
.right
;
2297 Label
.top
= Box
.top
;
2298 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2299 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2302 if (lprcLabel
) *lprcLabel
= Label
;
2303 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2306 /************************************************************/
2307 /* compute SELECT bounding box */
2308 /************************************************************/
2311 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2313 SelectBox
.left
= Icon
.left
;
2314 SelectBox
.top
= Box
.top
;
2315 SelectBox
.bottom
= Box
.bottom
;
2318 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2320 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2324 UnionRect(&SelectBox
, &Icon
, &Label
);
2326 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2327 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2330 /* Fix the Box if necessary */
2333 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2334 else *lprcBox
= Box
;
2336 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2340 * DESCRIPTION: [INTERNAL]
2343 * [I] infoPtr : valid pointer to the listview structure
2344 * [I] nItem : item number
2345 * [O] lprcBox : ptr to Box rectangle
2350 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2352 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2353 POINT Position
, Origin
;
2356 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2357 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2359 /* Be smart and try to figure out the minimum we have to do */
2361 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2362 lvItem
.mask
|= LVIF_TEXT
;
2363 lvItem
.iItem
= nItem
;
2364 lvItem
.iSubItem
= 0;
2365 lvItem
.pszText
= szDispText
;
2366 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2367 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2368 if (infoPtr
->uView
== LV_VIEW_ICON
)
2370 lvItem
.mask
|= LVIF_STATE
;
2371 lvItem
.stateMask
= LVIS_FOCUSED
;
2372 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2374 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2376 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2377 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2379 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2382 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2385 /* LISTVIEW_MapIdToIndex helper */
2386 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2388 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2389 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2391 if (id1
->id
== id2
->id
) return 0;
2393 return (id1
->id
< id2
->id
) ? -1 : 1;
2398 * Returns the item index for id specified.
2401 * [I] infoPtr : valid pointer to the listview structure
2402 * [I] iID : item id to get index for
2405 * Item index, or -1 on failure.
2407 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2412 TRACE("iID=%d\n", iID
);
2414 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2415 if (infoPtr
->nItemCount
== 0) return -1;
2418 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, &MapIdSearchCompare
, 0, DPAS_SORTED
);
2422 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2423 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2431 * Returns the item id for index given.
2434 * [I] infoPtr : valid pointer to the listview structure
2435 * [I] iItem : item index to get id for
2440 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2445 TRACE("iItem=%d\n", iItem
);
2447 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2448 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2450 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2451 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2453 return lpItem
->id
->id
;
2458 * Returns the current icon position, and advances it along the top.
2459 * The returned position is not offset by Origin.
2462 * [I] infoPtr : valid pointer to the listview structure
2463 * [O] lpPos : will get the current icon position
2468 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2470 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2472 *lpPos
= infoPtr
->currIconPos
;
2474 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2475 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2477 infoPtr
->currIconPos
.x
= 0;
2478 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2484 * Returns the current icon position, and advances it down the left edge.
2485 * The returned position is not offset by Origin.
2488 * [I] infoPtr : valid pointer to the listview structure
2489 * [O] lpPos : will get the current icon position
2494 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2496 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2498 *lpPos
= infoPtr
->currIconPos
;
2500 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2501 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2503 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2504 infoPtr
->currIconPos
.y
= 0;
2510 * Moves an icon to the specified position.
2511 * It takes care of invalidating the item, etc.
2514 * [I] infoPtr : valid pointer to the listview structure
2515 * [I] nItem : the item to move
2516 * [I] lpPos : the new icon position
2517 * [I] isNew : flags the item as being new
2523 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2529 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2530 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2532 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2533 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2536 /* Allocating a POINTER for every item is too resource intensive,
2537 * so we'll keep the (x,y) in different arrays */
2538 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2539 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2541 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2548 * Arranges listview items in icon display mode.
2551 * [I] infoPtr : valid pointer to the listview structure
2552 * [I] nAlignCode : alignment code
2558 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2560 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2564 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2566 TRACE("nAlignCode=%d\n", nAlignCode
);
2568 if (nAlignCode
== LVA_DEFAULT
)
2570 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2571 else nAlignCode
= LVA_ALIGNTOP
;
2576 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2577 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2578 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2579 default: return FALSE
;
2582 infoPtr
->bAutoarrange
= TRUE
;
2583 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2584 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2586 next_pos(infoPtr
, &pos
);
2587 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2595 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2596 * For LVS_REPORT always returns empty rectangle.
2599 * [I] infoPtr : valid pointer to the listview structure
2600 * [O] lprcView : bounding rectangle
2606 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2610 SetRectEmpty(lprcView
);
2612 switch (infoPtr
->uView
)
2615 case LV_VIEW_SMALLICON
:
2616 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2618 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2619 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2620 lprcView
->right
= max(lprcView
->right
, x
);
2621 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2623 if (infoPtr
->nItemCount
> 0)
2625 lprcView
->right
+= infoPtr
->nItemWidth
;
2626 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2631 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2632 x
= infoPtr
->nItemCount
/ y
;
2633 if (infoPtr
->nItemCount
% y
) x
++;
2634 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2635 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2642 * Retrieves the bounding rectangle of all the items.
2645 * [I] infoPtr : valid pointer to the listview structure
2646 * [O] lprcView : bounding rectangle
2652 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2656 TRACE("(lprcView=%p)\n", lprcView
);
2658 if (!lprcView
) return FALSE
;
2660 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2662 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2664 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2665 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2668 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2675 * Retrieves the subitem pointer associated with the subitem index.
2678 * [I] hdpaSubItems : DPA handle for a specific item
2679 * [I] nSubItem : index of subitem
2682 * SUCCESS : subitem pointer
2685 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2687 SUBITEM_INFO
*lpSubItem
;
2690 /* we should binary search here if need be */
2691 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2693 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2694 if (lpSubItem
->iSubItem
== nSubItem
)
2704 * Calculates the desired item width.
2707 * [I] infoPtr : valid pointer to the listview structure
2710 * The desired item width.
2712 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2716 TRACE("uView=%d\n", infoPtr
->uView
);
2718 if (infoPtr
->uView
== LV_VIEW_ICON
)
2719 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2720 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2722 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2727 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2728 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2730 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2731 nItemWidth
= rcHeader
.right
;
2734 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2738 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2739 nItemWidth
= max(LISTVIEW_GetLabelWidth(infoPtr
, i
), nItemWidth
);
2741 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2742 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2744 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2752 * Calculates the desired item height.
2755 * [I] infoPtr : valid pointer to the listview structure
2758 * The desired item height.
2760 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2764 TRACE("uView=%d\n", infoPtr
->uView
);
2766 if (infoPtr
->uView
== LV_VIEW_ICON
)
2767 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2770 nItemHeight
= infoPtr
->ntmHeight
;
2771 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
2773 if (infoPtr
->himlState
)
2774 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2775 if (infoPtr
->himlSmall
)
2776 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2777 if (infoPtr
->himlState
|| infoPtr
->himlSmall
)
2778 nItemHeight
+= HEIGHT_PADDING
;
2779 if (infoPtr
->nMeasureItemHeight
> 0)
2780 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2783 return max(nItemHeight
, 1);
2788 * Updates the width, and height of an item.
2791 * [I] infoPtr : valid pointer to the listview structure
2796 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2798 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2799 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2805 * Retrieves and saves important text metrics info for the current
2809 * [I] infoPtr : valid pointer to the listview structure
2812 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2814 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2815 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2816 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2820 if (GetTextMetricsW(hdc
, &tm
))
2822 infoPtr
->ntmHeight
= tm
.tmHeight
;
2823 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
2826 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
2827 infoPtr
->nEllipsisWidth
= sz
.cx
;
2829 SelectObject(hdc
, hOldFont
);
2830 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2832 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
2837 * A compare function for ranges
2840 * [I] range1 : pointer to range 1;
2841 * [I] range2 : pointer to range 2;
2845 * > 0 : if range 1 > range 2
2846 * < 0 : if range 2 > range 1
2847 * = 0 : if range intersects range 2
2849 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
2853 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
2855 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
2860 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
2866 #define ranges_check(ranges, desc) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
2868 #define ranges_check(ranges, desc) do { } while(0)
2871 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *func
, int line
)
2876 TRACE("*** Checking %s:%d:%s ***\n", func
, line
, desc
);
2878 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
2879 ranges_dump(ranges
);
2880 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
2882 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
2883 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
2884 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2886 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
2887 assert (prev
->upper
<= curr
->lower
);
2888 assert (curr
->lower
< curr
->upper
);
2892 TRACE("--- Done checking---\n");
2895 static RANGES
ranges_create(int count
)
2897 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
2898 if (!ranges
) return NULL
;
2899 ranges
->hdpa
= DPA_Create(count
);
2900 if (ranges
->hdpa
) return ranges
;
2905 static void ranges_clear(RANGES ranges
)
2909 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2910 Free(DPA_GetPtr(ranges
->hdpa
, i
));
2911 DPA_DeleteAllPtrs(ranges
->hdpa
);
2915 static void ranges_destroy(RANGES ranges
)
2917 if (!ranges
) return;
2918 ranges_clear(ranges
);
2919 DPA_Destroy(ranges
->hdpa
);
2923 static RANGES
ranges_clone(RANGES ranges
)
2928 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
2930 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2932 RANGE
*newrng
= Alloc(sizeof(RANGE
));
2933 if (!newrng
) goto fail
;
2934 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
2935 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
2940 TRACE ("clone failed\n");
2941 ranges_destroy(clone
);
2945 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
2949 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
2950 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
2955 static void ranges_dump(RANGES ranges
)
2959 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2960 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
2963 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
2965 RANGE srchrng
= { nItem
, nItem
+ 1 };
2967 TRACE("(nItem=%d)\n", nItem
);
2968 ranges_check(ranges
, "before contain");
2969 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
2972 static INT
ranges_itemcount(RANGES ranges
)
2976 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2978 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
2979 count
+= sel
->upper
- sel
->lower
;
2985 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
2987 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
2990 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2991 if (index
== -1) return TRUE
;
2993 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
2995 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
2996 if (chkrng
->lower
>= nItem
)
2997 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
2998 if (chkrng
->upper
> nItem
)
2999 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3004 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3009 TRACE("(%s)\n", debugrange(&range
));
3010 ranges_check(ranges
, "before add");
3012 /* try find overlapping regions first */
3013 srchrgn
.lower
= range
.lower
- 1;
3014 srchrgn
.upper
= range
.upper
+ 1;
3015 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3021 TRACE("Adding new range\n");
3023 /* create the brand new range to insert */
3024 newrgn
= Alloc(sizeof(RANGE
));
3025 if(!newrgn
) goto fail
;
3028 /* figure out where to insert it */
3029 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3030 TRACE("index=%d\n", index
);
3031 if (index
== -1) index
= 0;
3033 /* and get it over with */
3034 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3042 RANGE
*chkrgn
, *mrgrgn
;
3043 INT fromindex
, mergeindex
;
3045 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3046 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3048 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3049 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3051 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3053 /* merge now common ranges */
3055 srchrgn
.lower
= chkrgn
->lower
- 1;
3056 srchrgn
.upper
= chkrgn
->upper
+ 1;
3060 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3061 if (mergeindex
== -1) break;
3062 if (mergeindex
== index
)
3064 fromindex
= index
+ 1;
3068 TRACE("Merge with index %i\n", mergeindex
);
3070 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3071 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3072 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3074 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3075 if (mergeindex
< index
) index
--;
3079 ranges_check(ranges
, "after add");
3083 ranges_check(ranges
, "failed add");
3087 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3092 TRACE("(%s)\n", debugrange(&range
));
3093 ranges_check(ranges
, "before del");
3095 /* we don't use DPAS_SORTED here, since we need *
3096 * to find the first overlapping range */
3097 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3100 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3102 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3104 /* case 1: Same range */
3105 if ( (chkrgn
->upper
== range
.upper
) &&
3106 (chkrgn
->lower
== range
.lower
) )
3108 DPA_DeletePtr(ranges
->hdpa
, index
);
3111 /* case 2: engulf */
3112 else if ( (chkrgn
->upper
<= range
.upper
) &&
3113 (chkrgn
->lower
>= range
.lower
) )
3115 DPA_DeletePtr(ranges
->hdpa
, index
);
3117 /* case 3: overlap upper */
3118 else if ( (chkrgn
->upper
<= range
.upper
) &&
3119 (chkrgn
->lower
< range
.lower
) )
3121 chkrgn
->upper
= range
.lower
;
3123 /* case 4: overlap lower */
3124 else if ( (chkrgn
->upper
> range
.upper
) &&
3125 (chkrgn
->lower
>= range
.lower
) )
3127 chkrgn
->lower
= range
.upper
;
3130 /* case 5: fully internal */
3133 RANGE tmprgn
= *chkrgn
, *newrgn
;
3135 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3136 newrgn
->lower
= chkrgn
->lower
;
3137 newrgn
->upper
= range
.lower
;
3138 chkrgn
->lower
= range
.upper
;
3139 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3148 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3151 ranges_check(ranges
, "after del");
3155 ranges_check(ranges
, "failed del");
3161 * Removes all selection ranges
3164 * [I] infoPtr : valid pointer to the listview structure
3165 * [I] toSkip : item range to skip removing the selection
3171 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3180 lvItem
.stateMask
= LVIS_SELECTED
;
3182 /* need to clone the DPA because callbacks can change it */
3183 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3184 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3185 while(iterator_next(&i
))
3186 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3187 /* note that the iterator destructor will free the cloned range */
3188 iterator_destroy(&i
);
3193 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3197 if (!(toSkip
= ranges_create(1))) return FALSE
;
3198 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3199 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3200 ranges_destroy(toSkip
);
3204 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3206 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3211 * Retrieves the number of items that are marked as selected.
3214 * [I] infoPtr : valid pointer to the listview structure
3217 * Number of items selected.
3219 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3221 INT nSelectedCount
= 0;
3223 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3226 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3228 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3233 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3235 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3236 return nSelectedCount
;
3241 * Manages the item focus.
3244 * [I] infoPtr : valid pointer to the listview structure
3245 * [I] nItem : item index
3248 * TRUE : focused item changed
3249 * FALSE : focused item has NOT changed
3251 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3253 INT oldFocus
= infoPtr
->nFocusedItem
;
3256 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3258 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3259 lvItem
.stateMask
= LVIS_FOCUSED
;
3260 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3262 return oldFocus
!= infoPtr
->nFocusedItem
;
3265 /* Helper function for LISTVIEW_ShiftIndices *only* */
3266 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3268 if (nShiftItem
< nItem
) return nShiftItem
;
3270 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3272 if (direction
> 0) return nShiftItem
+ direction
;
3274 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3279 * Updates the various indices after an item has been inserted or deleted.
3282 * [I] infoPtr : valid pointer to the listview structure
3283 * [I] nItem : item index
3284 * [I] direction : Direction of shift, +1 or -1.
3289 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3294 /* temporarily disable change notification while shifting items */
3295 bOldChange
= infoPtr
->bDoChangeNotify
;
3296 infoPtr
->bDoChangeNotify
= FALSE
;
3298 TRACE("Shifting %iu, %i steps\n", nItem
, direction
);
3300 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3302 assert(abs(direction
) == 1);
3304 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3306 nNewFocus
= shift_item(infoPtr
, infoPtr
->nFocusedItem
, nItem
, direction
);
3307 if (nNewFocus
!= infoPtr
->nFocusedItem
)
3308 LISTVIEW_SetItemFocus(infoPtr
, nNewFocus
);
3310 /* But we are not supposed to modify nHotItem! */
3312 infoPtr
->bDoChangeNotify
= bOldChange
;
3318 * Adds a block of selections.
3321 * [I] infoPtr : valid pointer to the listview structure
3322 * [I] nItem : item index
3325 * Whether the window is still valid.
3327 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3329 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3330 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3331 HWND hwndSelf
= infoPtr
->hwndSelf
;
3332 NMLVODSTATECHANGE nmlv
;
3337 /* Temporarily disable change notification
3338 * If the control is LVS_OWNERDATA, we need to send
3339 * only one LVN_ODSTATECHANGED notification.
3340 * See MSDN documentation for LVN_ITEMCHANGED.
3342 bOldChange
= infoPtr
->bDoChangeNotify
;
3343 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3345 if (nFirst
== -1) nFirst
= nItem
;
3347 item
.state
= LVIS_SELECTED
;
3348 item
.stateMask
= LVIS_SELECTED
;
3350 for (i
= nFirst
; i
<= nLast
; i
++)
3351 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3353 ZeroMemory(&nmlv
, sizeof(nmlv
));
3354 nmlv
.iFrom
= nFirst
;
3357 nmlv
.uOldState
= item
.state
;
3359 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3360 if (!IsWindow(hwndSelf
))
3362 infoPtr
->bDoChangeNotify
= bOldChange
;
3369 * Sets a single group selection.
3372 * [I] infoPtr : valid pointer to the listview structure
3373 * [I] nItem : item index
3378 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3385 if (!(selection
= ranges_create(100))) return;
3387 item
.state
= LVIS_SELECTED
;
3388 item
.stateMask
= LVIS_SELECTED
;
3390 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3392 if (infoPtr
->nSelectionMark
== -1)
3394 infoPtr
->nSelectionMark
= nItem
;
3395 ranges_additem(selection
, nItem
);
3401 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3402 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3403 ranges_add(selection
, sel
);
3408 RECT rcItem
, rcSel
, rcSelMark
;
3411 rcItem
.left
= LVIR_BOUNDS
;
3412 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return;
3413 rcSelMark
.left
= LVIR_BOUNDS
;
3414 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) return;
3415 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3416 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3417 while(iterator_next(&i
))
3419 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3420 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3422 iterator_destroy(&i
);
3425 /* disable per item notifications on LVS_OWNERDATA style
3426 FIXME: single LVN_ODSTATECHANGED should be used */
3427 bOldChange
= infoPtr
->bDoChangeNotify
;
3428 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3430 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3433 iterator_rangesitems(&i
, selection
);
3434 while(iterator_next(&i
))
3435 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3436 /* this will also destroy the selection */
3437 iterator_destroy(&i
);
3439 infoPtr
->bDoChangeNotify
= bOldChange
;
3441 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3446 * Sets a single selection.
3449 * [I] infoPtr : valid pointer to the listview structure
3450 * [I] nItem : item index
3455 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3459 TRACE("nItem=%d\n", nItem
);
3461 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3463 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3464 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3465 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3467 infoPtr
->nSelectionMark
= nItem
;
3472 * Set selection(s) with keyboard.
3475 * [I] infoPtr : valid pointer to the listview structure
3476 * [I] nItem : item index
3477 * [I] space : VK_SPACE code sent
3480 * SUCCESS : TRUE (needs to be repainted)
3481 * FAILURE : FALSE (nothing has changed)
3483 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3485 /* FIXME: pass in the state */
3486 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3487 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3488 BOOL bResult
= FALSE
;
3490 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3491 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3495 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3496 LISTVIEW_SetSelection(infoPtr
, nItem
);
3500 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3504 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3505 lvItem
.stateMask
= LVIS_SELECTED
;
3508 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3509 if (lvItem
.state
& LVIS_SELECTED
)
3510 infoPtr
->nSelectionMark
= nItem
;
3512 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3515 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3518 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3522 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3524 LVHITTESTINFO lvHitTestInfo
;
3526 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3527 lvHitTestInfo
.pt
.x
= pt
.x
;
3528 lvHitTestInfo
.pt
.y
= pt
.y
;
3530 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3532 lpLVItem
->mask
= LVIF_PARAM
;
3533 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3534 lpLVItem
->iSubItem
= 0;
3536 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3539 static inline BOOL
LISTVIEW_isHotTracking(const LISTVIEW_INFO
*infoPtr
)
3541 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3542 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3543 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3548 * Called when the mouse is being actively tracked and has hovered for a specified
3552 * [I] infoPtr : valid pointer to the listview structure
3553 * [I] fwKeys : key indicator
3554 * [I] x,y : mouse position
3557 * 0 if the message was processed, non-zero if there was an error
3560 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3561 * over the item for a certain period of time.
3564 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3566 if (LISTVIEW_isHotTracking(infoPtr
))
3574 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3575 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3583 * Called whenever WM_MOUSEMOVE is received.
3586 * [I] infoPtr : valid pointer to the listview structure
3587 * [I] fwKeys : key indicator
3588 * [I] x,y : mouse position
3591 * 0 if the message is processed, non-zero if there was an error
3593 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3595 TRACKMOUSEEVENT trackinfo
;
3597 if (!(fwKeys
& MK_LBUTTON
))
3598 infoPtr
->bLButtonDown
= FALSE
;
3600 if (infoPtr
->bLButtonDown
)
3604 LVHITTESTINFO lvHitTestInfo
;
3605 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3606 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3608 rect
.left
= infoPtr
->ptClickPos
.x
- wDragWidth
;
3609 rect
.right
= infoPtr
->ptClickPos
.x
+ wDragWidth
;
3610 rect
.top
= infoPtr
->ptClickPos
.y
- wDragHeight
;
3611 rect
.bottom
= infoPtr
->ptClickPos
.y
+ wDragHeight
;
3616 lvHitTestInfo
.pt
= tmp
;
3617 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
3619 /* reset item marker */
3620 if (infoPtr
->nLButtonDownItem
!= lvHitTestInfo
.iItem
)
3621 infoPtr
->nLButtonDownItem
= -1;
3623 if (!PtInRect(&rect
, tmp
))
3625 /* this path covers the following:
3626 1. WM_LBUTTONDOWN over selected item (sets focus on it)
3627 2. change focus with keys
3628 3. move mouse over item from step 1 selects it and moves focus on it */
3629 if (infoPtr
->nLButtonDownItem
!= -1 &&
3630 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
3634 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3635 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3637 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
3638 infoPtr
->nLButtonDownItem
= -1;
3641 if (!infoPtr
->bDragging
)
3645 lvHitTestInfo
.pt
= infoPtr
->ptClickPos
;
3646 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
3648 ZeroMemory(&nmlv
, sizeof(nmlv
));
3649 nmlv
.iItem
= lvHitTestInfo
.iItem
;
3650 nmlv
.ptAction
= infoPtr
->ptClickPos
;
3652 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
3653 infoPtr
->bDragging
= TRUE
;
3660 /* see if we are supposed to be tracking mouse hovering */
3661 if (LISTVIEW_isHotTracking(infoPtr
)) {
3662 /* fill in the trackinfo struct */
3663 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
3664 trackinfo
.dwFlags
= TME_QUERY
;
3665 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
3666 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
3668 /* see if we are already tracking this hwnd */
3669 _TrackMouseEvent(&trackinfo
);
3671 if(!(trackinfo
.dwFlags
& TME_HOVER
)) {
3672 trackinfo
.dwFlags
= TME_HOVER
;
3674 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
3675 _TrackMouseEvent(&trackinfo
);
3684 * Tests whether the item is assignable to a list with style lStyle
3686 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
3688 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
3689 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
3690 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
3698 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
3701 * [I] infoPtr : valid pointer to the listview structure
3702 * [I] lpLVItem : valid pointer to new item attributes
3703 * [I] isNew : the item being set is being inserted
3704 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3705 * [O] bChanged : will be set to TRUE if the item really changed
3711 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
3717 /* stateMask is ignored for LVM_INSERTITEM */
3718 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
3722 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
3724 if (lpLVItem
->mask
== 0) return TRUE
;
3726 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3728 /* a virtual listview only stores selection and focus */
3729 if (lpLVItem
->mask
& ~LVIF_STATE
)
3735 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3736 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
3740 /* we need to get the lParam and state of the item */
3741 item
.iItem
= lpLVItem
->iItem
;
3742 item
.iSubItem
= lpLVItem
->iSubItem
;
3743 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
3744 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
3748 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
3750 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
3751 /* determine what fields will change */
3752 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
3753 uChanged
|= LVIF_STATE
;
3755 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
3756 uChanged
|= LVIF_IMAGE
;
3758 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
3759 uChanged
|= LVIF_PARAM
;
3761 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
3762 uChanged
|= LVIF_INDENT
;
3764 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
3765 uChanged
|= LVIF_TEXT
;
3767 TRACE("uChanged=0x%x\n", uChanged
);
3768 if (!uChanged
) return TRUE
;
3771 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
3772 nmlv
.iItem
= lpLVItem
->iItem
;
3773 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
3774 nmlv
.uOldState
= item
.state
;
3775 nmlv
.uChanged
= uChanged
;
3776 nmlv
.lParam
= item
.lParam
;
3778 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
3779 /* and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications */
3781 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
3783 HWND hwndSelf
= infoPtr
->hwndSelf
;
3785 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
3787 if (!IsWindow(hwndSelf
))
3791 /* copy information */
3792 if (lpLVItem
->mask
& LVIF_TEXT
)
3793 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3795 if (lpLVItem
->mask
& LVIF_IMAGE
)
3796 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
3798 if (lpLVItem
->mask
& LVIF_PARAM
)
3799 lpItem
->lParam
= lpLVItem
->lParam
;
3801 if (lpLVItem
->mask
& LVIF_INDENT
)
3802 lpItem
->iIndent
= lpLVItem
->iIndent
;
3804 if (uChanged
& LVIF_STATE
)
3806 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
3808 lpItem
->state
&= ~stateMask
;
3809 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
3811 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3813 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
3814 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3816 else if (stateMask
& LVIS_SELECTED
)
3818 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3820 /* if we are asked to change focus, and we manage it, do it */
3821 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
3823 if (lpLVItem
->state
& LVIS_FOCUSED
)
3825 if (infoPtr
->nFocusedItem
!= -1)
3827 /* remove current focus */
3828 item
.mask
= LVIF_STATE
;
3830 item
.stateMask
= LVIS_FOCUSED
;
3832 /* recurse with redrawing an item */
3833 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
3836 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
3837 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
3839 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
3841 infoPtr
->nFocusedItem
= -1;
3846 /* if we're inserting the item, we're done */
3847 if (isNew
) return TRUE
;
3849 /* send LVN_ITEMCHANGED notification */
3850 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
3851 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
3858 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
3861 * [I] infoPtr : valid pointer to the listview structure
3862 * [I] lpLVItem : valid pointer to new subitem attributes
3863 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3864 * [O] bChanged : will be set to TRUE if the item really changed
3870 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
3873 SUBITEM_INFO
*lpSubItem
;
3875 /* we do not support subitems for virtual listviews */
3876 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
3878 /* set subitem only if column is present */
3879 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
3881 /* First do some sanity checks */
3882 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
3883 particularly useful. We currently do not actually do anything with
3884 the flag on subitems.
3886 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
)) return FALSE
;
3887 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
3889 /* get the subitem structure, and create it if not there */
3890 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3891 assert (hdpaSubItems
);
3893 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
3896 SUBITEM_INFO
*tmpSubItem
;
3899 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
3900 if (!lpSubItem
) return FALSE
;
3901 /* we could binary search here, if need be...*/
3902 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
3904 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
3905 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
3907 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
3912 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
3913 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
3917 if (lpLVItem
->mask
& LVIF_IMAGE
)
3918 if (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
)
3920 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
3924 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
3926 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3935 * Sets item attributes.
3938 * [I] infoPtr : valid pointer to the listview structure
3939 * [I] lpLVItem : new item attributes
3940 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3946 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
3948 HWND hwndSelf
= infoPtr
->hwndSelf
;
3949 LPWSTR pszText
= NULL
;
3950 BOOL bResult
, bChanged
= FALSE
;
3952 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
3954 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
3957 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
3958 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_textW(lpLVItem
->pszText
))
3960 pszText
= lpLVItem
->pszText
;
3961 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
3964 /* actually set the fields */
3965 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
3967 if (lpLVItem
->iSubItem
)
3968 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
3970 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
3971 if (!IsWindow(hwndSelf
))
3974 /* redraw item, if necessary */
3975 if (bChanged
&& !infoPtr
->bIsDrawing
)
3977 /* this little optimization eliminates some nasty flicker */
3978 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
3979 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
3980 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
3981 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
3983 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
3988 textfreeT(lpLVItem
->pszText
, isW
);
3989 lpLVItem
->pszText
= pszText
;
3997 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4000 * [I] infoPtr : valid pointer to the listview structure
4005 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4008 SCROLLINFO scrollInfo
;
4010 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4011 scrollInfo
.fMask
= SIF_POS
;
4013 if (infoPtr
->uView
== LV_VIEW_LIST
)
4015 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4016 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4018 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4020 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4021 nItem
= scrollInfo
.nPos
;
4025 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4026 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4029 TRACE("nItem=%d\n", nItem
);
4037 * Erases the background of the given rectangle
4040 * [I] infoPtr : valid pointer to the listview structure
4041 * [I] hdc : device context handle
4042 * [I] lprcBox : clipping rectangle
4048 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4050 if (!infoPtr
->hBkBrush
) return FALSE
;
4052 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4054 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4062 * [I] infoPtr : valid pointer to the listview structure
4063 * [I] hdc : device context handle
4064 * [I] nItem : item index
4065 * [I] nSubItem : subitem index
4066 * [I] pos : item position in client coordinates
4067 * [I] cdmode : custom draw mode
4073 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
4076 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4077 static WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4078 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4080 RECT rcSelect
, rcBox
, rcIcon
, rcLabel
, rcStateIcon
;
4081 NMLVCUSTOMDRAW nmlvcd
;
4086 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, wine_dbgstr_point(&pos
));
4088 /* get information needed for drawing the item */
4089 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
4090 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
;
4091 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4092 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
;
4093 lvItem
.iItem
= nItem
;
4094 lvItem
.iSubItem
= nSubItem
;
4097 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4098 lvItem
.pszText
= szDispText
;
4099 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4100 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4101 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4102 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
4103 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4105 /* now check if we need to update the focus rectangle */
4106 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4108 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4109 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4110 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4111 OffsetRect(&rcSelect
, pos
.x
, pos
.y
);
4112 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
4113 OffsetRect(&rcStateIcon
, pos
.x
, pos
.y
);
4114 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
4115 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4116 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4117 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4119 /* fill in the custom draw structure */
4120 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4122 hOldFont
= GetCurrentObject(hdc
, OBJ_FONT
);
4123 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
4124 if (cdmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4125 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4126 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4127 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
4128 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4129 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
4130 if (nSubItem
== 0 && cdsubitemmode
== CDRF_NOTIFYITEMDRAW
)
4132 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4133 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4135 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4136 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4137 else if ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) == FALSE
)
4138 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4140 /* in full row select, subitems, will just use main item's colors */
4141 if (nSubItem
&& infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4142 nmlvcd
.clrTextBk
= CLR_NONE
;
4144 /* FIXME: temporary hack */
4145 rcSelect
.left
= rcLabel
.left
;
4147 /* draw the selection background, if we're drawing the main item */
4150 /* in icon mode, the label rect is really what we want to draw the
4152 if (infoPtr
->uView
== LV_VIEW_ICON
)
4155 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4157 /* we have to update left focus bound too if item isn't in leftmost column
4158 and reduce right box bound */
4159 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4163 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4165 INT Originx
= pos
.x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4166 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4167 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4169 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4170 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4174 rcSelect
.right
= rcBox
.right
;
4177 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
4178 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4179 /* store new focus rectangle */
4180 if (infoPtr
->nFocusedItem
== nItem
) infoPtr
->rcFocus
= rcSelect
;
4184 if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && (nSubItem
== 0))
4186 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
4189 TRACE("uStateImage=%d\n", uStateImage
);
4190 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
,
4191 rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4196 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4197 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4199 TRACE("iImage=%d\n", lvItem
.iImage
);
4200 ImageList_DrawEx(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
4201 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
, CLR_DEFAULT
,
4202 (lvItem
.state
& LVIS_SELECTED
) && (infoPtr
->bFocus
) ? ILD_SELECTED
: ILD_NORMAL
);
4205 /* Don't bother painting item being edited */
4206 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
4208 /* figure out the text drawing flags */
4209 uFormat
= (infoPtr
->uView
== LV_VIEW_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4210 if (infoPtr
->uView
== LV_VIEW_ICON
)
4211 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4214 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4216 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
4217 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
4218 default: uFormat
|= DT_LEFT
;
4221 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
4223 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4224 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4226 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4228 /* for GRIDLINES reduce the bottom so the text formats correctly */
4229 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4232 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
4235 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4236 notify_postpaint(infoPtr
, &nmlvcd
);
4237 if (cdsubitemmode
& CDRF_NEWFONT
)
4238 SelectObject(hdc
, hOldFont
);
4244 * Draws listview items when in owner draw mode.
4247 * [I] infoPtr : valid pointer to the listview structure
4248 * [I] hdc : device context handle
4253 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4255 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4256 DWORD cditemmode
= CDRF_DODEFAULT
;
4257 NMLVCUSTOMDRAW nmlvcd
;
4258 POINT Origin
, Position
;
4264 ZeroMemory(&dis
, sizeof(dis
));
4266 /* Get scroll info once before loop */
4267 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4269 /* iterate through the invalidated rows */
4270 while(iterator_next(i
))
4272 item
.iItem
= i
->nItem
;
4274 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4275 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4276 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4278 dis
.CtlType
= ODT_LISTVIEW
;
4280 dis
.itemID
= item
.iItem
;
4281 dis
.itemAction
= ODA_DRAWENTIRE
;
4283 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4284 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4285 dis
.hwndItem
= infoPtr
->hwndSelf
;
4287 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4288 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4289 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4290 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4291 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4292 dis
.itemData
= item
.lParam
;
4294 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4297 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4298 * structure for the rest. of the paint cycle
4300 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4301 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4302 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4304 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4306 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4307 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4310 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4311 notify_postpaint(infoPtr
, &nmlvcd
);
4317 * Draws listview items when in report display mode.
4320 * [I] infoPtr : valid pointer to the listview structure
4321 * [I] hdc : device context handle
4322 * [I] cdmode : custom draw mode
4327 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4330 RECT rcClip
, rcItem
;
4331 POINT Origin
, Position
;
4338 /* figure out what to draw */
4339 rgntype
= GetClipBox(hdc
, &rcClip
);
4340 if (rgntype
== NULLREGION
) return;
4342 /* Get scroll info once before loop */
4343 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4345 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4347 /* narrow down the columns we need to paint */
4348 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4350 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4352 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4353 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4354 ranges_additem(colRanges
, index
);
4356 iterator_rangesitems(&j
, colRanges
);
4358 /* in full row select, we _have_ to draw the main item */
4359 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4362 /* iterate through the invalidated rows */
4363 while(iterator_next(i
))
4365 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4366 Position
.y
+= Origin
.y
;
4368 /* iterate through the invalidated columns */
4369 while(iterator_next(&j
))
4371 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4372 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4374 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4377 rcItem
.bottom
= infoPtr
->nItemHeight
;
4378 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4379 if (!RectVisible(hdc
, &rcItem
)) continue;
4382 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
4385 iterator_destroy(&j
);
4390 * Draws the gridlines if necessary when in report display mode.
4393 * [I] infoPtr : valid pointer to the listview structure
4394 * [I] hdc : device context handle
4399 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4405 RECT rcClip
, rcItem
= {0};
4413 /* figure out what to draw */
4414 rgntype
= GetClipBox(hdc
, &rcClip
);
4415 if (rgntype
== NULLREGION
) return;
4417 /* Get scroll info once before loop */
4418 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4420 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4422 /* narrow down the columns we need to paint */
4423 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4425 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4427 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4428 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4429 ranges_additem(colRanges
, index
);
4432 /* is right most vertical line visible? */
4433 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4435 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4436 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4437 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
4440 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
4442 hOldPen
= SelectObject ( hdc
, hPen
);
4444 /* draw the vertical lines for the columns */
4445 iterator_rangesitems(&j
, colRanges
);
4446 while(iterator_next(&j
))
4448 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4449 if (rcItem
.left
== 0) continue; /* skip leftmost column */
4450 rcItem
.left
+= Origin
.x
;
4451 rcItem
.right
+= Origin
.x
;
4452 rcItem
.top
= infoPtr
->rcList
.top
;
4453 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
4454 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
4455 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4456 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
4458 iterator_destroy(&j
);
4459 /* draw rightmost grid line if visible */
4462 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4463 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4464 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4466 rcItem
.right
+= Origin
.x
;
4468 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
4469 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
4472 /* draw the horizontial lines for the rows */
4473 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
4474 rcItem
.left
= infoPtr
->rcList
.left
;
4475 rcItem
.right
= infoPtr
->rcList
.right
;
4476 rcItem
.bottom
= rcItem
.top
= Origin
.y
- 1;
4477 MoveToEx(hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4478 LineTo(hdc
, rcItem
.right
, rcItem
.top
);
4479 for(y
=itemheight
-1+Origin
.y
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
4481 rcItem
.bottom
= rcItem
.top
= y
;
4482 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
4483 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4484 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
4487 SelectObject( hdc
, hOldPen
);
4488 DeleteObject( hPen
);
4494 * Draws listview items when in list display mode.
4497 * [I] infoPtr : valid pointer to the listview structure
4498 * [I] hdc : device context handle
4499 * [I] cdmode : custom draw mode
4504 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4506 POINT Origin
, Position
;
4508 /* Get scroll info once before loop */
4509 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4511 while(iterator_prev(i
))
4513 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4514 Position
.x
+= Origin
.x
;
4515 Position
.y
+= Origin
.y
;
4517 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
4524 * Draws listview items.
4527 * [I] infoPtr : valid pointer to the listview structure
4528 * [I] hdc : device context handle
4529 * [I] prcErase : rect to be erased before refresh (may be NULL)
4534 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
4536 COLORREF oldTextColor
= 0, oldBkColor
= 0, oldClrTextBk
, oldClrText
;
4537 NMLVCUSTOMDRAW nmlvcd
;
4544 HBITMAP hbmp
= NULL
;
4547 LISTVIEW_DUMP(infoPtr
);
4549 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4550 TRACE("double buffering\n");
4552 hdc
= CreateCompatibleDC(hdcOrig
);
4554 ERR("Failed to create DC for backbuffer\n");
4557 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
4558 infoPtr
->rcList
.bottom
);
4560 ERR("Failed to create bitmap for backbuffer\n");
4565 SelectObject(hdc
, hbmp
);
4566 SelectObject(hdc
, infoPtr
->hFont
);
4568 /* Save dc values we're gonna trash while drawing
4569 * FIXME: Should be done in LISTVIEW_DrawItem() */
4570 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4571 oldBkMode
= GetBkMode(hdc
);
4572 oldBkColor
= GetBkColor(hdc
);
4573 oldTextColor
= GetTextColor(hdc
);
4576 infoPtr
->bIsDrawing
= TRUE
;
4579 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
4580 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4581 /* If no erasing was done (usually because RedrawWindow was called
4582 * with RDW_INVALIDATE only) we need to copy the old contents into
4583 * the backbuffer before continuing. */
4584 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
4585 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
4586 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
4587 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
4590 /* FIXME: Shouldn't need to do this */
4591 oldClrTextBk
= infoPtr
->clrTextBk
;
4592 oldClrText
= infoPtr
->clrText
;
4594 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
4596 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
4597 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
4598 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4599 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
4600 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4602 /* Use these colors to draw the items */
4603 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
4604 infoPtr
->clrText
= nmlvcd
.clrText
;
4606 /* nothing to draw */
4607 if(infoPtr
->nItemCount
== 0) goto enddraw
;
4609 /* figure out what we need to draw */
4610 iterator_visibleitems(&i
, infoPtr
, hdc
);
4611 range
= iterator_range(&i
);
4613 /* send cache hint notification */
4614 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4618 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
4619 nmlv
.iFrom
= range
.lower
;
4620 nmlv
.iTo
= range
.upper
- 1;
4621 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
4624 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
4625 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
4628 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4629 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
4630 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
4631 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
4633 /* if we have a focus rect and it's visible, draw it */
4634 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
4635 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
4636 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
4638 iterator_destroy(&i
);
4641 /* For LVS_EX_GRIDLINES go and draw lines */
4642 /* This includes the case where there were *no* items */
4643 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4644 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
4646 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
4647 notify_postpaint(infoPtr
, &nmlvcd
);
4649 infoPtr
->clrTextBk
= oldClrTextBk
;
4650 infoPtr
->clrText
= oldClrText
;
4653 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
4654 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
4655 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
4656 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
4661 SelectObject(hdc
, hOldFont
);
4662 SetBkMode(hdc
, oldBkMode
);
4663 SetBkColor(hdc
, oldBkColor
);
4664 SetTextColor(hdc
, oldTextColor
);
4667 infoPtr
->bIsDrawing
= FALSE
;
4673 * Calculates the approximate width and height of a given number of items.
4676 * [I] infoPtr : valid pointer to the listview structure
4677 * [I] nItemCount : number of items
4678 * [I] wWidth : width
4679 * [I] wHeight : height
4682 * Returns a DWORD. The width in the low word and the height in high word.
4684 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
4685 WORD wWidth
, WORD wHeight
)
4687 INT nItemCountPerColumn
= 1;
4688 INT nColumnCount
= 0;
4689 DWORD dwViewRect
= 0;
4691 if (nItemCount
== -1)
4692 nItemCount
= infoPtr
->nItemCount
;
4694 if (infoPtr
->uView
== LV_VIEW_LIST
)
4696 if (wHeight
== 0xFFFF)
4698 /* use current height */
4699 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
4702 if (wHeight
< infoPtr
->nItemHeight
)
4703 wHeight
= infoPtr
->nItemHeight
;
4707 if (infoPtr
->nItemHeight
> 0)
4709 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
4710 if (nItemCountPerColumn
== 0)
4711 nItemCountPerColumn
= 1;
4713 if (nItemCount
% nItemCountPerColumn
!= 0)
4714 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
4716 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
4720 /* Microsoft padding magic */
4721 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
4722 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
4724 dwViewRect
= MAKELONG(wWidth
, wHeight
);
4726 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4730 if (infoPtr
->nItemCount
> 0)
4732 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
4733 wWidth
= rcBox
.right
- rcBox
.left
;
4734 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
4738 /* use current height and width */
4739 if (wHeight
== 0xffff)
4740 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
4741 if (wWidth
== 0xffff)
4742 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
4745 dwViewRect
= MAKELONG(wWidth
, wHeight
);
4747 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
4748 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
4749 else if (infoPtr
->uView
== LV_VIEW_ICON
)
4750 FIXME("uView == LV_VIEW_ICON: not implemented\n");
4757 * Cancel edit label with saving item text.
4760 * [I] infoPtr : valid pointer to the listview structure
4763 * Always returns TRUE.
4765 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
4767 /* handle value will be lost after LISTVIEW_EndEditLabelT */
4768 HWND edit
= infoPtr
->hwndEdit
;
4770 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
4771 SendMessageW(edit
, WM_CLOSE
, 0, 0);
4778 * Create a drag image list for the specified item.
4781 * [I] infoPtr : valid pointer to the listview structure
4782 * [I] iItem : index of item
4783 * [O] lppt : Upper-left corner of the image
4786 * Returns a handle to the image list if successful, NULL otherwise.
4788 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
4794 HBITMAP hbmp
, hOldbmp
;
4795 HIMAGELIST dragList
= 0;
4796 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
4798 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
)
4801 rcItem
.left
= LVIR_BOUNDS
;
4802 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
4805 lppt
->x
= rcItem
.left
;
4806 lppt
->y
= rcItem
.top
;
4808 size
.cx
= rcItem
.right
- rcItem
.left
;
4809 size
.cy
= rcItem
.bottom
- rcItem
.top
;
4811 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
4812 hdc
= CreateCompatibleDC(hdcOrig
);
4813 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
4814 hOldbmp
= SelectObject(hdc
, hbmp
);
4816 rcItem
.left
= rcItem
.top
= 0;
4817 rcItem
.right
= size
.cx
;
4818 rcItem
.bottom
= size
.cy
;
4819 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
4822 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
4824 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4825 SelectObject(hdc
, hOldbmp
);
4826 ImageList_Add(dragList
, hbmp
, 0);
4829 SelectObject(hdc
, hOldbmp
);
4833 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
4835 TRACE("ret=%p\n", dragList
);
4843 * Removes all listview items and subitems.
4846 * [I] infoPtr : valid pointer to the listview structure
4852 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
4855 HDPA hdpaSubItems
= NULL
;
4862 /* we do it directly, to avoid notifications */
4863 ranges_clear(infoPtr
->selectionRanges
);
4864 infoPtr
->nSelectionMark
= -1;
4865 infoPtr
->nFocusedItem
= -1;
4866 SetRectEmpty(&infoPtr
->rcFocus
);
4867 /* But we are supposed to leave nHotItem as is! */
4870 /* send LVN_DELETEALLITEMS notification */
4871 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
4873 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
4875 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
4877 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4879 /* send LVN_DELETEITEM notification, if not suppressed
4880 and if it is not a virtual listview */
4881 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
4882 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
4883 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
4885 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
4886 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
4889 DPA_Destroy(hdpaSubItems
);
4890 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
4892 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
4893 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
4894 infoPtr
->nItemCount
--;
4899 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
4900 LISTVIEW_UpdateScroll(infoPtr
);
4902 LISTVIEW_InvalidateList(infoPtr
);
4909 * Scrolls, and updates the columns, when a column is changing width.
4912 * [I] infoPtr : valid pointer to the listview structure
4913 * [I] nColumn : column to scroll
4914 * [I] dx : amount of scroll, in pixels
4919 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
4921 COLUMN_INFO
*lpColumnInfo
;
4927 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
4928 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
4929 rcCol
= lpColumnInfo
->rcHeader
;
4930 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
4931 rcCol
.left
= rcCol
.right
;
4933 /* adjust the other columns */
4934 hdi
.mask
= HDI_ORDER
;
4935 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
4937 INT nOrder
= hdi
.iOrder
;
4938 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
4940 hdi
.mask
= HDI_ORDER
;
4941 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
4942 if (hdi
.iOrder
>= nOrder
) {
4943 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
4944 lpColumnInfo
->rcHeader
.left
+= dx
;
4945 lpColumnInfo
->rcHeader
.right
+= dx
;
4950 /* do not update screen if not in report mode */
4951 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
4953 /* Need to reset the item width when inserting a new column */
4954 infoPtr
->nItemWidth
+= dx
;
4956 LISTVIEW_UpdateScroll(infoPtr
);
4957 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
4959 /* scroll to cover the deleted column, and invalidate for redraw */
4960 rcOld
= infoPtr
->rcList
;
4961 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
4962 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4967 * Removes a column from the listview control.
4970 * [I] infoPtr : valid pointer to the listview structure
4971 * [I] nColumn : column index
4977 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
4981 TRACE("nColumn=%d\n", nColumn
);
4983 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
4984 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4986 /* While the MSDN specifically says that column zero should not be deleted,
4987 what actually happens is that the column itself is deleted but no items or subitems
4991 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
4993 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
4996 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
4997 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
4999 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5001 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5003 INT nItem
, nSubItem
, i
;
5005 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5007 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5010 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5012 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5013 if (lpSubItem
->iSubItem
== nColumn
)
5016 lpDelItem
= lpSubItem
;
5018 else if (lpSubItem
->iSubItem
> nColumn
)
5020 lpSubItem
->iSubItem
--;
5024 /* if we found our subitem, zapp it */
5028 if (is_textW(lpDelItem
->hdr
.pszText
))
5029 Free(lpDelItem
->hdr
.pszText
);
5034 /* free dpa memory */
5035 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5040 /* update the other column info */
5041 LISTVIEW_UpdateItemSize(infoPtr
);
5042 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5043 LISTVIEW_InvalidateList(infoPtr
);
5045 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5052 * Invalidates the listview after an item's insertion or deletion.
5055 * [I] infoPtr : valid pointer to the listview structure
5056 * [I] nItem : item index
5057 * [I] dir : -1 if deleting, 1 if inserting
5062 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5064 INT nPerCol
, nItemCol
, nItemRow
;
5068 /* if we don't refresh, what's the point of scrolling? */
5069 if (!is_redrawing(infoPtr
)) return;
5071 assert (abs(dir
) == 1);
5073 /* arrange icons if autoarrange is on */
5074 if (is_autoarrange(infoPtr
))
5076 BOOL arrange
= TRUE
;
5077 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5078 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5079 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5082 /* scrollbars need updating */
5083 LISTVIEW_UpdateScroll(infoPtr
);
5085 /* figure out the item's position */
5086 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5087 nPerCol
= infoPtr
->nItemCount
+ 1;
5088 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5089 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5090 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5093 nItemCol
= nItem
/ nPerCol
;
5094 nItemRow
= nItem
% nPerCol
;
5095 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5097 /* move the items below up a slot */
5098 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5099 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5100 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5101 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5102 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5103 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5104 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5106 TRACE("Scrolling rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5107 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5108 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5111 /* report has only that column, so we're done */
5112 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5114 /* now for LISTs, we have to deal with the columns to the right */
5115 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5117 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5118 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5119 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5120 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5121 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5122 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5127 * Removes an item from the listview control.
5130 * [I] infoPtr : valid pointer to the listview structure
5131 * [I] nItem : item index
5137 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5140 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5142 TRACE("(nItem=%d)\n", nItem
);
5144 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5146 /* remove selection, and focus */
5148 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5149 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5151 /* send LVN_DELETEITEM notification. */
5152 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5154 /* we need to do this here, because we'll be deleting stuff */
5156 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5158 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5166 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5167 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5169 /* free id struct */
5170 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5171 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5172 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5174 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5176 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5177 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5180 DPA_Destroy(hdpaSubItems
);
5185 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5186 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5189 infoPtr
->nItemCount
--;
5190 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5192 /* now is the invalidation fun */
5194 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5201 * Callback implementation for editlabel control
5204 * [I] infoPtr : valid pointer to the listview structure
5205 * [I] storeText : store edit box text as item text
5206 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5212 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5214 HWND hwndSelf
= infoPtr
->hwndSelf
;
5215 NMLVDISPINFOW dispInfo
;
5216 INT editedItem
= infoPtr
->nEditLabelItem
;
5218 WCHAR
*pszText
= NULL
;
5223 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5227 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5229 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5230 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5235 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5237 infoPtr
->nEditLabelItem
= -1;
5238 infoPtr
->hwndEdit
= 0;
5240 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5241 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5242 dispInfo
.item
.iItem
= editedItem
;
5243 dispInfo
.item
.iSubItem
= 0;
5244 dispInfo
.item
.stateMask
= ~0;
5245 if (!LISTVIEW_GetItemW(infoPtr
, &dispInfo
.item
))
5252 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5255 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5256 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5257 textfreeT(tmp
, FALSE
);
5265 /* add the text from the edit in */
5266 dispInfo
.item
.mask
|= LVIF_TEXT
;
5267 dispInfo
.item
.pszText
= pszText
;
5268 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5270 /* Do we need to update the Item Text */
5271 if (!notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
))
5276 if (!IsWindow(hwndSelf
))
5281 if (!pszText
) return TRUE
;
5283 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5285 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5286 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5287 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5289 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5295 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5296 dispInfo
.item
.mask
= LVIF_TEXT
;
5297 dispInfo
.item
.iItem
= editedItem
;
5298 dispInfo
.item
.iSubItem
= 0;
5299 dispInfo
.item
.pszText
= pszText
;
5300 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5301 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5311 * Begin in place editing of specified list view item
5314 * [I] infoPtr : valid pointer to the listview structure
5315 * [I] nItem : item index
5316 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
5322 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
5324 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5325 NMLVDISPINFOW dispInfo
;
5328 HWND hwndSelf
= infoPtr
->hwndSelf
;
5330 HFONT hOldFont
= NULL
;
5331 TEXTMETRICW textMetric
;
5333 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
5335 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
5337 /* Is the EditBox still there, if so remove it */
5338 if(infoPtr
->hwndEdit
!= 0)
5340 SetFocus(infoPtr
->hwndSelf
);
5341 infoPtr
->hwndEdit
= 0;
5344 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5346 infoPtr
->nEditLabelItem
= nItem
;
5348 LISTVIEW_SetSelection(infoPtr
, nItem
);
5349 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
5350 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5352 rect
.left
= LVIR_LABEL
;
5353 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
5355 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5356 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5357 dispInfo
.item
.iItem
= nItem
;
5358 dispInfo
.item
.iSubItem
= 0;
5359 dispInfo
.item
.stateMask
= ~0;
5360 dispInfo
.item
.pszText
= szDispText
;
5361 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5362 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
5364 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, WS_VISIBLE
, isW
);
5365 if (!infoPtr
->hwndEdit
) return 0;
5367 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
5369 if (!IsWindow(hwndSelf
))
5371 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
5372 infoPtr
->hwndEdit
= 0;
5376 /* Now position and display edit box */
5377 hdc
= GetDC(infoPtr
->hwndSelf
);
5379 /* Select the font to get appropriate metric dimensions */
5380 if(infoPtr
->hFont
!= 0)
5381 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5383 /* Get String Length in pixels */
5384 GetTextExtentPoint32W(hdc
, dispInfo
.item
.pszText
, lstrlenW(dispInfo
.item
.pszText
), &sz
);
5386 /* Add Extra spacing for the next character */
5387 GetTextMetricsW(hdc
, &textMetric
);
5388 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
5390 if(infoPtr
->hFont
!= 0)
5391 SelectObject(hdc
, hOldFont
);
5393 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
5395 MoveWindow(infoPtr
->hwndEdit
, rect
.left
- 2, rect
.top
- 1, sz
.cx
,
5396 rect
.bottom
- rect
.top
+ 2, FALSE
);
5397 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
5398 SetFocus(infoPtr
->hwndEdit
);
5399 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
5400 return infoPtr
->hwndEdit
;
5406 * Ensures the specified item is visible, scrolling into view if necessary.
5409 * [I] infoPtr : valid pointer to the listview structure
5410 * [I] nItem : item index
5411 * [I] bPartial : partially or entirely visible
5417 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
5419 INT nScrollPosHeight
= 0;
5420 INT nScrollPosWidth
= 0;
5421 INT nHorzAdjust
= 0;
5422 INT nVertAdjust
= 0;
5425 RECT rcItem
, rcTemp
;
5427 rcItem
.left
= LVIR_BOUNDS
;
5428 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
5430 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
5432 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
5434 /* scroll left/right, but in LV_VIEW_DETAILS mode */
5435 if (infoPtr
->uView
== LV_VIEW_LIST
)
5436 nScrollPosWidth
= infoPtr
->nItemWidth
;
5437 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
5438 nScrollPosWidth
= 1;
5440 if (rcItem
.left
< infoPtr
->rcList
.left
)
5443 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
5448 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
5452 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
5454 /* scroll up/down, but not in LVS_LIST mode */
5455 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5456 nScrollPosHeight
= infoPtr
->nItemHeight
;
5457 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
5458 nScrollPosHeight
= 1;
5460 if (rcItem
.top
< infoPtr
->rcList
.top
)
5463 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
5468 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
5472 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
5474 if (nScrollPosWidth
)
5476 INT diff
= nHorzDiff
/ nScrollPosWidth
;
5477 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
5478 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
5481 if (nScrollPosHeight
)
5483 INT diff
= nVertDiff
/ nScrollPosHeight
;
5484 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
5485 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
5493 * Searches for an item with specific characteristics.
5496 * [I] hwnd : window handle
5497 * [I] nStart : base item index
5498 * [I] lpFindInfo : item information to look for
5501 * SUCCESS : index of item
5504 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
5505 const LVFINDINFOW
*lpFindInfo
)
5507 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5508 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
5509 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
5510 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
5511 POINT Position
, Destination
;
5514 /* Search in virtual listviews should be done by application, not by
5515 listview control, so we just send LVN_ODFINDITEMW and return the result */
5516 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5520 nmlv
.iStart
= nStart
;
5521 nmlv
.lvfi
= *lpFindInfo
;
5522 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
5525 if (!lpFindInfo
|| nItem
< 0) return -1;
5528 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
))
5530 lvItem
.mask
|= LVIF_TEXT
;
5531 lvItem
.pszText
= szDispText
;
5532 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5535 if (lpFindInfo
->flags
& LVFI_WRAP
)
5538 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
5539 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
5544 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5545 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
5546 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
5547 switch(lpFindInfo
->vkDirection
)
5549 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
5550 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
5551 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
5552 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
5553 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
5554 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
5555 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
5557 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
5558 Destination
.x
= rcArea
.right
;
5559 Destination
.y
= rcArea
.bottom
;
5561 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
5565 else Destination
.x
= Destination
.y
= 0;
5567 /* if LVFI_PARAM is specified, all other flags are ignored */
5568 if (lpFindInfo
->flags
& LVFI_PARAM
)
5570 lvItem
.mask
|= LVIF_PARAM
;
5572 lvItem
.mask
&= ~LVIF_TEXT
;
5576 for (; nItem
< nLast
; nItem
++)
5578 lvItem
.iItem
= nItem
;
5579 lvItem
.iSubItem
= 0;
5580 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
5582 if (lvItem
.mask
& LVIF_PARAM
)
5584 if (lpFindInfo
->lParam
== lvItem
.lParam
)
5590 if (lvItem
.mask
& LVIF_TEXT
)
5592 if (lpFindInfo
->flags
& LVFI_PARTIAL
)
5594 if (strstrW(lvItem
.pszText
, lpFindInfo
->psz
) == NULL
) continue;
5598 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
5602 if (!bNearest
) return nItem
;
5604 /* This is very inefficient. To do a good job here,
5605 * we need a sorted array of (x,y) item positions */
5606 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
5608 /* compute the distance^2 to the destination */
5609 xdist
= Destination
.x
- Position
.x
;
5610 ydist
= Destination
.y
- Position
.y
;
5611 dist
= xdist
* xdist
+ ydist
* ydist
;
5613 /* remember the distance, and item if it's closer */
5617 nNearestItem
= nItem
;
5624 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
5629 return nNearestItem
;
5634 * Searches for an item with specific characteristics.
5637 * [I] hwnd : window handle
5638 * [I] nStart : base item index
5639 * [I] lpFindInfo : item information to look for
5642 * SUCCESS : index of item
5645 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
5646 const LVFINDINFOA
*lpFindInfo
)
5648 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
);
5653 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
5654 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
5655 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
5656 textfreeT(strW
, FALSE
);
5662 * Retrieves the background image of the listview control.
5665 * [I] infoPtr : valid pointer to the listview structure
5666 * [O] lpBkImage : background image attributes
5672 /* static BOOL LISTVIEW_GetBkImage(const LISTVIEW_INFO *infoPtr, LPLVBKIMAGE lpBkImage) */
5674 /* FIXME (listview, "empty stub!\n"); */
5680 * Retrieves column attributes.
5683 * [I] infoPtr : valid pointer to the listview structure
5684 * [I] nColumn : column index
5685 * [IO] lpColumn : column information
5686 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
5687 * otherwise it is in fact a LPLVCOLUMNA
5693 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
5695 COLUMN_INFO
*lpColumnInfo
;
5698 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5699 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
5701 /* initialize memory */
5702 ZeroMemory(&hdi
, sizeof(hdi
));
5704 if (lpColumn
->mask
& LVCF_TEXT
)
5706 hdi
.mask
|= HDI_TEXT
;
5707 hdi
.pszText
= lpColumn
->pszText
;
5708 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
5711 if (lpColumn
->mask
& LVCF_IMAGE
)
5712 hdi
.mask
|= HDI_IMAGE
;
5714 if (lpColumn
->mask
& LVCF_ORDER
)
5715 hdi
.mask
|= HDI_ORDER
;
5717 if (lpColumn
->mask
& LVCF_SUBITEM
)
5718 hdi
.mask
|= HDI_LPARAM
;
5720 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
5722 if (lpColumn
->mask
& LVCF_FMT
)
5723 lpColumn
->fmt
= lpColumnInfo
->fmt
;
5725 if (lpColumn
->mask
& LVCF_WIDTH
)
5726 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
5728 if (lpColumn
->mask
& LVCF_IMAGE
)
5729 lpColumn
->iImage
= hdi
.iImage
;
5731 if (lpColumn
->mask
& LVCF_ORDER
)
5732 lpColumn
->iOrder
= hdi
.iOrder
;
5734 if (lpColumn
->mask
& LVCF_SUBITEM
)
5735 lpColumn
->iSubItem
= hdi
.lParam
;
5737 if (lpColumn
->mask
& LVCF_MINWIDTH
)
5738 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
5744 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
5746 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
5751 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
5756 * Retrieves the column width.
5759 * [I] infoPtr : valid pointer to the listview structure
5760 * [I] int : column index
5763 * SUCCESS : column width
5766 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5768 INT nColumnWidth
= 0;
5771 TRACE("nColumn=%d\n", nColumn
);
5773 /* we have a 'column' in LIST and REPORT mode only */
5774 switch(infoPtr
->uView
)
5777 nColumnWidth
= infoPtr
->nItemWidth
;
5779 case LV_VIEW_DETAILS
:
5780 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
5781 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
5782 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
5784 * TODO: should we do the same in LVM_GETCOLUMN?
5786 hdItem
.mask
= HDI_WIDTH
;
5787 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
5789 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
5792 nColumnWidth
= hdItem
.cxy
;
5796 TRACE("nColumnWidth=%d\n", nColumnWidth
);
5797 return nColumnWidth
;
5802 * In list or report display mode, retrieves the number of items that can fit
5803 * vertically in the visible area. In icon or small icon display mode,
5804 * retrieves the total number of visible items.
5807 * [I] infoPtr : valid pointer to the listview structure
5810 * Number of fully visible items.
5812 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
5814 switch (infoPtr
->uView
)
5817 case LV_VIEW_SMALLICON
:
5818 return infoPtr
->nItemCount
;
5819 case LV_VIEW_DETAILS
:
5820 return LISTVIEW_GetCountPerColumn(infoPtr
);
5822 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
5830 * Retrieves an image list handle.
5833 * [I] infoPtr : valid pointer to the listview structure
5834 * [I] nImageList : image list identifier
5837 * SUCCESS : image list handle
5840 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
5844 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
5845 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
5846 case LVSIL_STATE
: return infoPtr
->himlState
;
5851 /* LISTVIEW_GetISearchString */
5855 * Retrieves item attributes.
5858 * [I] hwnd : window handle
5859 * [IO] lpLVItem : item info
5860 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
5861 * if FALSE, then lpLVItem is a LPLVITEMA.
5864 * This is the internal 'GetItem' interface -- it tries to
5865 * be smart and avoid text copies, if possible, by modifying
5866 * lpLVItem->pszText to point to the text string. Please note
5867 * that this is not always possible (e.g. OWNERDATA), so on
5868 * entry you *must* supply valid values for pszText, and cchTextMax.
5869 * The only difference to the documented interface is that upon
5870 * return, you should use *only* the lpLVItem->pszText, rather than
5871 * the buffer pointer you provided on input. Most code already does
5872 * that, so it's not a problem.
5873 * For the two cases when the text must be copied (that is,
5874 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
5880 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
5882 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
5883 NMLVDISPINFOW dispInfo
;
5889 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
5891 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
5894 if (lpLVItem
->mask
== 0) return TRUE
;
5896 /* make a local copy */
5897 isubitem
= lpLVItem
->iSubItem
;
5899 /* a quick optimization if all we're asked is the focus state
5900 * these queries are worth optimising since they are common,
5901 * and can be answered in constant time, without the heavy accesses */
5902 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
5903 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
5905 lpLVItem
->state
= 0;
5906 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5907 lpLVItem
->state
|= LVIS_FOCUSED
;
5911 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5913 /* if the app stores all the data, handle it separately */
5914 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5916 dispInfo
.item
.state
= 0;
5918 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
5919 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
5920 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
5922 UINT mask
= lpLVItem
->mask
;
5924 /* NOTE: copy only fields which we _know_ are initialized, some apps
5925 * depend on the uninitialized fields being 0 */
5926 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
5927 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
5928 dispInfo
.item
.iSubItem
= isubitem
;
5929 if (lpLVItem
->mask
& LVIF_TEXT
)
5931 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
5933 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
5936 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
5937 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
5940 if (lpLVItem
->mask
& LVIF_STATE
)
5941 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
5942 /* could be zeroed on LVIF_NORECOMPUTE case */
5943 if (dispInfo
.item
.mask
!= 0)
5945 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
5946 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
5947 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
5949 /* full size structure expected - _WIN32IE >= 0x560 */
5950 *lpLVItem
= dispInfo
.item
;
5952 else if (lpLVItem
->mask
& LVIF_INDENT
)
5954 /* indent member expected - _WIN32IE >= 0x300 */
5955 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
5959 /* minimal structure expected */
5960 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
5962 lpLVItem
->mask
= mask
;
5963 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
5967 /* make sure lParam is zeroed out */
5968 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
5970 /* callback marked pointer required here */
5971 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
5972 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
5974 /* we store only a little state, so if we're not asked, we're done */
5975 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
5977 /* if focus is handled by us, report it */
5978 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
5980 lpLVItem
->state
&= ~LVIS_FOCUSED
;
5981 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5982 lpLVItem
->state
|= LVIS_FOCUSED
;
5985 /* and do the same for selection, if we handle it */
5986 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
5988 lpLVItem
->state
&= ~LVIS_SELECTED
;
5989 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
5990 lpLVItem
->state
|= LVIS_SELECTED
;
5996 /* find the item and subitem structures before we proceed */
5997 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
5998 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6003 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6004 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6007 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6012 pItemHdr
= &lpItem
->hdr
;
6014 /* Do we need to query the state from the app? */
6015 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6017 dispInfo
.item
.mask
|= LVIF_STATE
;
6018 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6021 /* Do we need to enquire about the image? */
6022 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6023 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6025 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6026 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6029 /* Only items support indentation */
6030 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6033 dispInfo
.item
.mask
|= LVIF_INDENT
;
6034 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6037 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6038 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6039 !is_textW(pItemHdr
->pszText
))
6041 dispInfo
.item
.mask
|= LVIF_TEXT
;
6042 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6043 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6044 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6045 *dispInfo
.item
.pszText
= '\0';
6048 /* If we don't have all the requested info, query the application */
6049 if (dispInfo
.item
.mask
!= 0)
6051 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6052 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6053 dispInfo
.item
.lParam
= lpItem
->lParam
;
6054 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6055 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6058 /* we should not store values for subitems */
6059 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6061 /* Now, handle the iImage field */
6062 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6064 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6065 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6066 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6068 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6070 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6071 lpLVItem
->iImage
= pItemHdr
->iImage
;
6073 lpLVItem
->iImage
= 0;
6076 /* The pszText field */
6077 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6079 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6080 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6082 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6084 else if (lpLVItem
->mask
& LVIF_TEXT
)
6086 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6087 if (isW
|| !is_textW(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6088 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6091 /* Next is the lParam field */
6092 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6094 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6095 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6096 lpItem
->lParam
= dispInfo
.item
.lParam
;
6098 else if (lpLVItem
->mask
& LVIF_PARAM
)
6099 lpLVItem
->lParam
= lpItem
->lParam
;
6101 /* if this is a subitem, we're done */
6102 if (isubitem
) return TRUE
;
6104 /* ... the state field (this one is different due to uCallbackmask) */
6105 if (lpLVItem
->mask
& LVIF_STATE
)
6107 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6108 if (dispInfo
.item
.mask
& LVIF_STATE
)
6110 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6111 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6113 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6115 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6116 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6117 lpLVItem
->state
|= LVIS_FOCUSED
;
6119 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6121 lpLVItem
->state
&= ~LVIS_SELECTED
;
6122 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6123 lpLVItem
->state
|= LVIS_SELECTED
;
6127 /* and last, but not least, the indent field */
6128 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6130 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6131 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6132 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6134 else if (lpLVItem
->mask
& LVIF_INDENT
)
6136 lpLVItem
->iIndent
= lpItem
->iIndent
;
6144 * Retrieves item attributes.
6147 * [I] hwnd : window handle
6148 * [IO] lpLVItem : item info
6149 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6150 * if FALSE, then lpLVItem is a LPLVITEMA.
6153 * This is the external 'GetItem' interface -- it properly copies
6154 * the text in the provided buffer.
6160 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6165 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6168 pszText
= lpLVItem
->pszText
;
6169 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6170 if (bResult
&& lpLVItem
->pszText
!= pszText
)
6172 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6173 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6175 pszText
= LPSTR_TEXTCALLBACKW
;
6177 lpLVItem
->pszText
= pszText
;
6185 * Retrieves the position (upper-left) of the listview control item.
6186 * Note that for LVS_ICON style, the upper-left is that of the icon
6187 * and not the bounding box.
6190 * [I] infoPtr : valid pointer to the listview structure
6191 * [I] nItem : item index
6192 * [O] lpptPosition : coordinate information
6198 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6202 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6204 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6206 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6207 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6209 if (infoPtr
->uView
== LV_VIEW_ICON
)
6211 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6212 lpptPosition
->y
+= ICON_TOP_PADDING
;
6214 lpptPosition
->x
+= Origin
.x
;
6215 lpptPosition
->y
+= Origin
.y
;
6217 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6224 * Retrieves the bounding rectangle for a listview control item.
6227 * [I] infoPtr : valid pointer to the listview structure
6228 * [I] nItem : item index
6229 * [IO] lprc : bounding rectangle coordinates
6230 * lprc->left specifies the portion of the item for which the bounding
6231 * rectangle will be retrieved.
6233 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6234 * including the icon and label.
6237 * * Experiment shows that native control returns:
6238 * * width = min (48, length of text line)
6239 * * .left = position.x - (width - iconsize.cx)/2
6240 * * .right = .left + width
6241 * * height = #lines of text * ntmHeight + icon height + 8
6242 * * .top = position.y - 2
6243 * * .bottom = .top + height
6244 * * separation between items .y = itemSpacing.cy - height
6245 * * .x = itemSpacing.cx - width
6246 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6249 * * Experiment shows that native control returns:
6250 * * width = iconSize.cx + 16
6251 * * .left = position.x - (width - iconsize.cx)/2
6252 * * .right = .left + width
6253 * * height = iconSize.cy + 4
6254 * * .top = position.y - 2
6255 * * .bottom = .top + height
6256 * * separation between items .y = itemSpacing.cy - height
6257 * * .x = itemSpacing.cx - width
6258 * LVIR_LABEL Returns the bounding rectangle of the item text.
6261 * * Experiment shows that native control returns:
6262 * * width = text length
6263 * * .left = position.x - width/2
6264 * * .right = .left + width
6265 * * height = ntmH * linecount + 2
6266 * * .top = position.y + iconSize.cy + 6
6267 * * .bottom = .top + height
6268 * * separation between items .y = itemSpacing.cy - height
6269 * * .x = itemSpacing.cx - width
6270 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6271 * rectangles, but excludes columns in report view.
6278 * Note that the bounding rectangle of the label in the LVS_ICON view depends
6279 * upon whether the window has the focus currently and on whether the item
6280 * is the one with the focus. Ensure that the control's record of which
6281 * item has the focus agrees with the items' records.
6283 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6285 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6286 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
6287 POINT Position
, Origin
;
6291 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
6293 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6295 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6296 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6298 /* Be smart and try to figure out the minimum we have to do */
6299 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
6300 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
6301 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
6302 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
6303 oversizedBox
= TRUE
;
6305 /* get what we need from the item before hand, so we make
6306 * only one request. This can speed up things, if data
6307 * is stored on the app side */
6309 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6310 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
6311 lvItem
.iItem
= nItem
;
6312 lvItem
.iSubItem
= 0;
6313 lvItem
.pszText
= szDispText
;
6314 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6315 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6316 /* we got the state already up, simulate it here, to avoid a reget */
6317 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
6319 lvItem
.mask
|= LVIF_STATE
;
6320 lvItem
.stateMask
= LVIS_FOCUSED
;
6321 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
6324 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
6325 lprc
->left
= LVIR_BOUNDS
;
6331 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
6335 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
6339 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
6342 case LVIR_SELECTBOUNDS
:
6343 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
6347 WARN("Unknown value: %d\n", lprc
->left
);
6351 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6353 if (mode
!= LVIR_BOUNDS
)
6354 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
6355 Position
.y
+ Origin
.y
);
6357 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
6360 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
6362 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
6369 * Retrieves the spacing between listview control items.
6372 * [I] infoPtr : valid pointer to the listview structure
6373 * [IO] lprc : rectangle to receive the output
6374 * on input, lprc->top = nSubItem
6375 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
6377 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
6378 * not only those of the first column.
6379 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
6385 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6391 if (!lprc
) return FALSE
;
6393 nColumn
= lprc
->top
;
6395 TRACE("(nItem=%d, nSubItem=%d)\n", nItem
, lprc
->top
);
6396 /* On WinNT, a subitem of '0' calls LISTVIEW_GetItemRect */
6398 return LISTVIEW_GetItemRect(infoPtr
, nItem
, lprc
);
6400 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
6402 /* special case for header items */
6405 if (lprc
->left
!= LVIR_BOUNDS
)
6407 FIXME("Only LVIR_BOUNDS is implemented for header, got %d\n", lprc
->left
);
6411 if (infoPtr
->hwndHeader
)
6412 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)lprc
);
6415 memset(lprc
, 0, sizeof(RECT
));
6420 if (!LISTVIEW_GetItemPosition(infoPtr
, nItem
, &Position
)) return FALSE
;
6422 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6425 lvItem
.iItem
= nItem
;
6426 lvItem
.iSubItem
= nColumn
;
6428 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6432 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
6437 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
6441 ERR("Unknown bounds=%d\n", lprc
->left
);
6445 OffsetRect(lprc
, 0, Position
.y
);
6452 * Retrieves the width of a label.
6455 * [I] infoPtr : valid pointer to the listview structure
6458 * SUCCESS : string width (in pixels)
6461 static INT
LISTVIEW_GetLabelWidth(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
6463 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6466 TRACE("(nItem=%d)\n", nItem
);
6468 lvItem
.mask
= LVIF_TEXT
;
6469 lvItem
.iItem
= nItem
;
6470 lvItem
.iSubItem
= 0;
6471 lvItem
.pszText
= szDispText
;
6472 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6473 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
6475 return LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
6480 * Retrieves the spacing between listview control items.
6483 * [I] infoPtr : valid pointer to the listview structure
6484 * [I] bSmall : flag for small or large icon
6487 * Horizontal + vertical spacing
6489 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
6495 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
6499 if (infoPtr
->uView
== LV_VIEW_ICON
)
6500 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
6502 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
6509 * Retrieves the state of a listview control item.
6512 * [I] infoPtr : valid pointer to the listview structure
6513 * [I] nItem : item index
6514 * [I] uMask : state mask
6517 * State specified by the mask.
6519 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
6523 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6525 lvItem
.iItem
= nItem
;
6526 lvItem
.iSubItem
= 0;
6527 lvItem
.mask
= LVIF_STATE
;
6528 lvItem
.stateMask
= uMask
;
6529 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
6531 return lvItem
.state
& uMask
;
6536 * Retrieves the text of a listview control item or subitem.
6539 * [I] hwnd : window handle
6540 * [I] nItem : item index
6541 * [IO] lpLVItem : item information
6542 * [I] isW : TRUE if lpLVItem is Unicode
6545 * SUCCESS : string length
6548 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
6550 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6552 lpLVItem
->mask
= LVIF_TEXT
;
6553 lpLVItem
->iItem
= nItem
;
6554 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
6556 return textlenT(lpLVItem
->pszText
, isW
);
6561 * Searches for an item based on properties + relationships.
6564 * [I] infoPtr : valid pointer to the listview structure
6565 * [I] nItem : item index
6566 * [I] uFlags : relationship flag
6569 * SUCCESS : item index
6572 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
6575 LVFINDINFOW lvFindInfo
;
6576 INT nCountPerColumn
;
6580 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
6581 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
6583 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
6585 if (uFlags
& LVNI_CUT
)
6588 if (uFlags
& LVNI_DROPHILITED
)
6589 uMask
|= LVIS_DROPHILITED
;
6591 if (uFlags
& LVNI_FOCUSED
)
6592 uMask
|= LVIS_FOCUSED
;
6594 if (uFlags
& LVNI_SELECTED
)
6595 uMask
|= LVIS_SELECTED
;
6597 /* if we're asked for the focused item, that's only one,
6598 * so it's worth optimizing */
6599 if (uFlags
& LVNI_FOCUSED
)
6601 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
6602 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
6605 if (uFlags
& LVNI_ABOVE
)
6607 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
6612 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6618 /* Special case for autoarrange - move 'til the top of a list */
6619 if (is_autoarrange(infoPtr
))
6621 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
6622 while (nItem
- nCountPerRow
>= 0)
6624 nItem
-= nCountPerRow
;
6625 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6630 lvFindInfo
.flags
= LVFI_NEARESTXY
;
6631 lvFindInfo
.vkDirection
= VK_UP
;
6632 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
6633 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
6635 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6640 else if (uFlags
& LVNI_BELOW
)
6642 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
6644 while (nItem
< infoPtr
->nItemCount
)
6647 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6653 /* Special case for autoarrange - move 'til the bottom of a list */
6654 if (is_autoarrange(infoPtr
))
6656 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
6657 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
6659 nItem
+= nCountPerRow
;
6660 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6665 lvFindInfo
.flags
= LVFI_NEARESTXY
;
6666 lvFindInfo
.vkDirection
= VK_DOWN
;
6667 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
6668 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
6670 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6675 else if (uFlags
& LVNI_TOLEFT
)
6677 if (infoPtr
->uView
== LV_VIEW_LIST
)
6679 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
6680 while (nItem
- nCountPerColumn
>= 0)
6682 nItem
-= nCountPerColumn
;
6683 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6687 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6689 /* Special case for autoarrange - move 'til the beginning of a row */
6690 if (is_autoarrange(infoPtr
))
6692 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
6693 while (nItem
% nCountPerRow
> 0)
6696 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6701 lvFindInfo
.flags
= LVFI_NEARESTXY
;
6702 lvFindInfo
.vkDirection
= VK_LEFT
;
6703 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
6704 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
6706 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6711 else if (uFlags
& LVNI_TORIGHT
)
6713 if (infoPtr
->uView
== LV_VIEW_LIST
)
6715 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
6716 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
6718 nItem
+= nCountPerColumn
;
6719 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6723 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6725 /* Special case for autoarrange - move 'til the end of a row */
6726 if (is_autoarrange(infoPtr
))
6728 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
6729 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
6732 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6737 lvFindInfo
.flags
= LVFI_NEARESTXY
;
6738 lvFindInfo
.vkDirection
= VK_RIGHT
;
6739 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
6740 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
6742 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6751 /* search by index */
6752 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
6754 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
6762 /* LISTVIEW_GetNumberOfWorkAreas */
6766 * Retrieves the origin coordinates when in icon or small icon display mode.
6769 * [I] infoPtr : valid pointer to the listview structure
6770 * [O] lpptOrigin : coordinate information
6775 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
6777 INT nHorzPos
= 0, nVertPos
= 0;
6778 SCROLLINFO scrollInfo
;
6780 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
6781 scrollInfo
.fMask
= SIF_POS
;
6783 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
6784 nHorzPos
= scrollInfo
.nPos
;
6785 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
6786 nVertPos
= scrollInfo
.nPos
;
6788 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
6790 lpptOrigin
->x
= infoPtr
->rcList
.left
;
6791 lpptOrigin
->y
= infoPtr
->rcList
.top
;
6792 if (infoPtr
->uView
== LV_VIEW_LIST
)
6793 nHorzPos
*= infoPtr
->nItemWidth
;
6794 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6795 nVertPos
*= infoPtr
->nItemHeight
;
6797 lpptOrigin
->x
-= nHorzPos
;
6798 lpptOrigin
->y
-= nVertPos
;
6800 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
6805 * Retrieves the width of a string.
6808 * [I] hwnd : window handle
6809 * [I] lpszText : text string to process
6810 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
6813 * SUCCESS : string width (in pixels)
6816 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
6821 if (is_textT(lpszText
, isW
))
6823 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
6824 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
6825 HFONT hOldFont
= SelectObject(hdc
, hFont
);
6828 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
6830 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
6831 SelectObject(hdc
, hOldFont
);
6832 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6834 return stringSize
.cx
;
6839 * Determines which listview item is located at the specified position.
6842 * [I] infoPtr : valid pointer to the listview structure
6843 * [IO] lpht : hit test information
6844 * [I] subitem : fill out iSubItem.
6845 * [I] select : return the index only if the hit selects the item
6848 * (mm 20001022): We must not allow iSubItem to be touched, for
6849 * an app might pass only a structure with space up to iItem!
6850 * (MS Office 97 does that for instance in the file open dialog)
6853 * SUCCESS : item index
6856 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
6858 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6859 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
6860 POINT Origin
, Position
, opt
;
6865 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
6869 if (subitem
) lpht
->iSubItem
= 0;
6871 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6873 /* set whole list relation flags */
6874 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
6876 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
6877 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
6878 lpht
->flags
|= LVHT_TOLEFT
;
6880 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
6881 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
6885 if (infoPtr
->rcList
.bottom
< opt
.y
)
6886 lpht
->flags
|= LVHT_BELOW
;
6890 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
6891 lpht
->flags
|= LVHT_TOLEFT
;
6892 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
6893 lpht
->flags
|= LVHT_TORIGHT
;
6895 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
6896 lpht
->flags
|= LVHT_ABOVE
;
6897 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
6898 lpht
->flags
|= LVHT_BELOW
;
6901 /* even if item is invalid try to find subitem */
6902 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
6907 opt
.x
= lpht
->pt
.x
- Origin
.x
;
6909 lpht
->iSubItem
= -1;
6910 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
6912 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
6914 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
6920 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
6923 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
6924 if (lpht
->flags
) return -1;
6926 lpht
->flags
|= LVHT_NOWHERE
;
6928 /* first deal with the large items */
6929 rcSearch
.left
= lpht
->pt
.x
;
6930 rcSearch
.top
= lpht
->pt
.y
;
6931 rcSearch
.right
= rcSearch
.left
+ 1;
6932 rcSearch
.bottom
= rcSearch
.top
+ 1;
6934 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
6935 iterator_next(&i
); /* go to first item in the sequence */
6937 iterator_destroy(&i
);
6939 TRACE("lpht->iItem=%d\n", iItem
);
6940 if (iItem
== -1) return -1;
6942 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
6943 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6944 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
6945 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
6946 lvItem
.iItem
= iItem
;
6947 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
6948 lvItem
.pszText
= szDispText
;
6949 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6950 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
6951 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
6953 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
6954 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
6955 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
6957 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
6958 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
6960 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
6962 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6965 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
6966 opt
.x
= lpht
->pt
.x
- Origin
.x
;
6970 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
6971 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
6973 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
6974 if (!PtInRect(&rcBounds
, opt
)) return -1;
6976 if (PtInRect(&rcIcon
, opt
))
6977 lpht
->flags
|= LVHT_ONITEMICON
;
6978 else if (PtInRect(&rcLabel
, opt
))
6979 lpht
->flags
|= LVHT_ONITEMLABEL
;
6980 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
6981 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
6982 /* special case for LVS_EX_FULLROWSELECT */
6983 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
6984 !(lpht
->flags
& LVHT_ONITEM
))
6986 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
6988 if (lpht
->flags
& LVHT_ONITEM
)
6989 lpht
->flags
&= ~LVHT_NOWHERE
;
6990 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
6992 if (select
&& !(infoPtr
->uView
== LV_VIEW_DETAILS
&&
6993 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
6994 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
6996 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6998 /* get main item bounds */
6999 lvItem
.iSubItem
= 0;
7000 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7001 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7002 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7004 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7006 return lpht
->iItem
= iItem
;
7011 * Inserts a new item in the listview control.
7014 * [I] infoPtr : valid pointer to the listview structure
7015 * [I] lpLVItem : item information
7016 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7019 * SUCCESS : new item index
7022 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7029 BOOL is_sorted
, has_changed
;
7031 HWND hwndSelf
= infoPtr
->hwndSelf
;
7033 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7035 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7037 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7038 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7040 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7042 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7044 /* insert item in listview control data structure */
7045 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7046 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7048 /* link with id struct */
7049 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7051 lpID
->item
= hdpaSubItems
;
7052 lpID
->id
= get_next_itemid(infoPtr
);
7053 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7055 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7056 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7058 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7060 /* calculate new item index */
7067 while (i
< infoPtr
->nItemCount
)
7069 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7070 item_s
= (ITEM_INFO
*)DPA_GetPtr(hItem
, 0);
7072 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, TRUE
);
7073 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7075 if (cmpv
>= 0) break;
7081 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7083 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7084 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7085 if (nItem
== -1) goto fail
;
7086 infoPtr
->nItemCount
++;
7088 /* shift indices first so they don't get tangled */
7089 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7091 /* set the item attributes */
7092 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7094 /* full size structure expected - _WIN32IE >= 0x560 */
7097 else if (lpLVItem
->mask
& LVIF_INDENT
)
7099 /* indent member expected - _WIN32IE >= 0x300 */
7100 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7104 /* minimal structure expected */
7105 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7108 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7110 item
.mask
|= LVIF_STATE
;
7111 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7112 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7113 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7115 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7117 /* make room for the position, if we are in the right mode */
7118 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7120 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7122 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7124 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7129 /* send LVN_INSERTITEM notification */
7130 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
7132 nmlv
.lParam
= lpItem
->lParam
;
7133 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7134 if (!IsWindow(hwndSelf
))
7137 /* align items (set position of each item) */
7138 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7142 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7143 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7145 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7147 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7150 /* now is the invalidation fun */
7151 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7155 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7156 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7157 infoPtr
->nItemCount
--;
7159 DPA_DeletePtr(hdpaSubItems
, 0);
7160 DPA_Destroy (hdpaSubItems
);
7167 * Checks item visibility.
7170 * [I] infoPtr : valid pointer to the listview structure
7171 * [I] nFirst : item index to check for
7174 * Item visible : TRUE
7175 * Item invisible or failure : FALSE
7177 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7179 POINT Origin
, Position
;
7184 TRACE("nItem=%d\n", nItem
);
7186 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7188 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7189 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7190 rcItem
.left
= Position
.x
+ Origin
.x
;
7191 rcItem
.top
= Position
.y
+ Origin
.y
;
7192 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7193 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7195 hdc
= GetDC(infoPtr
->hwndSelf
);
7196 if (!hdc
) return FALSE
;
7197 ret
= RectVisible(hdc
, &rcItem
);
7198 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7205 * Redraws a range of items.
7208 * [I] infoPtr : valid pointer to the listview structure
7209 * [I] nFirst : first item
7210 * [I] nLast : last item
7216 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7220 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7221 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7224 for (i
= nFirst
; i
<= nLast
; i
++)
7225 LISTVIEW_InvalidateItem(infoPtr
, i
);
7232 * Scroll the content of a listview.
7235 * [I] infoPtr : valid pointer to the listview structure
7236 * [I] dx : horizontal scroll amount in pixels
7237 * [I] dy : vertical scroll amount in pixels
7244 * If the control is in report view (LV_VIEW_DETAILS) the control can
7245 * be scrolled only in line increments. "dy" will be rounded to the
7246 * nearest number of pixels that are a whole line. Ex: if line height
7247 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7248 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7250 * For: (per experimentation with native control and CSpy ListView)
7251 * LV_VIEW_ICON dy=1 = 1 pixel (vertical only)
7253 * LV_VIEW_SMALLICON dy=1 = 1 pixel (vertical only)
7255 * LV_VIEW_LIST dx=1 = 1 column (horizontal only)
7256 * but will only scroll 1 column per message
7257 * no matter what the value.
7258 * dy must be 0 or FALSE returned.
7259 * LV_VIEW_DETAILS dx=1 = 1 pixel
7263 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7265 switch(infoPtr
->uView
) {
7266 case LV_VIEW_DETAILS
:
7267 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7268 dy
/= infoPtr
->nItemHeight
;
7271 if (dy
!= 0) return FALSE
;
7278 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
, 0);
7279 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
, 0);
7286 * Sets the background color.
7289 * [I] infoPtr : valid pointer to the listview structure
7290 * [I] clrBk : background color
7296 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrBk
)
7298 TRACE("(clrBk=%x)\n", clrBk
);
7300 if(infoPtr
->clrBk
!= clrBk
) {
7301 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7302 infoPtr
->clrBk
= clrBk
;
7303 if (clrBk
== CLR_NONE
)
7304 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
7307 infoPtr
->hBkBrush
= CreateSolidBrush(clrBk
);
7308 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
7310 LISTVIEW_InvalidateList(infoPtr
);
7316 /* LISTVIEW_SetBkImage */
7318 /*** Helper for {Insert,Set}ColumnT *only* */
7319 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
7320 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7322 if (lpColumn
->mask
& LVCF_FMT
)
7324 /* format member is valid */
7325 lphdi
->mask
|= HDI_FORMAT
;
7327 /* set text alignment (leftmost column must be left-aligned) */
7328 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7329 lphdi
->fmt
|= HDF_LEFT
;
7330 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
7331 lphdi
->fmt
|= HDF_RIGHT
;
7332 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
7333 lphdi
->fmt
|= HDF_CENTER
;
7335 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
7336 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
7338 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
7340 lphdi
->fmt
|= HDF_IMAGE
;
7341 lphdi
->iImage
= I_IMAGECALLBACK
;
7344 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
7345 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
7348 if (lpColumn
->mask
& LVCF_WIDTH
)
7350 lphdi
->mask
|= HDI_WIDTH
;
7351 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
7353 /* make it fill the remainder of the controls width */
7357 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
7359 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
7360 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
7363 /* retrieve the layout of the header */
7364 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
7365 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
7367 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
7370 lphdi
->cxy
= lpColumn
->cx
;
7373 if (lpColumn
->mask
& LVCF_TEXT
)
7375 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
7376 lphdi
->fmt
|= HDF_STRING
;
7377 lphdi
->pszText
= lpColumn
->pszText
;
7378 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
7381 if (lpColumn
->mask
& LVCF_IMAGE
)
7383 lphdi
->mask
|= HDI_IMAGE
;
7384 lphdi
->iImage
= lpColumn
->iImage
;
7387 if (lpColumn
->mask
& LVCF_ORDER
)
7389 lphdi
->mask
|= HDI_ORDER
;
7390 lphdi
->iOrder
= lpColumn
->iOrder
;
7397 * Inserts a new column.
7400 * [I] infoPtr : valid pointer to the listview structure
7401 * [I] nColumn : column index
7402 * [I] lpColumn : column information
7403 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
7406 * SUCCESS : new column index
7409 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
7410 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7412 COLUMN_INFO
*lpColumnInfo
;
7416 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
7418 if (!lpColumn
|| nColumn
< 0) return -1;
7419 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
7421 ZeroMemory(&hdi
, sizeof(HDITEMW
));
7422 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
7425 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
7426 * (can be seen in SPY) otherwise column never gets added.
7428 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
7429 hdi
.mask
|= HDI_WIDTH
;
7434 * when the iSubItem is available Windows copies it to the header lParam. It seems
7435 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
7437 if (lpColumn
->mask
& LVCF_SUBITEM
)
7439 hdi
.mask
|= HDI_LPARAM
;
7440 hdi
.lParam
= lpColumn
->iSubItem
;
7443 /* create header if not present */
7444 LISTVIEW_CreateHeader(infoPtr
);
7445 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
7446 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
7448 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
7451 /* insert item in header control */
7452 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
7453 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
7454 (WPARAM
)nColumn
, (LPARAM
)&hdi
);
7455 if (nNewColumn
== -1) return -1;
7456 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
7458 /* create our own column info */
7459 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
7460 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
7462 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
7463 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
7464 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
7467 /* now we have to actually adjust the data */
7468 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
7470 SUBITEM_INFO
*lpSubItem
;
7474 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
7476 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
7477 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
7479 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
7480 if (lpSubItem
->iSubItem
>= nNewColumn
)
7481 lpSubItem
->iSubItem
++;
7486 /* make space for the new column */
7487 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
7488 LISTVIEW_UpdateItemSize(infoPtr
);
7493 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
7496 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
7504 * Sets the attributes of a header item.
7507 * [I] infoPtr : valid pointer to the listview structure
7508 * [I] nColumn : column index
7509 * [I] lpColumn : column attributes
7510 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
7516 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
7517 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7519 HDITEMW hdi
, hdiget
;
7522 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
7524 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
7526 ZeroMemory(&hdi
, sizeof(HDITEMW
));
7527 if (lpColumn
->mask
& LVCF_FMT
)
7529 hdi
.mask
|= HDI_FORMAT
;
7530 hdiget
.mask
= HDI_FORMAT
;
7531 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
7532 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
7534 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
7536 /* set header item attributes */
7537 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, (WPARAM
)nColumn
, (LPARAM
)&hdi
);
7538 if (!bResult
) return FALSE
;
7540 if (lpColumn
->mask
& LVCF_FMT
)
7542 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
7543 INT oldFmt
= lpColumnInfo
->fmt
;
7545 lpColumnInfo
->fmt
= lpColumn
->fmt
;
7546 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
7548 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
7552 if (lpColumn
->mask
& LVCF_MINWIDTH
)
7553 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
7560 * Sets the column order array
7563 * [I] infoPtr : valid pointer to the listview structure
7564 * [I] iCount : number of elements in column order array
7565 * [I] lpiArray : pointer to column order array
7571 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
7573 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
7575 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
7577 infoPtr
->colRectsDirty
= TRUE
;
7579 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
7584 * Sets the width of a column
7587 * [I] infoPtr : valid pointer to the listview structure
7588 * [I] nColumn : column index
7589 * [I] cx : column width
7595 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
7597 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
7601 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
7603 /* set column width only if in report or list mode */
7604 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
7606 /* take care of invalid cx values */
7607 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
7608 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
7610 /* resize all columns if in LV_VIEW_LIST mode */
7611 if(infoPtr
->uView
== LV_VIEW_LIST
)
7613 infoPtr
->nItemWidth
= cx
;
7614 LISTVIEW_InvalidateList(infoPtr
);
7618 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
7620 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
7625 lvItem
.mask
= LVIF_TEXT
;
7627 lvItem
.iSubItem
= nColumn
;
7628 lvItem
.pszText
= szDispText
;
7629 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7630 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
7632 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
7633 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
7634 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
7636 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
7637 max_cx
+= infoPtr
->iconSize
.cx
;
7638 max_cx
+= TRAILING_LABEL_PADDING
;
7641 /* autosize based on listview items width */
7642 if(cx
== LVSCW_AUTOSIZE
)
7644 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
7646 /* if iCol is the last column make it fill the remainder of the controls width */
7647 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
7652 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7653 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
7655 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
7659 /* Despite what the MS docs say, if this is not the last
7660 column, then MS resizes the column to the width of the
7661 largest text string in the column, including headers
7662 and items. This is different from LVSCW_AUTOSIZE in that
7663 LVSCW_AUTOSIZE ignores the header string length. */
7666 /* retrieve header text */
7667 hdi
.mask
= HDI_TEXT
;
7668 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
7669 hdi
.pszText
= szDispText
;
7670 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
7672 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7673 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
7676 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
7677 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
7678 /* FIXME: Take into account the header image, if one is present */
7679 SelectObject(hdc
, old_font
);
7680 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7682 cx
= max (cx
, max_cx
);
7686 if (cx
< 0) return FALSE
;
7688 /* call header to update the column change */
7689 hdi
.mask
= HDI_WIDTH
;
7690 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
7691 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
7692 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
7696 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
7699 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
7702 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
7704 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
7705 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
7708 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
7709 ILC_COLOR
| ILC_MASK
, 2, 2);
7710 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
7711 hdc
= CreateCompatibleDC(hdc_wnd
);
7712 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
7713 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
7714 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
7716 rc
.left
= rc
.top
= 0;
7717 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
7718 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
7720 hbm_orig
= SelectObject(hdc
, hbm_mask
);
7721 FillRect(hdc
, &rc
, hbr_white
);
7722 InflateRect(&rc
, -2, -2);
7723 FillRect(hdc
, &rc
, hbr_black
);
7725 SelectObject(hdc
, hbm_im
);
7726 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
7727 SelectObject(hdc
, hbm_orig
);
7728 ImageList_Add(himl
, hbm_im
, hbm_mask
);
7730 SelectObject(hdc
, hbm_im
);
7731 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
7732 SelectObject(hdc
, hbm_orig
);
7733 ImageList_Add(himl
, hbm_im
, hbm_mask
);
7735 DeleteObject(hbm_mask
);
7736 DeleteObject(hbm_im
);
7744 * Sets the extended listview style.
7747 * [I] infoPtr : valid pointer to the listview structure
7749 * [I] dwStyle : style
7752 * SUCCESS : previous style
7755 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD dwMask
, DWORD dwExStyle
)
7757 DWORD dwOldExStyle
= infoPtr
->dwLvExStyle
;
7761 infoPtr
->dwLvExStyle
= (dwOldExStyle
& ~dwMask
) | (dwExStyle
& dwMask
);
7763 infoPtr
->dwLvExStyle
= dwExStyle
;
7765 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_CHECKBOXES
)
7767 HIMAGELIST himl
= 0;
7768 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7771 item
.mask
= LVIF_STATE
;
7772 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7773 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7774 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
7776 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
7778 LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
7781 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_HEADERDRAGDROP
)
7785 /* if not already created */
7786 LISTVIEW_CreateHeader(infoPtr
);
7788 dwStyle
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
7789 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
7790 dwStyle
|= HDS_DRAGDROP
;
7792 dwStyle
&= ~HDS_DRAGDROP
;
7793 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, dwStyle
);
7796 /* GRIDLINES adds decoration at top so changes sizes */
7797 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_GRIDLINES
)
7799 LISTVIEW_UpdateSize(infoPtr
);
7802 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_TRANSPARENTBKGND
)
7804 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
7805 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
7808 LISTVIEW_InvalidateList(infoPtr
);
7809 return dwOldExStyle
;
7814 * Sets the new hot cursor used during hot tracking and hover selection.
7817 * [I] infoPtr : valid pointer to the listview structure
7818 * [I] hCursor : the new hot cursor handle
7821 * Returns the previous hot cursor
7823 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
7825 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
7827 infoPtr
->hHotCursor
= hCursor
;
7835 * Sets the hot item index.
7838 * [I] infoPtr : valid pointer to the listview structure
7839 * [I] iIndex : index
7842 * SUCCESS : previous hot item index
7843 * FAILURE : -1 (no hot item)
7845 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
7847 INT iOldIndex
= infoPtr
->nHotItem
;
7849 infoPtr
->nHotItem
= iIndex
;
7857 * Sets the amount of time the cursor must hover over an item before it is selected.
7860 * [I] infoPtr : valid pointer to the listview structure
7861 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
7864 * Returns the previous hover time
7866 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
7868 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
7870 infoPtr
->dwHoverTime
= dwHoverTime
;
7872 return oldHoverTime
;
7877 * Sets spacing for icons of LVS_ICON style.
7880 * [I] infoPtr : valid pointer to the listview structure
7881 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
7882 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
7885 * MAKELONG(oldcx, oldcy)
7887 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
7889 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7891 TRACE("requested=(%d,%d)\n", cx
, cy
);
7893 /* this is supported only for LVS_ICON style */
7894 if (infoPtr
->uView
!= LV_VIEW_ICON
) return oldspacing
;
7896 /* set to defaults, if instructed to */
7897 if (cx
== -1) cx
= GetSystemMetrics(SM_CXICONSPACING
);
7898 if (cy
== -1) cy
= GetSystemMetrics(SM_CYICONSPACING
);
7900 /* if 0 then compute width
7901 * FIXME: Should scan each item and determine max width of
7902 * icon or label, then make that the width */
7904 cx
= infoPtr
->iconSpacing
.cx
;
7906 /* if 0 then compute height */
7908 cy
= infoPtr
->iconSize
.cy
+ 2 * infoPtr
->ntmHeight
+
7909 ICON_BOTTOM_PADDING
+ ICON_TOP_PADDING
+ LABEL_VERT_PADDING
;
7912 infoPtr
->iconSpacing
.cx
= cx
;
7913 infoPtr
->iconSpacing
.cy
= cy
;
7915 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
7916 LOWORD(oldspacing
), HIWORD(oldspacing
), cx
, cy
,
7917 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
7918 infoPtr
->ntmHeight
);
7920 /* these depend on the iconSpacing */
7921 LISTVIEW_UpdateItemSize(infoPtr
);
7926 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
7930 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
7937 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
7938 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
7947 * [I] infoPtr : valid pointer to the listview structure
7948 * [I] nType : image list type
7949 * [I] himl : image list handle
7952 * SUCCESS : old image list
7955 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
7957 INT oldHeight
= infoPtr
->nItemHeight
;
7958 HIMAGELIST himlOld
= 0;
7960 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
7965 himlOld
= infoPtr
->himlNormal
;
7966 infoPtr
->himlNormal
= himl
;
7967 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
7968 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
7972 himlOld
= infoPtr
->himlSmall
;
7973 infoPtr
->himlSmall
= himl
;
7974 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
7978 himlOld
= infoPtr
->himlState
;
7979 infoPtr
->himlState
= himl
;
7980 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
7981 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
7985 ERR("Unknown icon type=%d\n", nType
);
7989 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
7990 if (infoPtr
->nItemHeight
!= oldHeight
)
7991 LISTVIEW_UpdateScroll(infoPtr
);
7998 * Preallocates memory (does *not* set the actual count of items !)
8001 * [I] infoPtr : valid pointer to the listview structure
8002 * [I] nItems : item count (projected number of items to allocate)
8003 * [I] dwFlags : update flags
8009 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8011 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8013 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8015 INT nOldCount
= infoPtr
->nItemCount
;
8017 if (nItems
< nOldCount
)
8019 RANGE range
= { nItems
, nOldCount
};
8020 ranges_del(infoPtr
->selectionRanges
, range
);
8021 if (infoPtr
->nFocusedItem
>= nItems
)
8023 LISTVIEW_SetItemFocus(infoPtr
, -1);
8024 SetRectEmpty(&infoPtr
->rcFocus
);
8028 infoPtr
->nItemCount
= nItems
;
8029 LISTVIEW_UpdateScroll(infoPtr
);
8031 /* the flags are valid only in ownerdata report and list modes */
8032 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8034 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8035 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8037 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8038 LISTVIEW_InvalidateList(infoPtr
);
8045 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8046 nFrom
= min(nOldCount
, nItems
);
8047 nTo
= max(nOldCount
, nItems
);
8049 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8052 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8053 rcErase
.right
= infoPtr
->nItemWidth
;
8054 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8055 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8056 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8057 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8059 else /* LV_VIEW_LIST */
8061 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8063 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8064 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8065 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8066 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8067 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8068 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8069 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8071 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8073 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8074 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8075 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8076 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8077 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8083 /* According to MSDN for non-LVS_OWNERDATA this is just
8084 * a performance issue. The control allocates its internal
8085 * data structures for the number of items specified. It
8086 * cuts down on the number of memory allocations. Therefore
8087 * we will just issue a WARN here
8089 WARN("for non-ownerdata performance option not implemented.\n");
8097 * Sets the position of an item.
8100 * [I] infoPtr : valid pointer to the listview structure
8101 * [I] nItem : item index
8102 * [I] pt : coordinate
8108 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, POINT pt
)
8112 TRACE("(nItem=%d, &pt=%s\n", nItem
, wine_dbgstr_point(&pt
));
8114 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8115 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8117 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8119 /* This point value seems to be an undocumented feature.
8120 * The best guess is that it means either at the origin,
8121 * or at true beginning of the list. I will assume the origin. */
8122 if ((pt
.x
== -1) && (pt
.y
== -1))
8125 if (infoPtr
->uView
== LV_VIEW_ICON
)
8127 pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8128 pt
.y
-= ICON_TOP_PADDING
;
8133 infoPtr
->bAutoarrange
= FALSE
;
8135 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, FALSE
);
8140 * Sets the state of one or many items.
8143 * [I] infoPtr : valid pointer to the listview structure
8144 * [I] nItem : item index
8145 * [I] lpLVItem : item or subitem info
8151 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
)
8153 BOOL bResult
= TRUE
;
8156 lvItem
.iItem
= nItem
;
8157 lvItem
.iSubItem
= 0;
8158 lvItem
.mask
= LVIF_STATE
;
8159 lvItem
.state
= lpLVItem
->state
;
8160 lvItem
.stateMask
= lpLVItem
->stateMask
;
8161 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8165 /* select all isn't allowed in LVS_SINGLESEL */
8166 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8169 /* focus all isn't allowed */
8170 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8172 /* apply to all items */
8173 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8174 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) bResult
= FALSE
;
8177 bResult
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8184 * Sets the text of an item or subitem.
8187 * [I] hwnd : window handle
8188 * [I] nItem : item index
8189 * [I] lpLVItem : item or subitem info
8190 * [I] isW : TRUE if input is Unicode
8196 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8200 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
8202 lvItem
.iItem
= nItem
;
8203 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
8204 lvItem
.mask
= LVIF_TEXT
;
8205 lvItem
.pszText
= lpLVItem
->pszText
;
8206 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
8208 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
8210 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
8215 * Set item index that marks the start of a multiple selection.
8218 * [I] infoPtr : valid pointer to the listview structure
8219 * [I] nIndex : index
8222 * Index number or -1 if there is no selection mark.
8224 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
8226 INT nOldIndex
= infoPtr
->nSelectionMark
;
8228 TRACE("(nIndex=%d)\n", nIndex
);
8230 infoPtr
->nSelectionMark
= nIndex
;
8237 * Sets the text background color.
8240 * [I] infoPtr : valid pointer to the listview structure
8241 * [I] clrTextBk : text background color
8247 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrTextBk
)
8249 TRACE("(clrTextBk=%x)\n", clrTextBk
);
8251 if (infoPtr
->clrTextBk
!= clrTextBk
)
8253 infoPtr
->clrTextBk
= clrTextBk
;
8254 LISTVIEW_InvalidateList(infoPtr
);
8262 * Sets the text foreground color.
8265 * [I] infoPtr : valid pointer to the listview structure
8266 * [I] clrText : text color
8272 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF clrText
)
8274 TRACE("(clrText=%x)\n", clrText
);
8276 if (infoPtr
->clrText
!= clrText
)
8278 infoPtr
->clrText
= clrText
;
8279 LISTVIEW_InvalidateList(infoPtr
);
8287 * Sets new ToolTip window to ListView control.
8290 * [I] infoPtr : valid pointer to the listview structure
8291 * [I] hwndNewToolTip : handle to new ToolTip
8296 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
8298 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
8299 infoPtr
->hwndToolTip
= hwndNewToolTip
;
8300 return hwndOldToolTip
;
8305 * sets the Unicode character format flag for the control
8307 * [I] infoPtr :valid pointer to the listview structure
8308 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
8311 * Old Unicode Format
8313 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL fUnicode
)
8315 SHORT rc
= infoPtr
->notifyFormat
;
8316 infoPtr
->notifyFormat
= (fUnicode
) ? NFR_UNICODE
: NFR_ANSI
;
8317 return rc
== NFR_UNICODE
;
8322 * sets the control view mode
8324 * [I] infoPtr :valid pointer to the listview structure
8325 * [I] nView :new view mode value
8331 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
8333 SIZE oldIconSize
= infoPtr
->iconSize
;
8336 if (infoPtr
->uView
== nView
) return 1;
8338 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
8339 if (nView
== LV_VIEW_TILE
)
8341 FIXME("View LV_VIEW_TILE unimplemented\n");
8345 infoPtr
->uView
= nView
;
8347 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8348 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8350 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
8351 SetRectEmpty(&infoPtr
->rcFocus
);
8353 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
8354 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
8359 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
8361 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
8362 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
8363 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
8365 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8367 case LV_VIEW_SMALLICON
:
8368 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8370 case LV_VIEW_DETAILS
:
8375 LISTVIEW_CreateHeader( infoPtr
);
8377 hl
.prc
= &infoPtr
->rcList
;
8379 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
8380 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
8381 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
8388 LISTVIEW_UpdateItemSize(infoPtr
);
8389 LISTVIEW_UpdateSize(infoPtr
);
8390 LISTVIEW_UpdateScroll(infoPtr
);
8391 LISTVIEW_InvalidateList(infoPtr
);
8393 TRACE("nView=%d\n", nView
);
8398 /* LISTVIEW_SetWorkAreas */
8402 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
8405 * [I] first : pointer to first ITEM_INFO to compare
8406 * [I] second : pointer to second ITEM_INFO to compare
8407 * [I] lParam : HWND of control
8410 * if first comes before second : negative
8411 * if first comes after second : positive
8412 * if first and second are equivalent : zero
8414 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
8416 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
8417 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
8418 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
8420 /* Forward the call to the client defined callback */
8421 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
8426 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
8429 * [I] first : pointer to first ITEM_INFO to compare
8430 * [I] second : pointer to second ITEM_INFO to compare
8431 * [I] lParam : HWND of control
8434 * if first comes before second : negative
8435 * if first comes after second : positive
8436 * if first and second are equivalent : zero
8438 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
8440 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
8441 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
8442 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
8444 /* Forward the call to the client defined callback */
8445 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
8450 * Sorts the listview items.
8453 * [I] infoPtr : valid pointer to the listview structure
8454 * [I] pfnCompare : application-defined value
8455 * [I] lParamSort : pointer to comparison callback
8456 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
8462 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
8463 LPARAM lParamSort
, BOOL IsEx
)
8467 LPVOID selectionMarkItem
= NULL
;
8468 LPVOID focusedItem
= NULL
;
8471 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
8473 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
8475 if (!pfnCompare
) return FALSE
;
8476 if (!infoPtr
->hdpaItems
) return FALSE
;
8478 /* if there are 0 or 1 items, there is no need to sort */
8479 if (infoPtr
->nItemCount
< 2) return TRUE
;
8481 /* clear selection */
8482 ranges_clear(infoPtr
->selectionRanges
);
8484 /* save selection mark and focused item */
8485 if (infoPtr
->nSelectionMark
>= 0)
8486 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
8487 if (infoPtr
->nFocusedItem
>= 0)
8488 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
8490 infoPtr
->pfnCompare
= pfnCompare
;
8491 infoPtr
->lParamSort
= lParamSort
;
8493 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
8495 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
8497 /* restore selection ranges */
8498 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
8500 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
8501 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
8503 if (lpItem
->state
& LVIS_SELECTED
)
8504 ranges_additem(infoPtr
->selectionRanges
, i
);
8506 /* restore selection mark and focused item */
8507 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
8508 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
8510 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
8512 /* refresh the display */
8513 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
)
8514 LISTVIEW_InvalidateList(infoPtr
);
8521 * Update theme handle after a theme change.
8524 * [I] infoPtr : valid pointer to the listview structure
8528 * FAILURE : something else
8530 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
8532 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
8533 CloseThemeData(theme
);
8534 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
8540 * Updates an items or rearranges the listview control.
8543 * [I] infoPtr : valid pointer to the listview structure
8544 * [I] nItem : item index
8550 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
8552 TRACE("(nItem=%d)\n", nItem
);
8554 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
8556 /* rearrange with default alignment style */
8557 if (is_autoarrange(infoPtr
))
8558 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8560 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
8567 * Draw the track line at the place defined in the infoPtr structure.
8568 * The line is drawn with a XOR pen so drawing the line for the second time
8569 * in the same place erases the line.
8572 * [I] infoPtr : valid pointer to the listview structure
8578 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
8584 if (infoPtr
->xTrackLine
== -1)
8587 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
8589 hOldPen
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
8590 oldROP
= SetROP2(hdc
, R2_XORPEN
);
8591 MoveToEx(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
, NULL
);
8592 LineTo(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.bottom
);
8593 SetROP2(hdc
, oldROP
);
8594 SelectObject(hdc
, hOldPen
);
8595 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8601 * Called when an edit control should be displayed. This function is called after
8602 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
8605 * [I] hwnd : Handle to the listview
8606 * [I] uMsg : WM_TIMER (ignored)
8607 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
8608 * [I] dwTimer : The elapsed time (ignored)
8613 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
8615 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
8616 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
8618 KillTimer(hwnd
, idEvent
);
8619 editItem
->fEnabled
= FALSE
;
8620 /* check if the item is still selected */
8621 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
8622 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
8627 * Creates the listview control - the WM_NCCREATE phase.
8630 * [I] hwnd : window handle
8631 * [I] lpcs : the create parameters
8637 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
8639 LISTVIEW_INFO
*infoPtr
;
8642 TRACE("(lpcs=%p)\n", lpcs
);
8644 /* initialize info pointer */
8645 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
8646 if (!infoPtr
) return FALSE
;
8648 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
8650 infoPtr
->hwndSelf
= hwnd
;
8651 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
8652 map_style_view(infoPtr
);
8653 /* determine the type of structures to use */
8654 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
8655 /* infoPtr->notifyFormat will be filled in WM_CREATE */
8657 /* initialize color information */
8658 infoPtr
->clrBk
= CLR_NONE
;
8659 infoPtr
->clrText
= CLR_DEFAULT
;
8660 infoPtr
->clrTextBk
= CLR_DEFAULT
;
8661 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
8663 /* set default values */
8664 infoPtr
->nFocusedItem
= -1;
8665 infoPtr
->nSelectionMark
= -1;
8666 infoPtr
->nHotItem
= -1;
8667 infoPtr
->bRedraw
= TRUE
;
8668 infoPtr
->bNoItemMetrics
= TRUE
;
8669 infoPtr
->bDoChangeNotify
= TRUE
;
8670 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
);
8671 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
);
8672 infoPtr
->nEditLabelItem
= -1;
8673 infoPtr
->nLButtonDownItem
= -1;
8674 infoPtr
->dwHoverTime
= -1; /* default system hover time */
8675 infoPtr
->nMeasureItemHeight
= 0;
8676 infoPtr
->xTrackLine
= -1; /* no track line */
8677 infoPtr
->itemEdit
.fEnabled
= FALSE
;
8678 infoPtr
->iVersion
= COMCTL32_VERSION
;
8679 infoPtr
->colRectsDirty
= FALSE
;
8681 /* get default font (icon title) */
8682 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
8683 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
8684 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
8685 LISTVIEW_SaveTextMetrics(infoPtr
);
8687 /* allocate memory for the data structure */
8688 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
8689 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
8690 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
8691 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
8692 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
8693 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
8697 DestroyWindow(infoPtr
->hwndHeader
);
8698 ranges_destroy(infoPtr
->selectionRanges
);
8699 DPA_Destroy(infoPtr
->hdpaItems
);
8700 DPA_Destroy(infoPtr
->hdpaItemIds
);
8701 DPA_Destroy(infoPtr
->hdpaPosX
);
8702 DPA_Destroy(infoPtr
->hdpaPosY
);
8703 DPA_Destroy(infoPtr
->hdpaColumns
);
8710 * Creates the listview control - the WM_CREATE phase. Most of the data is
8711 * already set up in LISTVIEW_NCCreate
8714 * [I] hwnd : window handle
8715 * [I] lpcs : the create parameters
8721 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
8723 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
8725 TRACE("(lpcs=%p)\n", lpcs
);
8727 infoPtr
->dwStyle
= lpcs
->style
;
8728 map_style_view(infoPtr
);
8730 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
8731 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
8732 /* on error defaulting to ANSI notifications */
8733 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
8735 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
8737 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
8740 infoPtr
->hwndHeader
= 0;
8742 /* init item size to avoid division by 0 */
8743 LISTVIEW_UpdateItemSize (infoPtr
);
8745 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8747 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
8749 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8751 LISTVIEW_UpdateScroll(infoPtr
);
8752 /* send WM_MEASUREITEM notification */
8753 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
8756 OpenThemeData(hwnd
, themeClass
);
8758 /* initialize the icon sizes */
8759 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
8760 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
8766 * Destroys the listview control.
8769 * [I] infoPtr : valid pointer to the listview structure
8775 static LRESULT
LISTVIEW_Destroy(const LISTVIEW_INFO
*infoPtr
)
8777 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
8778 CloseThemeData(theme
);
8784 * Enables the listview control.
8787 * [I] infoPtr : valid pointer to the listview structure
8788 * [I] bEnable : specifies whether to enable or disable the window
8794 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
, BOOL bEnable
)
8796 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
8797 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
8803 * Erases the background of the listview control.
8806 * [I] infoPtr : valid pointer to the listview structure
8807 * [I] hdc : device context handle
8813 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
8817 TRACE("(hdc=%p)\n", hdc
);
8819 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
8821 if (infoPtr
->clrBk
== CLR_NONE
)
8823 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8824 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
8825 (WPARAM
)hdc
, PRF_ERASEBKGND
);
8827 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
8830 /* for double buffered controls we need to do this during refresh */
8831 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
8833 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
8839 * Helper function for LISTVIEW_[HV]Scroll *only*.
8840 * Performs vertical/horizontal scrolling by a give amount.
8843 * [I] infoPtr : valid pointer to the listview structure
8844 * [I] dx : amount of horizontal scroll
8845 * [I] dy : amount of vertical scroll
8847 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8849 /* now we can scroll the list */
8850 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
8851 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
8852 /* if we have focus, adjust rect */
8853 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
8854 UpdateWindow(infoPtr
->hwndSelf
);
8859 * Performs vertical scrolling.
8862 * [I] infoPtr : valid pointer to the listview structure
8863 * [I] nScrollCode : scroll code
8864 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
8865 * [I] hScrollWnd : scrollbar control window handle
8871 * SB_LINEUP/SB_LINEDOWN:
8872 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
8873 * for LVS_REPORT is 1 line
8874 * for LVS_LIST cannot occur
8877 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
8878 INT nScrollDiff
, HWND hScrollWnd
)
8880 INT nOldScrollPos
, nNewScrollPos
;
8881 SCROLLINFO scrollInfo
;
8884 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
8885 debugscrollcode(nScrollCode
), nScrollDiff
);
8887 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8889 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
8890 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
8892 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
8894 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
8896 nOldScrollPos
= scrollInfo
.nPos
;
8897 switch (nScrollCode
)
8903 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
8907 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
8911 nScrollDiff
= -scrollInfo
.nPage
;
8915 nScrollDiff
= scrollInfo
.nPage
;
8918 case SB_THUMBPOSITION
:
8920 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
8927 /* quit right away if pos isn't changing */
8928 if (nScrollDiff
== 0) return 0;
8930 /* calculate new position, and handle overflows */
8931 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
8932 if (nScrollDiff
> 0) {
8933 if (nNewScrollPos
< nOldScrollPos
||
8934 nNewScrollPos
> scrollInfo
.nMax
)
8935 nNewScrollPos
= scrollInfo
.nMax
;
8937 if (nNewScrollPos
> nOldScrollPos
||
8938 nNewScrollPos
< scrollInfo
.nMin
)
8939 nNewScrollPos
= scrollInfo
.nMin
;
8942 /* set the new position, and reread in case it changed */
8943 scrollInfo
.fMask
= SIF_POS
;
8944 scrollInfo
.nPos
= nNewScrollPos
;
8945 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
8947 /* carry on only if it really changed */
8948 if (nNewScrollPos
== nOldScrollPos
) return 0;
8950 /* now adjust to client coordinates */
8951 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
8952 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
8954 /* and scroll the window */
8955 scroll_list(infoPtr
, 0, nScrollDiff
);
8962 * Performs horizontal scrolling.
8965 * [I] infoPtr : valid pointer to the listview structure
8966 * [I] nScrollCode : scroll code
8967 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
8968 * [I] hScrollWnd : scrollbar control window handle
8974 * SB_LINELEFT/SB_LINERIGHT:
8975 * for LVS_ICON, LVS_SMALLICON 1 pixel
8976 * for LVS_REPORT is 1 pixel
8977 * for LVS_LIST is 1 column --> which is a 1 because the
8978 * scroll is based on columns not pixels
8981 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
8982 INT nScrollDiff
, HWND hScrollWnd
)
8984 INT nOldScrollPos
, nNewScrollPos
;
8985 SCROLLINFO scrollInfo
;
8987 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
8988 debugscrollcode(nScrollCode
), nScrollDiff
);
8990 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8992 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
8993 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
8995 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
8997 nOldScrollPos
= scrollInfo
.nPos
;
8999 switch (nScrollCode
)
9013 nScrollDiff
= -scrollInfo
.nPage
;
9017 nScrollDiff
= scrollInfo
.nPage
;
9020 case SB_THUMBPOSITION
:
9022 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9029 /* quit right away if pos isn't changing */
9030 if (nScrollDiff
== 0) return 0;
9032 /* calculate new position, and handle overflows */
9033 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9034 if (nScrollDiff
> 0) {
9035 if (nNewScrollPos
< nOldScrollPos
||
9036 nNewScrollPos
> scrollInfo
.nMax
)
9037 nNewScrollPos
= scrollInfo
.nMax
;
9039 if (nNewScrollPos
> nOldScrollPos
||
9040 nNewScrollPos
< scrollInfo
.nMin
)
9041 nNewScrollPos
= scrollInfo
.nMin
;
9044 /* set the new position, and reread in case it changed */
9045 scrollInfo
.fMask
= SIF_POS
;
9046 scrollInfo
.nPos
= nNewScrollPos
;
9047 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9049 /* carry on only if it really changed */
9050 if (nNewScrollPos
== nOldScrollPos
) return 0;
9052 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9053 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9055 /* now adjust to client coordinates */
9056 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9057 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9059 /* and scroll the window */
9060 scroll_list(infoPtr
, nScrollDiff
, 0);
9065 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9067 INT gcWheelDelta
= 0;
9068 INT pulScrollLines
= 3;
9069 SCROLLINFO scrollInfo
;
9071 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9073 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9074 gcWheelDelta
-= wheelDelta
;
9076 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9077 scrollInfo
.fMask
= SIF_POS
;
9079 switch(infoPtr
->uView
)
9082 case LV_VIEW_SMALLICON
:
9084 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9085 * should be fixed in the future.
9087 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (gcWheelDelta
< 0) ?
9088 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
, 0);
9091 case LV_VIEW_DETAILS
:
9092 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
9094 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9095 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
9096 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, cLineScroll
, 0);
9101 LISTVIEW_HScroll(infoPtr
, (gcWheelDelta
< 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0, 0);
9112 * [I] infoPtr : valid pointer to the listview structure
9113 * [I] nVirtualKey : virtual key
9114 * [I] lKeyData : key data
9119 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9121 HWND hwndSelf
= infoPtr
->hwndSelf
;
9123 NMLVKEYDOWN nmKeyDown
;
9125 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9127 /* send LVN_KEYDOWN notification */
9128 nmKeyDown
.wVKey
= nVirtualKey
;
9129 nmKeyDown
.flags
= 0;
9130 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9131 if (!IsWindow(hwndSelf
))
9134 switch (nVirtualKey
)
9137 nItem
= infoPtr
->nFocusedItem
;
9138 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9139 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9143 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9145 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9146 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9151 if (infoPtr
->nItemCount
> 0)
9156 if (infoPtr
->nItemCount
> 0)
9157 nItem
= infoPtr
->nItemCount
- 1;
9161 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9165 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9169 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9173 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9177 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9179 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9180 if (infoPtr
->nFocusedItem
== topidx
)
9181 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9186 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9187 * LISTVIEW_GetCountPerRow(infoPtr
);
9188 if(nItem
< 0) nItem
= 0;
9192 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9194 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9195 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9196 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9197 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9199 nItem
= topidx
+ cnt
- 1;
9202 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9203 * LISTVIEW_GetCountPerRow(infoPtr
);
9204 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9208 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9209 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
9219 * [I] infoPtr : valid pointer to the listview structure
9224 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
9228 /* if we did not have the focus, there's nothing to do */
9229 if (!infoPtr
->bFocus
) return 0;
9231 /* send NM_KILLFOCUS notification */
9232 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
9234 /* if we have a focus rectangle, get rid of it */
9235 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
9237 /* set window focus flag */
9238 infoPtr
->bFocus
= FALSE
;
9240 /* invalidate the selected items before resetting focus flag */
9241 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9248 * Processes double click messages (left mouse button).
9251 * [I] infoPtr : valid pointer to the listview structure
9252 * [I] wKey : key flag
9253 * [I] x,y : mouse coordinate
9258 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9260 LVHITTESTINFO htInfo
;
9262 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
9264 /* Cancel the item edition if any */
9265 if (infoPtr
->itemEdit
.fEnabled
)
9267 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
9268 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9271 /* send NM_RELEASEDCAPTURE notification */
9272 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9277 /* send NM_DBLCLK notification */
9278 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
9279 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
9281 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
9282 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
9289 * Processes mouse down messages (left mouse button).
9292 * infoPtr [I ] valid pointer to the listview structure
9293 * wKey [I ] key flag
9294 * x,y [I ] mouse coordinate
9299 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9301 LVHITTESTINFO lvHitTestInfo
;
9302 static BOOL bGroupSelect
= TRUE
;
9303 POINT pt
= { x
, y
};
9306 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
9308 /* send NM_RELEASEDCAPTURE notification */
9309 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9311 /* set left button down flag and record the click position */
9312 infoPtr
->bLButtonDown
= TRUE
;
9313 infoPtr
->ptClickPos
= pt
;
9314 infoPtr
->bDragging
= FALSE
;
9316 lvHitTestInfo
.pt
.x
= x
;
9317 lvHitTestInfo
.pt
.y
= y
;
9319 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
9320 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
9321 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
9323 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
9325 toggle_checkbox_state(infoPtr
, nItem
);
9329 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
9331 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9332 infoPtr
->nEditLabelItem
= nItem
;
9334 LISTVIEW_SetSelection(infoPtr
, nItem
);
9338 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
9342 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
9343 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9344 infoPtr
->nSelectionMark
= nItem
;
9350 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
9351 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9353 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
9354 infoPtr
->nSelectionMark
= nItem
;
9357 else if (wKey
& MK_CONTROL
)
9361 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
9363 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
9364 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9365 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
9366 infoPtr
->nSelectionMark
= nItem
;
9368 else if (wKey
& MK_SHIFT
)
9370 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
9374 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9376 infoPtr
->nEditLabelItem
= nItem
;
9377 infoPtr
->nLButtonDownItem
= nItem
;
9379 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9382 /* set selection (clears other pre-existing selections) */
9383 LISTVIEW_SetSelection(infoPtr
, nItem
);
9387 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
9388 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
9392 /* remove all selections */
9393 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
9394 LISTVIEW_DeselectAll(infoPtr
);
9403 * Processes mouse up messages (left mouse button).
9406 * infoPtr [I ] valid pointer to the listview structure
9407 * wKey [I ] key flag
9408 * x,y [I ] mouse coordinate
9413 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9415 LVHITTESTINFO lvHitTestInfo
;
9417 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
9419 if (!infoPtr
->bLButtonDown
) return 0;
9421 lvHitTestInfo
.pt
.x
= x
;
9422 lvHitTestInfo
.pt
.y
= y
;
9424 /* send NM_CLICK notification */
9425 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
9426 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
9428 /* set left button flag */
9429 infoPtr
->bLButtonDown
= FALSE
;
9431 /* set a single selection, reset others */
9432 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
9433 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
9434 infoPtr
->nLButtonDownItem
= -1;
9436 if (infoPtr
->bDragging
)
9438 infoPtr
->bDragging
= FALSE
;
9442 /* if we clicked on a selected item, edit the label */
9443 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
9445 /* we want to make sure the user doesn't want to do a double click. So we will
9446 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
9448 infoPtr
->itemEdit
.fEnabled
= TRUE
;
9449 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
9450 SetTimer(infoPtr
->hwndSelf
,
9451 (UINT_PTR
)&infoPtr
->itemEdit
,
9452 GetDoubleClickTime(),
9453 LISTVIEW_DelayedEditItem
);
9456 if (!infoPtr
->bFocus
)
9457 SetFocus(infoPtr
->hwndSelf
);
9464 * Destroys the listview control (called after WM_DESTROY).
9467 * [I] infoPtr : valid pointer to the listview structure
9472 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
9476 /* delete all items */
9477 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9479 /* destroy data structure */
9480 DPA_Destroy(infoPtr
->hdpaItems
);
9481 DPA_Destroy(infoPtr
->hdpaItemIds
);
9482 DPA_Destroy(infoPtr
->hdpaPosX
);
9483 DPA_Destroy(infoPtr
->hdpaPosY
);
9484 DPA_Destroy(infoPtr
->hdpaColumns
);
9485 ranges_destroy(infoPtr
->selectionRanges
);
9487 /* destroy image lists */
9488 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
9490 if (infoPtr
->himlNormal
)
9491 ImageList_Destroy(infoPtr
->himlNormal
);
9492 if (infoPtr
->himlSmall
)
9493 ImageList_Destroy(infoPtr
->himlSmall
);
9494 if (infoPtr
->himlState
)
9495 ImageList_Destroy(infoPtr
->himlState
);
9498 /* destroy font, bkgnd brush */
9500 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
9501 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
9503 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
9505 /* free listview info pointer*/
9513 * Handles notifications from header.
9516 * [I] infoPtr : valid pointer to the listview structure
9517 * [I] nCtrlId : control identifier
9518 * [I] lpnmh : notification information
9523 static LRESULT
LISTVIEW_HeaderNotification(LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
9525 HWND hwndSelf
= infoPtr
->hwndSelf
;
9527 TRACE("(lpnmh=%p)\n", lpnmh
);
9529 if (!lpnmh
|| lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
9531 switch (lpnmh
->hdr
.code
)
9536 COLUMN_INFO
*lpColumnInfo
;
9540 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
9543 /* remove the old line (if any) */
9544 LISTVIEW_DrawTrackLine(infoPtr
);
9546 /* compute & draw the new line */
9547 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
9548 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
9549 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
9550 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
9551 LISTVIEW_DrawTrackLine(infoPtr
);
9557 /* remove the track line (if any) */
9558 LISTVIEW_DrawTrackLine(infoPtr
);
9559 infoPtr
->xTrackLine
= -1;
9563 notify_forward_header(infoPtr
, lpnmh
);
9564 return (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0;
9567 infoPtr
->colRectsDirty
= TRUE
;
9568 LISTVIEW_InvalidateList(infoPtr
);
9569 notify_forward_header(infoPtr
, lpnmh
);
9572 case HDN_ITEMCHANGINGW
:
9573 case HDN_ITEMCHANGINGA
:
9574 return notify_forward_header(infoPtr
, lpnmh
);
9576 case HDN_ITEMCHANGEDW
:
9577 case HDN_ITEMCHANGEDA
:
9579 COLUMN_INFO
*lpColumnInfo
;
9583 notify_forward_header(infoPtr
, lpnmh
);
9584 if (!IsWindow(hwndSelf
))
9587 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
9589 hdi
.mask
= HDI_WIDTH
;
9590 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
9594 cxy
= lpnmh
->pitem
->cxy
;
9596 /* determine how much we change since the last know position */
9597 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
9598 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
9601 lpColumnInfo
->rcHeader
.right
+= dx
;
9603 hdi
.mask
= HDI_ORDER
;
9604 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
9606 /* not the rightmost one */
9607 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
9609 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
9611 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
9615 /* only needs to update the scrolls */
9616 infoPtr
->nItemWidth
+= dx
;
9617 LISTVIEW_UpdateScroll(infoPtr
);
9619 LISTVIEW_UpdateItemSize(infoPtr
);
9620 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
9623 RECT rcCol
= lpColumnInfo
->rcHeader
;
9625 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
9626 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
9628 rcCol
.top
= infoPtr
->rcList
.top
;
9629 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
9631 /* resizing left-aligned columns leaves most of the left side untouched */
9632 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
9634 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
9637 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
9640 /* when shrinking the last column clear the now unused field */
9641 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
9647 /* deal with right from rightmost column area */
9648 right
.left
= rcCol
.right
;
9649 right
.top
= rcCol
.top
;
9650 right
.bottom
= rcCol
.bottom
;
9651 right
.right
= infoPtr
->rcList
.right
;
9653 LISTVIEW_InvalidateRect(infoPtr
, &right
);
9656 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
9662 case HDN_ITEMCLICKW
:
9663 case HDN_ITEMCLICKA
:
9665 /* Handle sorting by Header Column */
9668 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
9670 nmlv
.iSubItem
= lpnmh
->iItem
;
9671 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
9672 notify_forward_header(infoPtr
, lpnmh
);
9676 case HDN_DIVIDERDBLCLICKW
:
9677 case HDN_DIVIDERDBLCLICKA
:
9678 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
9679 notify_forward_header(infoPtr
, lpnmh
);
9688 * Paint non-client area of control.
9691 * [I] infoPtr : valid pointer to the listview structureof the sender
9692 * [I] region : update region
9695 * TRUE - frame was painted
9696 * FALSE - call default window proc
9698 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
9700 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
9704 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
9705 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
9707 if (!theme
) return FALSE
;
9709 GetWindowRect(infoPtr
->hwndSelf
, &r
);
9711 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
9712 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
9713 if (region
!= (HRGN
)1)
9714 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
9715 OffsetRect(&r
, -r
.left
, -r
.top
);
9717 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
9718 OffsetRect(&r
, -r
.left
, -r
.top
);
9720 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
9721 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
9722 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
9723 ReleaseDC(infoPtr
->hwndSelf
, dc
);
9725 /* Call default proc to get the scrollbars etc. painted */
9726 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
9733 * Determines the type of structure to use.
9736 * [I] infoPtr : valid pointer to the listview structureof the sender
9737 * [I] hwndFrom : listview window handle
9738 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
9743 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
9745 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
9747 if (nCommand
== NF_REQUERY
)
9748 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9750 return infoPtr
->notifyFormat
;
9755 * Paints/Repaints the listview control. Internal use.
9758 * [I] infoPtr : valid pointer to the listview structure
9759 * [I] hdc : device context handle
9764 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9766 TRACE("(hdc=%p)\n", hdc
);
9768 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
9770 infoPtr
->bNoItemMetrics
= FALSE
;
9771 LISTVIEW_UpdateItemSize(infoPtr
);
9772 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
9773 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9774 LISTVIEW_UpdateScroll(infoPtr
);
9777 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
9780 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
9785 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
9787 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
9788 EndPaint(infoPtr
->hwndSelf
, &ps
);
9796 * Paints/Repaints the listview control, WM_PAINT handler.
9799 * [I] infoPtr : valid pointer to the listview structure
9800 * [I] hdc : device context handle
9805 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9807 TRACE("(hdc=%p)\n", hdc
);
9809 if (!is_redrawing(infoPtr
))
9810 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
9812 return LISTVIEW_Paint(infoPtr
, hdc
);
9817 * Paints/Repaints the listview control.
9820 * [I] infoPtr : valid pointer to the listview structure
9821 * [I] hdc : device context handle
9822 * [I] options : drawing options
9827 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
9829 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
9831 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
9834 if (options
& PRF_ERASEBKGND
)
9835 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
9837 if (options
& PRF_CLIENT
)
9838 LISTVIEW_Paint(infoPtr
, hdc
);
9846 * Processes double click messages (right mouse button).
9849 * [I] infoPtr : valid pointer to the listview structure
9850 * [I] wKey : key flag
9851 * [I] x,y : mouse coordinate
9856 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9858 LVHITTESTINFO lvHitTestInfo
;
9860 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
9862 /* send NM_RELEASEDCAPTURE notification */
9863 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9865 /* send NM_RDBLCLK notification */
9866 lvHitTestInfo
.pt
.x
= x
;
9867 lvHitTestInfo
.pt
.y
= y
;
9868 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
9869 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
9876 * Processes mouse down messages (right mouse button).
9879 * [I] infoPtr : valid pointer to the listview structure
9880 * [I] wKey : key flag
9881 * [I] x,y : mouse coordinate
9886 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9888 LVHITTESTINFO lvHitTestInfo
;
9891 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
9893 /* send NM_RELEASEDCAPTURE notification */
9894 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9896 /* make sure the listview control window has the focus */
9897 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
9899 /* set right button down flag */
9900 infoPtr
->bRButtonDown
= TRUE
;
9902 /* determine the index of the selected item */
9903 lvHitTestInfo
.pt
.x
= x
;
9904 lvHitTestInfo
.pt
.y
= y
;
9905 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
9907 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
9909 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9910 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
9911 !LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9912 LISTVIEW_SetSelection(infoPtr
, nItem
);
9916 LISTVIEW_DeselectAll(infoPtr
);
9924 * Processes mouse up messages (right mouse button).
9927 * [I] infoPtr : valid pointer to the listview structure
9928 * [I] wKey : key flag
9929 * [I] x,y : mouse coordinate
9934 static LRESULT
LISTVIEW_RButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9936 LVHITTESTINFO lvHitTestInfo
;
9939 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
9941 if (!infoPtr
->bRButtonDown
) return 0;
9943 /* set button flag */
9944 infoPtr
->bRButtonDown
= FALSE
;
9946 /* Send NM_RCLICK notification */
9947 lvHitTestInfo
.pt
.x
= x
;
9948 lvHitTestInfo
.pt
.y
= y
;
9949 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
9950 if (!notify_click(infoPtr
, NM_RCLICK
, &lvHitTestInfo
)) return 0;
9952 /* Change to screen coordinate for WM_CONTEXTMENU */
9953 pt
= lvHitTestInfo
.pt
;
9954 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
9956 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
9957 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
9958 (WPARAM
)infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
9969 * [I] infoPtr : valid pointer to the listview structure
9970 * [I] hwnd : window handle of window containing the cursor
9971 * [I] nHittest : hit-test code
9972 * [I] wMouseMsg : ideintifier of the mouse message
9975 * TRUE if cursor is set
9978 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, HWND hwnd
, UINT nHittest
, UINT wMouseMsg
)
9980 LVHITTESTINFO lvHitTestInfo
;
9982 if(!(LISTVIEW_isHotTracking(infoPtr
))) return FALSE
;
9984 if(!infoPtr
->hHotCursor
) return FALSE
;
9986 GetCursorPos(&lvHitTestInfo
.pt
);
9987 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) return FALSE
;
9989 SetCursor(infoPtr
->hHotCursor
);
9999 * [I] infoPtr : valid pointer to the listview structure
10000 * [I] hwndLoseFocus : handle of previously focused window
10005 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10007 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10009 /* if we have the focus already, there's nothing to do */
10010 if (infoPtr
->bFocus
) return 0;
10012 /* send NM_SETFOCUS notification */
10013 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10015 /* set window focus flag */
10016 infoPtr
->bFocus
= TRUE
;
10018 /* put the focus rect back on */
10019 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10021 /* redraw all visible selected items */
10022 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10032 * [I] infoPtr : valid pointer to the listview structure
10033 * [I] fRedraw : font handle
10034 * [I] fRedraw : redraw flag
10039 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10041 HFONT oldFont
= infoPtr
->hFont
;
10043 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10045 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10046 if (infoPtr
->hFont
== oldFont
) return 0;
10048 LISTVIEW_SaveTextMetrics(infoPtr
);
10050 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10052 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10053 LISTVIEW_UpdateSize(infoPtr
);
10054 LISTVIEW_UpdateScroll(infoPtr
);
10057 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10064 * Message handling for WM_SETREDRAW.
10065 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10068 * [I] infoPtr : valid pointer to the listview structure
10069 * [I] bRedraw: state of redraw flag
10072 * DefWinProc return value
10074 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10076 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10078 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10079 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10081 infoPtr
->bRedraw
= bRedraw
;
10083 if(!bRedraw
) return 0;
10085 if (is_autoarrange(infoPtr
))
10086 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10087 LISTVIEW_UpdateScroll(infoPtr
);
10089 /* despite what the WM_SETREDRAW docs says, apps expect us
10090 * to invalidate the listview here... stupid! */
10091 LISTVIEW_InvalidateList(infoPtr
);
10098 * Resizes the listview control. This function processes WM_SIZE
10099 * messages. At this time, the width and height are not used.
10102 * [I] infoPtr : valid pointer to the listview structure
10103 * [I] Width : new width
10104 * [I] Height : new height
10109 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10111 RECT rcOld
= infoPtr
->rcList
;
10113 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10115 LISTVIEW_UpdateSize(infoPtr
);
10116 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10118 /* do not bother with display related stuff if we're not redrawing */
10119 if (!is_redrawing(infoPtr
)) return 0;
10121 if (is_autoarrange(infoPtr
))
10122 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10124 LISTVIEW_UpdateScroll(infoPtr
);
10126 /* refresh all only for lists whose height changed significantly */
10127 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10128 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10129 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10130 LISTVIEW_InvalidateList(infoPtr
);
10137 * Sets the size information.
10140 * [I] infoPtr : valid pointer to the listview structure
10145 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10147 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
10149 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
10151 if (infoPtr
->uView
== LV_VIEW_LIST
)
10153 /* Apparently the "LIST" style is supposed to have the same
10154 * number of items in a column even if there is no scroll bar.
10155 * Since if a scroll bar already exists then the bottom is already
10156 * reduced, only reduce if the scroll bar does not currently exist.
10157 * The "2" is there to mimic the native control. I think it may be
10158 * related to either padding or edges. (GLA 7/2002)
10160 if (!(infoPtr
->dwStyle
& WS_HSCROLL
))
10161 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
10162 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
10164 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10169 hl
.prc
= &infoPtr
->rcList
;
10171 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10172 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10173 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
10174 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
10175 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
10176 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10178 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
10179 infoPtr
->rcList
.top
+= (infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
) ? 2 : 0;
10182 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
10187 * Processes WM_STYLECHANGED messages.
10190 * [I] infoPtr : valid pointer to the listview structure
10191 * [I] wStyleType : window style type (normal or extended)
10192 * [I] lpss : window style information
10197 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10198 const STYLESTRUCT
*lpss
)
10200 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
10201 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
10204 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10205 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10207 if (wStyleType
!= GWL_STYLE
) return 0;
10209 infoPtr
->dwStyle
= lpss
->styleNew
;
10210 map_style_view(infoPtr
);
10212 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
10213 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
10214 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
10216 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
10217 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
10218 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
10220 if (uNewView
!= uOldView
)
10222 SIZE oldIconSize
= infoPtr
->iconSize
;
10225 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
10226 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
10228 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
10229 SetRectEmpty(&infoPtr
->rcFocus
);
10231 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
10232 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
10234 if (uNewView
== LVS_ICON
)
10236 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
10238 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
10239 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
10240 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
10243 else if (uNewView
== LVS_REPORT
)
10248 LISTVIEW_CreateHeader( infoPtr
);
10250 hl
.prc
= &infoPtr
->rcList
;
10252 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10253 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
10254 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
10255 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
10258 LISTVIEW_UpdateItemSize(infoPtr
);
10261 if (uNewView
== LVS_REPORT
)
10263 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
10265 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
10267 /* Turn off the header control */
10268 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
10269 TRACE("Hide header control, was 0x%08x\n", style
);
10270 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
10272 /* Turn on the header control */
10273 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
10275 TRACE("Show header control, was 0x%08x\n", style
);
10276 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
10282 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
10283 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
10284 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10286 /* update the size of the client area */
10287 LISTVIEW_UpdateSize(infoPtr
);
10289 /* add scrollbars if needed */
10290 LISTVIEW_UpdateScroll(infoPtr
);
10292 /* invalidate client area + erase background */
10293 LISTVIEW_InvalidateList(infoPtr
);
10300 * Processes WM_STYLECHANGING messages.
10303 * [I] infoPtr : valid pointer to the listview structure
10304 * [I] wStyleType : window style type (normal or extended)
10305 * [I0] lpss : window style information
10310 static INT
LISTVIEW_StyleChanging(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10313 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10314 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10316 /* don't forward LVS_OWNERDATA only if not already set to */
10317 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
10319 if (lpss
->styleOld
& LVS_OWNERDATA
)
10320 lpss
->styleNew
|= LVS_OWNERDATA
;
10322 lpss
->styleNew
&= ~LVS_OWNERDATA
;
10330 * Processes WM_SHOWWINDOW messages.
10333 * [I] infoPtr : valid pointer to the listview structure
10334 * [I] bShown : window is being shown (FALSE when hidden)
10335 * [I] iStatus : window show status
10340 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, BOOL bShown
, INT iStatus
)
10342 /* header delayed creation */
10343 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
10345 LISTVIEW_CreateHeader(infoPtr
);
10347 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
10348 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
10356 * Processes CCM_GETVERSION messages.
10359 * [I] infoPtr : valid pointer to the listview structure
10364 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
10366 return infoPtr
->iVersion
;
10371 * Processes CCM_SETVERSION messages.
10374 * [I] infoPtr : valid pointer to the listview structure
10375 * [I] iVersion : version to be set
10378 * -1 when requested version is greater than DLL version;
10379 * previous version otherwise
10381 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
10383 INT iOldVersion
= infoPtr
->iVersion
;
10385 if (iVersion
> COMCTL32_VERSION
)
10388 infoPtr
->iVersion
= iVersion
;
10390 TRACE("new version %d\n", iVersion
);
10392 return iOldVersion
;
10397 * Window procedure of the listview control.
10400 static LRESULT WINAPI
10401 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
10403 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
10405 TRACE("(uMsg=%x wParam=%lx lParam=%lx)\n", uMsg
, wParam
, lParam
);
10407 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
10408 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10412 case LVM_APPROXIMATEVIEWRECT
:
10413 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
10414 LOWORD(lParam
), HIWORD(lParam
));
10416 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
10418 case LVM_CANCELEDITLABEL
:
10419 return LISTVIEW_CancelEditLabel(infoPtr
);
10421 case LVM_CREATEDRAGIMAGE
:
10422 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
10424 case LVM_DELETEALLITEMS
:
10425 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
10427 case LVM_DELETECOLUMN
:
10428 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
10430 case LVM_DELETEITEM
:
10431 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
10433 case LVM_EDITLABELW
:
10434 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, TRUE
);
10436 case LVM_EDITLABELA
:
10437 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, FALSE
);
10439 /* case LVM_ENABLEGROUPVIEW: */
10441 case LVM_ENSUREVISIBLE
:
10442 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
10444 case LVM_FINDITEMW
:
10445 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
10447 case LVM_FINDITEMA
:
10448 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
10450 case LVM_GETBKCOLOR
:
10451 return infoPtr
->clrBk
;
10453 /* case LVM_GETBKIMAGE: */
10455 case LVM_GETCALLBACKMASK
:
10456 return infoPtr
->uCallbackMask
;
10458 case LVM_GETCOLUMNA
:
10459 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
10461 case LVM_GETCOLUMNW
:
10462 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
10464 case LVM_GETCOLUMNORDERARRAY
:
10465 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
10467 case LVM_GETCOLUMNWIDTH
:
10468 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
10470 case LVM_GETCOUNTPERPAGE
:
10471 return LISTVIEW_GetCountPerPage(infoPtr
);
10473 case LVM_GETEDITCONTROL
:
10474 return (LRESULT
)infoPtr
->hwndEdit
;
10476 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
10477 return infoPtr
->dwLvExStyle
;
10479 /* case LVM_GETGROUPINFO: */
10481 /* case LVM_GETGROUPMETRICS: */
10483 case LVM_GETHEADER
:
10484 return (LRESULT
)infoPtr
->hwndHeader
;
10486 case LVM_GETHOTCURSOR
:
10487 return (LRESULT
)infoPtr
->hHotCursor
;
10489 case LVM_GETHOTITEM
:
10490 return infoPtr
->nHotItem
;
10492 case LVM_GETHOVERTIME
:
10493 return infoPtr
->dwHoverTime
;
10495 case LVM_GETIMAGELIST
:
10496 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
10498 /* case LVM_GETINSERTMARK: */
10500 /* case LVM_GETINSERTMARKCOLOR: */
10502 /* case LVM_GETINSERTMARKRECT: */
10504 case LVM_GETISEARCHSTRINGA
:
10505 case LVM_GETISEARCHSTRINGW
:
10506 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
10510 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
10513 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
10515 case LVM_GETITEMCOUNT
:
10516 return infoPtr
->nItemCount
;
10518 case LVM_GETITEMPOSITION
:
10519 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
10521 case LVM_GETITEMRECT
:
10522 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
10524 case LVM_GETITEMSPACING
:
10525 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
10527 case LVM_GETITEMSTATE
:
10528 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
10530 case LVM_GETITEMTEXTA
:
10531 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
10533 case LVM_GETITEMTEXTW
:
10534 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
10536 case LVM_GETNEXTITEM
:
10537 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
10539 case LVM_GETNUMBEROFWORKAREAS
:
10540 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
10543 case LVM_GETORIGIN
:
10544 if (!lParam
) return FALSE
;
10545 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
10546 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
10547 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
10550 /* case LVM_GETOUTLINECOLOR: */
10552 /* case LVM_GETSELECTEDCOLUMN: */
10554 case LVM_GETSELECTEDCOUNT
:
10555 return LISTVIEW_GetSelectedCount(infoPtr
);
10557 case LVM_GETSELECTIONMARK
:
10558 return infoPtr
->nSelectionMark
;
10560 case LVM_GETSTRINGWIDTHA
:
10561 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, FALSE
);
10563 case LVM_GETSTRINGWIDTHW
:
10564 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, TRUE
);
10566 case LVM_GETSUBITEMRECT
:
10567 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
10569 case LVM_GETTEXTBKCOLOR
:
10570 return infoPtr
->clrTextBk
;
10572 case LVM_GETTEXTCOLOR
:
10573 return infoPtr
->clrText
;
10575 /* case LVM_GETTILEINFO: */
10577 /* case LVM_GETTILEVIEWINFO: */
10579 case LVM_GETTOOLTIPS
:
10580 if( !infoPtr
->hwndToolTip
)
10581 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
10582 return (LRESULT
)infoPtr
->hwndToolTip
;
10584 case LVM_GETTOPINDEX
:
10585 return LISTVIEW_GetTopIndex(infoPtr
);
10587 case LVM_GETUNICODEFORMAT
:
10588 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
10591 return infoPtr
->uView
;
10593 case LVM_GETVIEWRECT
:
10594 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
10596 case LVM_GETWORKAREAS
:
10597 FIXME("LVM_GETWORKAREAS: unimplemented\n");
10600 /* case LVM_HASGROUP: */
10603 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
10605 case LVM_INSERTCOLUMNA
:
10606 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
10608 case LVM_INSERTCOLUMNW
:
10609 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
10611 /* case LVM_INSERTGROUP: */
10613 /* case LVM_INSERTGROUPSORTED: */
10615 case LVM_INSERTITEMA
:
10616 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
10618 case LVM_INSERTITEMW
:
10619 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
10621 /* case LVM_INSERTMARKHITTEST: */
10623 /* case LVM_ISGROUPVIEWENABLED: */
10625 case LVM_ISITEMVISIBLE
:
10626 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
10628 case LVM_MAPIDTOINDEX
:
10629 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
10631 case LVM_MAPINDEXTOID
:
10632 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
10634 /* case LVM_MOVEGROUP: */
10636 /* case LVM_MOVEITEMTOGROUP: */
10638 case LVM_REDRAWITEMS
:
10639 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
10641 /* case LVM_REMOVEALLGROUPS: */
10643 /* case LVM_REMOVEGROUP: */
10646 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
10648 case LVM_SETBKCOLOR
:
10649 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
10651 /* case LVM_SETBKIMAGE: */
10653 case LVM_SETCALLBACKMASK
:
10654 infoPtr
->uCallbackMask
= (UINT
)wParam
;
10657 case LVM_SETCOLUMNA
:
10658 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
10660 case LVM_SETCOLUMNW
:
10661 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
10663 case LVM_SETCOLUMNORDERARRAY
:
10664 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
10666 case LVM_SETCOLUMNWIDTH
:
10667 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
10669 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
10670 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
10672 /* case LVM_SETGROUPINFO: */
10674 /* case LVM_SETGROUPMETRICS: */
10676 case LVM_SETHOTCURSOR
:
10677 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
10679 case LVM_SETHOTITEM
:
10680 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
10682 case LVM_SETHOVERTIME
:
10683 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)wParam
);
10685 case LVM_SETICONSPACING
:
10686 return LISTVIEW_SetIconSpacing(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
10688 case LVM_SETIMAGELIST
:
10689 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
10691 /* case LVM_SETINFOTIP: */
10693 /* case LVM_SETINSERTMARK: */
10695 /* case LVM_SETINSERTMARKCOLOR: */
10700 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
10701 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
10704 case LVM_SETITEMCOUNT
:
10705 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
10707 case LVM_SETITEMPOSITION
:
10710 pt
.x
= (short)LOWORD(lParam
);
10711 pt
.y
= (short)HIWORD(lParam
);
10712 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, pt
);
10715 case LVM_SETITEMPOSITION32
:
10716 if (lParam
== 0) return FALSE
;
10717 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, *((POINT
*)lParam
));
10719 case LVM_SETITEMSTATE
:
10720 if (lParam
== 0) return FALSE
;
10721 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
10723 case LVM_SETITEMTEXTA
:
10724 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
10726 case LVM_SETITEMTEXTW
:
10727 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
10729 /* case LVM_SETOUTLINECOLOR: */
10731 /* case LVM_SETSELECTEDCOLUMN: */
10733 case LVM_SETSELECTIONMARK
:
10734 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
10736 case LVM_SETTEXTBKCOLOR
:
10737 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
10739 case LVM_SETTEXTCOLOR
:
10740 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
10742 /* case LVM_SETTILEINFO: */
10744 /* case LVM_SETTILEVIEWINFO: */
10746 /* case LVM_SETTILEWIDTH: */
10748 case LVM_SETTOOLTIPS
:
10749 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
10751 case LVM_SETUNICODEFORMAT
:
10752 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
10755 return LISTVIEW_SetView(infoPtr
, wParam
);
10757 /* case LVM_SETWORKAREAS: */
10759 /* case LVM_SORTGROUPS: */
10761 case LVM_SORTITEMS
:
10762 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, (LPARAM
)wParam
, FALSE
);
10764 case LVM_SORTITEMSEX
:
10765 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, (LPARAM
)wParam
, TRUE
);
10767 case LVM_SUBITEMHITTEST
:
10768 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
10771 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
10773 case CCM_GETVERSION
:
10774 return LISTVIEW_GetVersion(infoPtr
);
10776 case CCM_SETVERSION
:
10777 return LISTVIEW_SetVersion(infoPtr
, wParam
);
10780 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
10783 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
10786 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
10789 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
10792 return LISTVIEW_Destroy(infoPtr
);
10795 return LISTVIEW_Enable(infoPtr
, (BOOL
)wParam
);
10797 case WM_ERASEBKGND
:
10798 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
10800 case WM_GETDLGCODE
:
10801 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
10804 return (LRESULT
)infoPtr
->hFont
;
10807 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
10810 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
10813 return LISTVIEW_KillFocus(infoPtr
);
10815 case WM_LBUTTONDBLCLK
:
10816 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10818 case WM_LBUTTONDOWN
:
10819 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10822 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10825 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10827 case WM_MOUSEHOVER
:
10828 return LISTVIEW_MouseHover(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10831 return LISTVIEW_NCDestroy(infoPtr
);
10834 if (LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
))
10839 if (lParam
&& ((LPNMHDR
)lParam
)->hwndFrom
== infoPtr
->hwndHeader
)
10840 return LISTVIEW_HeaderNotification(infoPtr
, (LPNMHEADERW
)lParam
);
10843 case WM_NOTIFYFORMAT
:
10844 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
10846 case WM_PRINTCLIENT
:
10847 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
10850 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
10852 case WM_RBUTTONDBLCLK
:
10853 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10855 case WM_RBUTTONDOWN
:
10856 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10859 return LISTVIEW_RButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10862 if(LISTVIEW_SetCursor(infoPtr
, (HWND
)wParam
, LOWORD(lParam
), HIWORD(lParam
)))
10867 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
10870 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
10873 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
10875 case WM_SHOWWINDOW
:
10876 LISTVIEW_ShowWindow(infoPtr
, (BOOL
)wParam
, (INT
)lParam
);
10877 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10880 return LISTVIEW_Size(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
10882 case WM_STYLECHANGED
:
10883 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
10885 case WM_STYLECHANGING
:
10886 return LISTVIEW_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
10888 case WM_SYSCOLORCHANGE
:
10889 COMCTL32_RefreshSysColors();
10892 /* case WM_TIMER: */
10893 case WM_THEMECHANGED
:
10894 return LISTVIEW_ThemeChanged(infoPtr
);
10897 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
10899 case WM_MOUSEWHEEL
:
10900 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
10901 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10902 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
10904 case WM_WINDOWPOSCHANGED
:
10905 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
10907 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
10908 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
10910 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
10912 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
10915 LISTVIEW_UpdateSize(infoPtr
);
10916 LISTVIEW_UpdateScroll(infoPtr
);
10918 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10920 /* case WM_WININICHANGE: */
10923 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
10924 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
10927 /* call default window procedure */
10928 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10935 * Registers the window class.
10943 void LISTVIEW_Register(void)
10945 WNDCLASSW wndClass
;
10947 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
10948 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
10949 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
10950 wndClass
.cbClsExtra
= 0;
10951 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
10952 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
10953 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
10954 wndClass
.lpszClassName
= WC_LISTVIEWW
;
10955 RegisterClassW(&wndClass
);
10960 * Unregisters the window class.
10968 void LISTVIEW_Unregister(void)
10970 UnregisterClassW(WC_LISTVIEWW
, NULL
);
10975 * Handle any WM_COMMAND messages
10978 * [I] infoPtr : valid pointer to the listview structure
10979 * [I] wParam : the first message parameter
10980 * [I] lParam : the second message parameter
10985 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10987 switch (HIWORD(wParam
))
10992 * Adjust the edit window size
10994 WCHAR buffer
[1024];
10995 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
10996 HFONT hFont
, hOldFont
= 0;
11000 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11001 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11002 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11004 /* Select font to get the right dimension of the string */
11005 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11008 hOldFont
= SelectObject(hdc
, hFont
);
11011 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11013 TEXTMETRICW textMetric
;
11015 /* Add Extra spacing for the next character */
11016 GetTextMetricsW(hdc
, &textMetric
);
11017 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11025 rect
.bottom
- rect
.top
,
11026 SWP_DRAWFRAME
|SWP_NOMOVE
);
11029 SelectObject(hdc
, hOldFont
);
11031 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11037 LISTVIEW_CancelEditLabel(infoPtr
);
11041 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
11050 * Subclassed edit control windproc function
11053 * [I] hwnd : the edit window handle
11054 * [I] uMsg : the message that is to be processed
11055 * [I] wParam : first message parameter
11056 * [I] lParam : second message parameter
11057 * [I] isW : TRUE if input is Unicode
11062 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
11064 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
11067 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
11068 hwnd
, uMsg
, wParam
, lParam
, isW
);
11072 case WM_GETDLGCODE
:
11073 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
11077 WNDPROC editProc
= infoPtr
->EditWndProc
;
11078 infoPtr
->EditWndProc
= 0;
11079 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
11080 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
11084 if (VK_ESCAPE
== (INT
)wParam
)
11089 else if (VK_RETURN
== (INT
)wParam
)
11093 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
11096 /* kill the edit */
11097 if (infoPtr
->hwndEdit
)
11098 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
11100 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
11106 * Subclassed edit control Unicode windproc function
11109 * [I] hwnd : the edit window handle
11110 * [I] uMsg : the message that is to be processed
11111 * [I] wParam : first message parameter
11112 * [I] lParam : second message parameter
11116 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11118 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
11123 * Subclassed edit control ANSI windproc function
11126 * [I] hwnd : the edit window handle
11127 * [I] uMsg : the message that is to be processed
11128 * [I] wParam : first message parameter
11129 * [I] lParam : second message parameter
11133 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11135 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
11140 * Creates a subclassed edit control
11143 * [I] infoPtr : valid pointer to the listview structure
11144 * [I] text : initial text for the edit
11145 * [I] style : the window style
11146 * [I] isW : TRUE if input is Unicode
11150 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, DWORD style
, BOOL isW
)
11152 WCHAR editName
[5] = { 'E', 'd', 'i', 't', '\0' };
11154 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
11156 TRACE("(text=%s, ..., isW=%d)\n", debugtext_t(text
, isW
), isW
);
11158 style
|= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
;
11160 /* Window will be resized and positioned after LVN_BEGINLABELEDIT */
11162 hedit
= CreateWindowW(editName
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
11164 hedit
= CreateWindowA("Edit", (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
11166 if (!hedit
) return 0;
11168 infoPtr
->EditWndProc
= (WNDPROC
)
11169 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
11170 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
11172 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);