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-2011 Nikolay Sivov
10 * Copyright 2009 Owen Rudge for CodeWeavers
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 * This code was audited for completeness against the documented features
29 * of Comctl32.dll version 6.0 on May. 20, 2005, by James Hawkins.
31 * Unless otherwise noted, we believe this code to be complete, as per
32 * the specification mentioned above.
33 * If you discover missing features, or bugs, please note them below.
37 * Default Message Processing
38 * -- WM_CREATE: create the icon and small icon image lists at this point only if
39 * the LVS_SHAREIMAGELISTS style is not specified.
40 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
41 * or small icon and the LVS_AUTOARRANGE style is specified.
46 * -- Hot item handling, mouse hovering
47 * -- Workareas support
52 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
53 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
54 * -- LVA_SNAPTOGRID not implemented
55 * -- LISTVIEW_ApproximateViewRect partially implemented
56 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
57 * -- LISTVIEW_SetIconSpacing is incomplete
58 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
61 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
62 * linear in the number of items in the list, and this is
63 * unacceptable for large lists.
64 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
65 * binary search to calculate item index (e.g. DPA_Search()).
66 * This requires sorted state to be reliably tracked in item modifiers.
67 * -- we should keep an ordered array of coordinates in iconic mode
68 * this would allow to frame items (iterator_frameditems),
69 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
76 * -- 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
105 * -- LVM_ENABLEGROUPVIEW
106 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
107 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
108 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
109 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
110 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
111 * -- LVM_GETINSERTMARKRECT
112 * -- LVM_GETNUMBEROFWORKAREAS
113 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
114 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
115 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
116 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
117 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
118 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
119 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
120 * -- LVM_INSERTGROUPSORTED
121 * -- LVM_INSERTMARKHITTEST
122 * -- LVM_ISGROUPVIEWENABLED
124 * -- LVM_MOVEITEMTOGROUP
126 * -- LVM_SETTILEWIDTH
130 * -- ListView_GetHoverTime, ListView_SetHoverTime
131 * -- ListView_GetISearchString
132 * -- ListView_GetNumberOfWorkAreas
133 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
138 * Known differences in message stream from native control (not known if
139 * these differences cause problems):
140 * LVM_INSERTITEM issues LVM_SETITEMSTATE and LVM_SETITEM in certain cases.
141 * LVM_SETITEM does not always issue LVN_ITEMCHANGING/LVN_ITEMCHANGED.
142 * WM_CREATE does not issue WM_QUERYUISTATE and associated registry
143 * processing for "USEDOUBLECLICKTIME".
147 #include "wine/port.h"
162 #include "commctrl.h"
163 #include "comctl32.h"
166 #include "wine/debug.h"
167 #include "wine/unicode.h"
169 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
171 typedef struct tagCOLUMN_INFO
173 RECT rcHeader
; /* tracks the header's rectangle */
174 INT fmt
; /* same as LVCOLUMN.fmt */
178 typedef struct tagITEMHDR
182 } ITEMHDR
, *LPITEMHDR
;
184 typedef struct tagSUBITEM_INFO
190 typedef struct tagITEM_ID ITEM_ID
;
192 typedef struct tagITEM_INFO
203 UINT id
; /* item id */
204 HDPA item
; /* link to item data */
207 typedef struct tagRANGE
213 typedef struct tagRANGES
218 typedef struct tagITERATOR
227 typedef struct tagDELAYED_ITEM_EDIT
233 typedef struct tagLISTVIEW_INFO
237 RECT rcList
; /* This rectangle is really the window
238 * client rectangle possibly reduced by the
239 * horizontal scroll bar and/or header - see
240 * LISTVIEW_UpdateSize. This rectangle offset
241 * by the LISTVIEW_GetOrigin value is in
242 * client coordinates */
244 /* notification window */
247 BOOL bDoChangeNotify
; /* send change notification messages? */
254 INT nItemCount
; /* the number of items in the list */
255 HDPA hdpaItems
; /* array ITEM_INFO pointers */
256 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
257 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
258 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
259 RANGES selectionRanges
;
260 INT nSelectionMark
; /* item to start next multiselection from */
262 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
265 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
266 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
269 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
274 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
278 DWORD dwStyle
; /* the cached window GWL_STYLE */
279 DWORD dwLvExStyle
; /* extended listview style */
280 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
286 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
289 HIMAGELIST himlNormal
;
290 HIMAGELIST himlSmall
;
291 HIMAGELIST himlState
;
295 POINT currIconPos
; /* this is the position next icon will be placed */
299 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
301 /* marquee selection */
302 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
304 RECT marqueeRect
; /* absolute coordinates of marquee selection */
305 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
306 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
309 BOOL bFocus
; /* control has focus */
311 RECT rcFocus
; /* focus bounds */
322 INT ntmHeight
; /* Some cached metrics of the font used */
323 INT ntmMaxCharWidth
; /* by the listview to draw items */
326 /* mouse operation */
330 POINT ptClickPos
; /* point where the user clicked */
331 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
335 /* keyboard operation */
336 DWORD lastKeyPressTimestamp
;
338 INT nSearchParamLength
;
339 WCHAR szSearchParam
[ MAX_PATH
];
342 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
343 BOOL bIsDrawing
; /* Drawing in progress */
344 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
345 BOOL bRedraw
; /* WM_SETREDRAW switch */
348 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
354 /* How many we debug buffer to allocate */
355 #define DEBUG_BUFFERS 20
356 /* The size of a single debug buffer */
357 #define DEBUG_BUFFER_SIZE 256
359 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
360 #define SB_INTERNAL -1
362 /* maximum size of a label */
363 #define DISP_TEXT_SIZE 260
365 /* padding for items in list and small icon display modes */
366 #define WIDTH_PADDING 12
368 /* padding for items in list, report and small icon display modes */
369 #define HEIGHT_PADDING 1
371 /* offset of items in report display mode */
372 #define REPORT_MARGINX 2
374 /* padding for icon in large icon display mode
375 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
376 * that HITTEST will see.
377 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
378 * ICON_TOP_PADDING - sum of the two above.
379 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
380 * LABEL_HOR_PADDING - between text and sides of box
381 * LABEL_VERT_PADDING - between bottom of text and end of box
383 * ICON_LR_PADDING - additional width above icon size.
384 * ICON_LR_HALF - half of the above value
386 #define ICON_TOP_PADDING_NOTHITABLE 2
387 #define ICON_TOP_PADDING_HITABLE 2
388 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
389 #define ICON_BOTTOM_PADDING 4
390 #define LABEL_HOR_PADDING 5
391 #define LABEL_VERT_PADDING 7
392 #define ICON_LR_PADDING 16
393 #define ICON_LR_HALF (ICON_LR_PADDING/2)
395 /* default label width for items in list and small icon display modes */
396 #define DEFAULT_LABEL_WIDTH 40
397 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
398 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
400 /* default column width for items in list display mode */
401 #define DEFAULT_COLUMN_WIDTH 128
403 /* Size of "line" scroll for V & H scrolls */
404 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
406 /* Padding between image and label */
407 #define IMAGE_PADDING 2
409 /* Padding behind the label */
410 #define TRAILING_LABEL_PADDING 12
411 #define TRAILING_HEADER_PADDING 11
413 /* Border for the icon caption */
414 #define CAPTION_BORDER 2
416 /* Standard DrawText flags */
417 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
418 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
419 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
421 /* Image index from state */
422 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
424 /* The time in milliseconds to reset the search in the list */
425 #define KEY_DELAY 450
427 /* Dump the LISTVIEW_INFO structure to the debug channel */
428 #define LISTVIEW_DUMP(iP) do { \
429 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
430 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
431 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
432 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
433 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
434 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
435 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
436 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
437 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
438 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
441 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
444 * forward declarations
446 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
447 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
448 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
449 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
450 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
451 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
452 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
453 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
454 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
455 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
456 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
457 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
458 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
459 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
460 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
461 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
462 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
463 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
464 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
465 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
467 /******** Text handling functions *************************************/
469 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
470 * text string. The string may be ANSI or Unicode, in which case
471 * the boolean isW tells us the type of the string.
473 * The name of the function tell what type of strings it expects:
474 * W: Unicode, T: ANSI/Unicode - function of isW
477 static inline BOOL
is_text(LPCWSTR text
)
479 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
482 static inline int textlenT(LPCWSTR text
, BOOL isW
)
484 return !is_text(text
) ? 0 :
485 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
488 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
491 if (isSrcW
) lstrcpynW(dest
, src
, max
);
492 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
494 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
495 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
498 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
500 LPWSTR wstr
= (LPWSTR
)text
;
502 if (!isW
&& is_text(text
))
504 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
505 wstr
= Alloc(len
* sizeof(WCHAR
));
506 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
508 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
512 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
514 if (!isW
&& is_text(wstr
)) Free (wstr
);
518 * dest is a pointer to a Unicode string
519 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
521 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
525 if (src
== LPSTR_TEXTCALLBACKW
)
527 if (is_text(*dest
)) Free(*dest
);
528 *dest
= LPSTR_TEXTCALLBACKW
;
532 LPWSTR pszText
= textdupTtoW(src
, isW
);
533 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
534 bResult
= Str_SetPtrW(dest
, pszText
);
535 textfreeT(pszText
, isW
);
541 * compares a Unicode to a Unicode/ANSI text string
543 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
545 if (!aw
) return bt
? -1 : 0;
547 if (aw
== LPSTR_TEXTCALLBACKW
)
548 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
549 if (bt
!= LPSTR_TEXTCALLBACKW
)
551 LPWSTR bw
= textdupTtoW(bt
, isW
);
552 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
560 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
564 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
565 res
= CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
);
566 return res
? res
- sizeof(WCHAR
) : res
;
569 /******** Debugging functions *****************************************/
571 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
573 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
574 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
577 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
579 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
580 n
= min(textlenT(text
, isW
), n
);
581 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
584 static char* debug_getbuf(void)
586 static int index
= 0;
587 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
588 return buffers
[index
++ % DEBUG_BUFFERS
];
591 static inline const char* debugrange(const RANGE
*lprng
)
593 if (!lprng
) return "(null)";
594 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
597 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
599 char* buf
= debug_getbuf(), *text
= buf
;
600 int len
, size
= DEBUG_BUFFER_SIZE
;
602 if (pScrollInfo
== NULL
) return "(null)";
603 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
604 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
605 if (pScrollInfo
->fMask
& SIF_RANGE
)
606 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
608 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
609 if (pScrollInfo
->fMask
& SIF_PAGE
)
610 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
612 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
613 if (pScrollInfo
->fMask
& SIF_POS
)
614 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
616 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
617 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
618 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
620 if (len
== -1) goto end
; buf
+= len
;
623 buf
= text
+ strlen(text
);
625 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
629 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
631 if (!plvnm
) return "(null)";
632 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
633 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
634 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
635 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
638 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
640 char* buf
= debug_getbuf(), *text
= buf
;
641 int len
, size
= DEBUG_BUFFER_SIZE
;
643 if (lpLVItem
== NULL
) return "(null)";
644 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
645 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
646 if (lpLVItem
->mask
& LVIF_STATE
)
647 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
649 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
650 if (lpLVItem
->mask
& LVIF_TEXT
)
651 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
653 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
654 if (lpLVItem
->mask
& LVIF_IMAGE
)
655 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
657 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
658 if (lpLVItem
->mask
& LVIF_PARAM
)
659 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
661 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
662 if (lpLVItem
->mask
& LVIF_INDENT
)
663 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
665 if (len
== -1) goto end
; buf
+= len
;
668 buf
= text
+ strlen(text
);
670 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
674 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
676 char* buf
= debug_getbuf(), *text
= buf
;
677 int len
, size
= DEBUG_BUFFER_SIZE
;
679 if (lpColumn
== NULL
) return "(null)";
680 len
= snprintf(buf
, size
, "{");
681 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
682 if (lpColumn
->mask
& LVCF_SUBITEM
)
683 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
685 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
686 if (lpColumn
->mask
& LVCF_FMT
)
687 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
689 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
690 if (lpColumn
->mask
& LVCF_WIDTH
)
691 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
693 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
694 if (lpColumn
->mask
& LVCF_TEXT
)
695 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
697 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
698 if (lpColumn
->mask
& LVCF_IMAGE
)
699 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
701 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
702 if (lpColumn
->mask
& LVCF_ORDER
)
703 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
705 if (len
== -1) goto end
; buf
+= len
;
708 buf
= text
+ strlen(text
);
710 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
714 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
716 if (!lpht
) return "(null)";
718 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
719 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
722 /* Return the corresponding text for a given scroll value */
723 static inline LPCSTR
debugscrollcode(int nScrollCode
)
727 case SB_LINELEFT
: return "SB_LINELEFT";
728 case SB_LINERIGHT
: return "SB_LINERIGHT";
729 case SB_PAGELEFT
: return "SB_PAGELEFT";
730 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
731 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
732 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
733 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
734 case SB_INTERNAL
: return "SB_INTERNAL";
735 default: return "unknown";
740 /******** Notification functions ************************************/
742 static int get_ansi_notification(UINT unicodeNotificationCode
)
744 switch (unicodeNotificationCode
)
746 case LVN_BEGINLABELEDITA
:
747 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
748 case LVN_ENDLABELEDITA
:
749 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
750 case LVN_GETDISPINFOA
:
751 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
752 case LVN_SETDISPINFOA
:
753 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
754 case LVN_ODFINDITEMA
:
755 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
756 case LVN_GETINFOTIPA
:
757 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
758 /* header forwards */
760 case HDN_TRACKW
: return HDN_TRACKA
;
762 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
763 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
764 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
765 case HDN_ITEMCHANGINGA
:
766 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
767 case HDN_ITEMCHANGEDA
:
768 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
770 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
771 case HDN_DIVIDERDBLCLICKA
:
772 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
775 FIXME("unknown notification %x\n", unicodeNotificationCode
);
776 return unicodeNotificationCode
;
779 /* forwards header notifications to listview parent */
780 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
784 HD_TEXTFILTERA textfilter
;
785 LPSTR text
= NULL
, filter
= NULL
;
788 /* on unicode format exit earlier */
789 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
790 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
793 /* header always supplies unicode notifications,
794 all we have to do is to convert strings to ANSI */
795 nmhA
= *(const NMHEADERA
*)lpnmh
;
798 hditema
= *(HDITEMA
*)lpnmh
->pitem
;
799 nmhA
.pitem
= &hditema
;
800 /* convert item text */
801 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
803 hditema
.pszText
= NULL
;
804 Str_SetPtrWtoA(&hditema
.pszText
, lpnmh
->pitem
->pszText
);
805 text
= hditema
.pszText
;
807 /* convert filter text */
808 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
809 lpnmh
->pitem
->pvFilter
)
811 hditema
.pvFilter
= &textfilter
;
812 textfilter
= *(HD_TEXTFILTERA
*)(lpnmh
->pitem
->pvFilter
);
813 textfilter
.pszText
= NULL
;
814 Str_SetPtrWtoA(&textfilter
.pszText
, ((HD_TEXTFILTERW
*)lpnmh
->pitem
->pvFilter
)->pszText
);
815 filter
= textfilter
.pszText
;
818 nmhA
.hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
820 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhA
.hdr
.idFrom
,
830 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
834 TRACE("(code=%d)\n", code
);
836 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
837 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
839 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
841 TRACE(" <= %ld\n", result
);
846 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
849 HWND hwnd
= infoPtr
->hwndSelf
;
850 notify_hdr(infoPtr
, code
, &nmh
);
851 return IsWindow(hwnd
);
854 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
865 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
866 item
.iItem
= htInfo
->iItem
;
868 item
.stateMask
= (UINT
)-1;
869 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
870 nmia
.lParam
= item
.lParam
;
871 nmia
.uOldState
= item
.state
;
872 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
873 nmia
.uChanged
= LVIF_STATE
;
876 nmia
.iItem
= htInfo
->iItem
;
877 nmia
.iSubItem
= htInfo
->iSubItem
;
878 nmia
.ptAction
= htInfo
->pt
;
880 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
881 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
882 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
884 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
887 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
889 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
890 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
893 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
897 HWND hwnd
= infoPtr
->hwndSelf
;
899 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
900 ZeroMemory(&nmia
, sizeof(nmia
));
901 nmia
.iItem
= lvht
->iItem
;
902 nmia
.iSubItem
= lvht
->iSubItem
;
903 nmia
.ptAction
= lvht
->pt
;
904 item
.mask
= LVIF_PARAM
;
905 item
.iItem
= lvht
->iItem
;
907 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
908 notify_hdr(infoPtr
, code
, (LPNMHDR
)&nmia
);
909 return IsWindow(hwnd
);
912 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
916 HWND hwnd
= infoPtr
->hwndSelf
;
918 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
920 item
.mask
= LVIF_PARAM
;
923 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
924 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
925 return IsWindow(hwnd
);
929 Send notification. depends on dispinfoW having same
930 structure as dispinfoA.
931 infoPtr : listview struct
932 code : *Unicode* notification code
933 pdi : dispinfo structure (can be unicode or ansi)
934 isW : TRUE if dispinfo is Unicode
936 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
938 INT length
= 0, ret_length
;
939 LPWSTR buffer
= NULL
, ret_text
;
940 BOOL return_ansi
= FALSE
;
941 BOOL return_unicode
= FALSE
;
944 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
946 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
947 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
950 ret_length
= pdi
->item
.cchTextMax
;
951 ret_text
= pdi
->item
.pszText
;
953 if (return_unicode
|| return_ansi
)
955 if (code
!= LVN_GETDISPINFOW
)
957 length
= return_ansi
?
958 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
959 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
963 length
= pdi
->item
.cchTextMax
;
964 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
967 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
968 if (!buffer
) return FALSE
;
971 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
974 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
977 pdi
->item
.pszText
= buffer
;
978 pdi
->item
.cchTextMax
= length
;
981 if (infoPtr
->notifyFormat
== NFR_ANSI
)
982 code
= get_ansi_notification(code
);
984 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
985 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
986 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
988 if (return_ansi
|| return_unicode
)
990 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
992 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
994 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
996 strcpyW(ret_text
, pdi
->item
.pszText
);
998 else if (return_ansi
) /* note : pointer can be changed by app ! */
1000 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
1001 ret_length
, NULL
, NULL
);
1004 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
1005 ret_text
, ret_length
);
1007 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
1008 pdi
->item
.cchTextMax
= ret_length
;
1014 /* if dipsinfo holder changed notification code then convert */
1015 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1017 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1019 buffer
= Alloc(length
* sizeof(CHAR
));
1020 if (!buffer
) return FALSE
;
1022 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1023 ret_length
, NULL
, NULL
);
1025 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1032 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1033 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1035 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1036 lpnmlvcd
->nmcd
.hdc
= hdc
;
1037 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1038 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1039 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1040 if (!lplvItem
) return;
1041 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1042 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1043 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1044 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1045 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1046 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1049 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1051 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1054 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1055 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1056 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1057 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1058 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1059 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1063 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1065 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
1066 lpnmlvcd
->clrTextBk
= comctl32_color
.clrWindow
;
1067 if (lpnmlvcd
->clrText
== CLR_DEFAULT
)
1068 lpnmlvcd
->clrText
= comctl32_color
.clrWindowText
;
1070 /* apparently, for selected items, we have to override the returned values */
1073 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1075 if (infoPtr
->bFocus
)
1077 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1078 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1080 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1082 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1083 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1088 /* Set the text attributes */
1089 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
1091 SetBkMode(hdc
, OPAQUE
);
1092 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1095 SetBkMode(hdc
, TRANSPARENT
);
1096 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1099 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1101 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1104 /* returns TRUE when repaint needed, FALSE otherwise */
1105 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1107 MEASUREITEMSTRUCT mis
;
1108 mis
.CtlType
= ODT_LISTVIEW
;
1109 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1113 mis
.itemHeight
= infoPtr
->nItemHeight
;
1114 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1115 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1117 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1123 /******** Item iterator functions **********************************/
1125 static RANGES
ranges_create(int count
);
1126 static void ranges_destroy(RANGES ranges
);
1127 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1128 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1129 static void ranges_dump(RANGES ranges
);
1131 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1133 RANGE range
= { nItem
, nItem
+ 1 };
1135 return ranges_add(ranges
, range
);
1138 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1140 RANGE range
= { nItem
, nItem
+ 1 };
1142 return ranges_del(ranges
, range
);
1146 * ITERATOR DOCUMENTATION
1148 * The iterator functions allow for easy, and convenient iteration
1149 * over items of interest in the list. Typically, you create a
1150 * iterator, use it, and destroy it, as such:
1153 * iterator_xxxitems(&i, ...);
1154 * while (iterator_{prev,next}(&i)
1156 * //code which uses i.nItem
1158 * iterator_destroy(&i);
1160 * where xxx is either: framed, or visible.
1161 * Note that it is important that the code destroys the iterator
1162 * after it's done with it, as the creation of the iterator may
1163 * allocate memory, which thus needs to be freed.
1165 * You can iterate both forwards, and backwards through the list,
1166 * by using iterator_next or iterator_prev respectively.
1168 * Lower numbered items are draw on top of higher number items in
1169 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1170 * items may overlap). So, to test items, you should use
1172 * which lists the items top to bottom (in Z-order).
1173 * For drawing items, you should use
1175 * which lists the items bottom to top (in Z-order).
1176 * If you keep iterating over the items after the end-of-items
1177 * marker (-1) is returned, the iterator will start from the
1178 * beginning. Typically, you don't need to test for -1,
1179 * because iterator_{next,prev} will return TRUE if more items
1180 * are to be iterated over, or FALSE otherwise.
1182 * Note: the iterator is defined to be bidirectional. That is,
1183 * any number of prev followed by any number of next, or
1184 * five versa, should leave the iterator at the same item:
1185 * prev * n, next * n = next * n, prev * n
1187 * The iterator has a notion of an out-of-order, special item,
1188 * which sits at the start of the list. This is used in
1189 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1190 * which needs to be first, as it may overlap other items.
1192 * The code is a bit messy because we have:
1193 * - a special item to deal with
1194 * - simple range, or composite range
1196 * If you find bugs, or want to add features, please make sure you
1197 * always check/modify *both* iterator_prev, and iterator_next.
1201 * This function iterates through the items in increasing order,
1202 * but prefixed by the special item, then -1. That is:
1203 * special, 1, 2, 3, ..., n, -1.
1204 * Each item is listed only once.
1206 static inline BOOL
iterator_next(ITERATOR
* i
)
1210 i
->nItem
= i
->nSpecial
;
1211 if (i
->nItem
!= -1) return TRUE
;
1213 if (i
->nItem
== i
->nSpecial
)
1215 if (i
->ranges
) i
->index
= 0;
1221 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1222 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1227 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1228 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1231 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1233 i
->nItem
= i
->range
.lower
;
1234 if (i
->nItem
>= 0) goto testitem
;
1241 * This function iterates through the items in decreasing order,
1242 * followed by the special item, then -1. That is:
1243 * n, n-1, ..., 3, 2, 1, special, -1.
1244 * Each item is listed only once.
1246 static inline BOOL
iterator_prev(ITERATOR
* i
)
1253 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1256 if (i
->nItem
== i
->nSpecial
)
1264 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1265 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1271 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1274 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1276 i
->nItem
= i
->range
.upper
;
1277 if (i
->nItem
> 0) goto testitem
;
1279 return (i
->nItem
= i
->nSpecial
) != -1;
1282 static RANGE
iterator_range(const ITERATOR
*i
)
1286 if (!i
->ranges
) return i
->range
;
1288 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1290 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1291 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1293 else range
.lower
= range
.upper
= 0;
1299 * Releases resources associated with this ierator.
1301 static inline void iterator_destroy(const ITERATOR
*i
)
1303 ranges_destroy(i
->ranges
);
1307 * Create an empty iterator.
1309 static inline BOOL
iterator_empty(ITERATOR
* i
)
1311 ZeroMemory(i
, sizeof(*i
));
1312 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1317 * Create an iterator over a range.
1319 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1327 * Create an iterator over a bunch of ranges.
1328 * Please note that the iterator will take ownership of the ranges,
1329 * and will free them upon destruction.
1331 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1339 * Creates an iterator over the items which intersect frame.
1340 * Uses absolute coordinates rather than compensating for the current offset.
1342 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1344 RECT rcItem
, rcTemp
;
1346 /* in case we fail, we want to return an empty iterator */
1347 if (!iterator_empty(i
)) return FALSE
;
1349 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1351 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1355 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1357 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1358 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1359 i
->nSpecial
= infoPtr
->nFocusedItem
;
1361 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1362 /* to do better here, we need to have PosX, and PosY sorted */
1363 TRACE("building icon ranges:\n");
1364 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1366 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1367 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1368 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1369 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1370 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1371 ranges_additem(i
->ranges
, nItem
);
1375 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1379 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1380 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1382 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1383 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1384 if (range
.upper
<= range
.lower
) return TRUE
;
1385 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1386 TRACE(" report=%s\n", debugrange(&i
->range
));
1390 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1391 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1392 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1399 if (infoPtr
->nItemWidth
)
1401 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1402 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1406 nFirstCol
= max(frame
->left
, 0);
1407 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1410 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1412 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1413 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1415 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1417 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1418 TRACE("building list ranges:\n");
1419 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1421 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1422 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1423 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1424 TRACE(" list=%s\n", debugrange(&item_range
));
1425 ranges_add(i
->ranges
, item_range
);
1433 * Creates an iterator over the items which intersect lprc.
1435 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1440 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1442 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1443 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1445 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1449 * Creates an iterator over the items which intersect the visible region of hdc.
1451 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1453 POINT Origin
, Position
;
1454 RECT rcItem
, rcClip
;
1457 rgntype
= GetClipBox(hdc
, &rcClip
);
1458 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1459 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1460 if (rgntype
== SIMPLEREGION
) return TRUE
;
1462 /* first deal with the special item */
1463 if (i
->nSpecial
!= -1)
1465 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1466 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1469 /* if we can't deal with the region, we'll just go with the simple range */
1470 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1471 TRACE("building visible range:\n");
1472 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1474 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1475 if (!ranges_add(i
->ranges
, i
->range
))
1477 ranges_destroy(i
->ranges
);
1483 /* now delete the invisible items from the list */
1484 while(iterator_next(i
))
1486 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1487 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1488 rcItem
.top
= Position
.y
+ Origin
.y
;
1489 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1490 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1491 if (!RectVisible(hdc
, &rcItem
))
1492 ranges_delitem(i
->ranges
, i
->nItem
);
1494 /* the iterator should restart on the next iterator_next */
1500 /******** Misc helper functions ************************************/
1502 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1503 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1505 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1506 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1509 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1511 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1512 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1515 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1517 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1518 if(state
== 1 || state
== 2)
1522 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1523 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1524 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1528 /* this should be called after window style got updated,
1529 it used to reset view state to match current window style */
1530 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1532 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1535 infoPtr
->uView
= LV_VIEW_ICON
;
1538 infoPtr
->uView
= LV_VIEW_DETAILS
;
1541 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1544 infoPtr
->uView
= LV_VIEW_LIST
;
1548 /* computes next item id value */
1549 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1551 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1555 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1556 return lpID
->id
+ 1;
1561 /******** Internal API functions ************************************/
1563 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1565 static COLUMN_INFO mainItem
;
1567 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1568 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1570 /* update cached column rectangles */
1571 if (infoPtr
->colRectsDirty
)
1574 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1577 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1578 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1579 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1581 Ptr
->colRectsDirty
= FALSE
;
1584 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1587 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1589 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1592 if (infoPtr
->hwndHeader
) return 0;
1594 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1596 /* setup creation flags */
1597 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1598 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1600 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1603 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1604 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1605 if (!infoPtr
->hwndHeader
) return -1;
1607 /* set header unicode format */
1608 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1610 /* set header font */
1611 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1613 LISTVIEW_UpdateSize(infoPtr
);
1618 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1620 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1623 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1625 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1626 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1627 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1630 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1632 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1635 /* used to handle collapse main item column case */
1636 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1640 if (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
)
1642 DWORD dwOldBkColor
, dwOldTextColor
;
1644 dwOldBkColor
= SetBkColor(hdc
, RGB(255, 255, 255));
1645 dwOldTextColor
= SetBkColor(hdc
, RGB(0, 0, 0));
1646 Ret
= DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1647 SetBkColor(hdc
, dwOldBkColor
);
1648 SetBkColor(hdc
, dwOldTextColor
);
1653 /* Listview invalidation functions: use _only_ these functions to invalidate */
1655 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1657 return infoPtr
->bRedraw
;
1660 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1662 if(!is_redrawing(infoPtr
)) return;
1663 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1664 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1667 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1671 if(!is_redrawing(infoPtr
)) return;
1672 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1673 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1676 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1678 POINT Origin
, Position
;
1681 if(!is_redrawing(infoPtr
)) return;
1682 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1683 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1684 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1685 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1687 rcBox
.bottom
= infoPtr
->nItemHeight
;
1688 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1689 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1692 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1694 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1697 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1701 if(!is_redrawing(infoPtr
)) return;
1702 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1703 rcCol
.top
= infoPtr
->rcList
.top
;
1704 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1705 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1710 * Retrieves the number of items that can fit vertically in the client area.
1713 * [I] infoPtr : valid pointer to the listview structure
1716 * Number of items per row.
1718 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1720 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1722 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1727 * Retrieves the number of items that can fit horizontally in the client
1731 * [I] infoPtr : valid pointer to the listview structure
1734 * Number of items per column.
1736 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1738 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1740 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1744 /*************************************************************************
1745 * LISTVIEW_ProcessLetterKeys
1747 * Processes keyboard messages generated by pressing the letter keys
1749 * What this does is perform a case insensitive search from the
1750 * current position with the following quirks:
1751 * - If two chars or more are pressed in quick succession we search
1752 * for the corresponding string (e.g. 'abc').
1753 * - If there is a delay we wipe away the current search string and
1754 * restart with just that char.
1755 * - If the user keeps pressing the same character, whether slowly or
1756 * fast, so that the search string is entirely composed of this
1757 * character ('aaaaa' for instance), then we search for first item
1758 * that starting with that character.
1759 * - If the user types the above character in quick succession, then
1760 * we must also search for the corresponding string ('aaaaa'), and
1761 * go to that string if there is a match.
1764 * [I] hwnd : handle to the window
1765 * [I] charCode : the character code, the actual character
1766 * [I] keyData : key data
1774 * - The current implementation has a list of characters it will
1775 * accept and it ignores everything else. In particular it will
1776 * ignore accentuated characters which seems to match what
1777 * Windows does. But I'm not sure it makes sense to follow
1779 * - We don't sound a beep when the search fails.
1783 * TREEVIEW_ProcessLetterKeys
1785 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1787 WCHAR buffer
[MAX_PATH
];
1788 INT endidx
, startidx
;
1794 /* simple parameter checking */
1795 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1797 /* only allow the valid WM_CHARs through */
1798 if (!isalnumW(charCode
) &&
1799 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1800 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1801 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1802 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1803 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1804 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1805 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1806 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1807 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1810 /* update the search parameters */
1811 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1812 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1813 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1815 if (diff
>= 0 && diff
< KEY_DELAY
)
1817 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1818 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1820 if (infoPtr
->charCode
!= charCode
)
1821 infoPtr
->charCode
= charCode
= 0;
1825 infoPtr
->charCode
= charCode
;
1826 infoPtr
->szSearchParam
[0] = charCode
;
1827 infoPtr
->nSearchParamLength
= 1;
1830 /* and search from the current position */
1832 endidx
= infoPtr
->nItemCount
;
1834 /* should start from next after focused item, so next item that matches
1835 will be selected, if there isn't any and focused matches it will be selected
1836 on second search stage from beginning of the list */
1837 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1838 startidx
= infoPtr
->nFocusedItem
+ 1;
1842 /* let application handle this for virtual listview */
1843 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1847 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1848 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1849 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1850 nmlv
.iStart
= startidx
;
1852 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1854 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1860 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1863 /* start from first item if not found with >= startidx */
1864 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1870 for (i
= startidx
; i
< endidx
; i
++)
1873 item
.mask
= LVIF_TEXT
;
1876 item
.pszText
= buffer
;
1877 item
.cchTextMax
= MAX_PATH
;
1878 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1880 if (lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
) == 0)
1885 else if (nItem
== -1 && lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1) == 0)
1887 /* this would work but we must keep looking for a longer match */
1892 if ( nItem
!= -1 || /* found something */
1893 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1894 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1900 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1905 /*************************************************************************
1906 * LISTVIEW_UpdateHeaderSize [Internal]
1908 * Function to resize the header control
1911 * [I] hwnd : handle to a window
1912 * [I] nNewScrollPos : scroll pos to set
1917 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1922 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1924 if (!infoPtr
->hwndHeader
) return;
1926 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1927 point
[0].x
= winRect
.left
;
1928 point
[0].y
= winRect
.top
;
1929 point
[1].x
= winRect
.right
;
1930 point
[1].y
= winRect
.bottom
;
1932 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1933 point
[0].x
= -nNewScrollPos
;
1934 point
[1].x
+= nNewScrollPos
;
1936 SetWindowPos(infoPtr
->hwndHeader
,0,
1937 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1938 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1939 SWP_NOZORDER
| SWP_NOACTIVATE
);
1944 * Update the scrollbars. This functions should be called whenever
1945 * the content, size or view changes.
1948 * [I] infoPtr : valid pointer to the listview structure
1953 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
1955 SCROLLINFO horzInfo
, vertInfo
;
1958 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
1960 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
1961 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
1962 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1964 /* for now, we'll set info.nMax to the _count_, and adjust it later */
1965 if (infoPtr
->uView
== LV_VIEW_LIST
)
1967 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
1968 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
1970 /* scroll by at least one column per page */
1971 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
1972 horzInfo
.nPage
= infoPtr
->nItemWidth
;
1974 if (infoPtr
->nItemWidth
)
1975 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
1977 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1979 horzInfo
.nMax
= infoPtr
->nItemWidth
;
1981 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
1985 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
1988 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
1990 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
1995 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
1996 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
1998 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
1999 horzInfo
.nMax
= rcHeader
.right
;
2000 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2004 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2005 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2006 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2007 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2008 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2010 /* Setting the horizontal scroll can change the listview size
2011 * (and potentially everything else) so we need to recompute
2012 * everything again for the vertical scroll
2015 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2016 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2017 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2019 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2021 vertInfo
.nMax
= infoPtr
->nItemCount
;
2023 /* scroll by at least one page */
2024 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2025 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2027 if (infoPtr
->nItemHeight
> 0)
2028 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2030 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2034 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2037 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2038 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2039 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2040 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2041 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2043 /* Change of the range may have changed the scroll pos. If so move the content */
2044 if (dx
!= 0 || dy
!= 0)
2047 listRect
= infoPtr
->rcList
;
2048 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2049 SW_ERASE
| SW_INVALIDATE
);
2052 /* Update the Header Control */
2053 if (infoPtr
->hwndHeader
)
2055 horzInfo
.fMask
= SIF_POS
;
2056 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2057 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2064 * Shows/hides the focus rectangle.
2067 * [I] infoPtr : valid pointer to the listview structure
2068 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2073 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2077 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2079 if (infoPtr
->nFocusedItem
< 0) return;
2081 /* we need some gymnastics in ICON mode to handle large items */
2082 if (infoPtr
->uView
== LV_VIEW_ICON
)
2086 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2087 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2089 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2094 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2096 /* for some reason, owner draw should work only in report mode */
2097 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2102 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2103 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2105 item
.iItem
= infoPtr
->nFocusedItem
;
2107 item
.mask
= LVIF_PARAM
;
2108 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2110 ZeroMemory(&dis
, sizeof(dis
));
2111 dis
.CtlType
= ODT_LISTVIEW
;
2112 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2113 dis
.itemID
= item
.iItem
;
2114 dis
.itemAction
= ODA_FOCUS
;
2115 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2116 dis
.hwndItem
= infoPtr
->hwndSelf
;
2118 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2119 dis
.itemData
= item
.lParam
;
2121 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2123 SelectObject(hdc
, hOldFont
);
2127 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2130 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2134 * Invalidates all visible selected items.
2136 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2140 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2141 while(iterator_next(&i
))
2143 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2144 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2146 iterator_destroy(&i
);
2151 * DESCRIPTION: [INTERNAL]
2152 * Computes an item's (left,top) corner, relative to rcView.
2153 * That is, the position has NOT been made relative to the Origin.
2154 * This is deliberate, to avoid computing the Origin over, and
2155 * over again, when this function is called in a loop. Instead,
2156 * one can factor the computation of the Origin before the loop,
2157 * and offset the value returned by this function, on every iteration.
2160 * [I] infoPtr : valid pointer to the listview structure
2161 * [I] nItem : item number
2162 * [O] lpptOrig : item top, left corner
2167 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2169 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2171 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2173 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2174 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2176 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2178 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2179 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2180 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2182 else /* LV_VIEW_DETAILS */
2184 lpptPosition
->x
= REPORT_MARGINX
;
2185 /* item is always at zero indexed column */
2186 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2187 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2188 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2193 * DESCRIPTION: [INTERNAL]
2194 * Compute the rectangles of an item. This is to localize all
2195 * the computations in one place. If you are not interested in some
2196 * of these values, simply pass in a NULL -- the function is smart
2197 * enough to compute only what's necessary. The function computes
2198 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2199 * one, the BOX rectangle. This rectangle is very cheap to compute,
2200 * and is guaranteed to contain all the other rectangles. Computing
2201 * the ICON rect is also cheap, but all the others are potentially
2202 * expensive. This gives an easy and effective optimization when
2203 * searching (like point inclusion, or rectangle intersection):
2204 * first test against the BOX, and if TRUE, test against the desired
2206 * If the function does not have all the necessary information
2207 * to computed the requested rectangles, will crash with a
2208 * failed assertion. This is done so we catch all programming
2209 * errors, given that the function is called only from our code.
2211 * We have the following 'special' meanings for a few fields:
2212 * * If LVIS_FOCUSED is set, we assume the item has the focus
2213 * This is important in ICON mode, where it might get a larger
2214 * then usual rectangle
2216 * Please note that subitem support works only in REPORT mode.
2219 * [I] infoPtr : valid pointer to the listview structure
2220 * [I] lpLVItem : item to compute the measures for
2221 * [O] lprcBox : ptr to Box rectangle
2222 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2223 * [0] lprcSelectBox : ptr to select box rectangle
2224 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2225 * [O] lprcIcon : ptr to Icon rectangle
2226 * Same as LVM_GETITEMRECT with LVIR_ICON
2227 * [O] lprcStateIcon: ptr to State Icon rectangle
2228 * [O] lprcLabel : ptr to Label rectangle
2229 * Same as LVM_GETITEMRECT with LVIR_LABEL
2234 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2235 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2236 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2238 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2239 RECT Box
, SelectBox
, Icon
, Label
;
2240 COLUMN_INFO
*lpColumnInfo
= NULL
;
2241 SIZE labelSize
= { 0, 0 };
2243 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2245 /* Be smart and try to figure out the minimum we have to do */
2246 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2247 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2249 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2250 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2252 if (lprcSelectBox
) doSelectBox
= TRUE
;
2253 if (lprcLabel
) doLabel
= TRUE
;
2254 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2261 /************************************************************/
2262 /* compute the box rectangle (it should be cheap to do) */
2263 /************************************************************/
2264 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2265 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2267 if (lpLVItem
->iSubItem
)
2269 Box
= lpColumnInfo
->rcHeader
;
2274 Box
.right
= infoPtr
->nItemWidth
;
2277 Box
.bottom
= infoPtr
->nItemHeight
;
2279 /******************************************************************/
2280 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2281 /******************************************************************/
2284 LONG state_width
= 0;
2286 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2287 state_width
= infoPtr
->iconStateSize
.cx
;
2289 if (infoPtr
->uView
== LV_VIEW_ICON
)
2291 Icon
.left
= Box
.left
+ state_width
;
2292 if (infoPtr
->himlNormal
)
2293 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2294 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2295 Icon
.right
= Icon
.left
;
2296 Icon
.bottom
= Icon
.top
;
2297 if (infoPtr
->himlNormal
)
2299 Icon
.right
+= infoPtr
->iconSize
.cx
;
2300 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2303 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2305 Icon
.left
= Box
.left
+ state_width
;
2307 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2309 /* we need the indent in report mode */
2310 assert(lpLVItem
->mask
& LVIF_INDENT
);
2311 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2315 Icon
.right
= Icon
.left
;
2316 if (infoPtr
->himlSmall
&&
2317 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 || (lpColumnInfo
->fmt
& LVCFMT_IMAGE
) ||
2318 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2319 Icon
.right
+= infoPtr
->iconSize
.cx
;
2320 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2322 if(lprcIcon
) *lprcIcon
= Icon
;
2323 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2325 /* TODO: is this correct? */
2328 lprcStateIcon
->left
= Icon
.left
- state_width
;
2329 lprcStateIcon
->right
= Icon
.left
;
2330 lprcStateIcon
->top
= Icon
.top
;
2331 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2332 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2335 else Icon
.right
= 0;
2337 /************************************************************/
2338 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2339 /************************************************************/
2342 /* calculate how far to the right can the label stretch */
2343 Label
.right
= Box
.right
;
2344 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2346 if (lpLVItem
->iSubItem
== 0)
2348 /* we need a zero based rect here */
2349 Label
= lpColumnInfo
->rcHeader
;
2350 OffsetRect(&Label
, -Label
.left
, 0);
2354 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2356 labelSize
.cx
= infoPtr
->nItemWidth
;
2357 labelSize
.cy
= infoPtr
->nItemHeight
;
2361 /* we need the text in non owner draw mode */
2362 assert(lpLVItem
->mask
& LVIF_TEXT
);
2363 if (is_text(lpLVItem
->pszText
))
2365 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2366 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2367 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2371 /* compute rough rectangle where the label will go */
2372 SetRectEmpty(&rcText
);
2373 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2374 rcText
.bottom
= infoPtr
->nItemHeight
;
2375 if (infoPtr
->uView
== LV_VIEW_ICON
)
2376 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2378 /* now figure out the flags */
2379 if (infoPtr
->uView
== LV_VIEW_ICON
)
2380 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2382 uFormat
= LV_SL_DT_FLAGS
;
2384 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2386 if (rcText
.right
!= rcText
.left
)
2387 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2389 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2391 SelectObject(hdc
, hOldFont
);
2392 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2396 if (infoPtr
->uView
== LV_VIEW_ICON
)
2398 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2399 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2400 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2401 Label
.right
= Label
.left
+ labelSize
.cx
;
2402 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2403 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2405 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2406 labelSize
.cy
/= infoPtr
->ntmHeight
;
2407 labelSize
.cy
= max(labelSize
.cy
, 1);
2408 labelSize
.cy
*= infoPtr
->ntmHeight
;
2410 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2412 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2414 Label
.left
= Icon
.right
;
2415 Label
.top
= Box
.top
;
2416 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2417 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2418 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2420 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2422 Label
.left
= Icon
.right
;
2423 Label
.top
= Box
.top
;
2424 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2425 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2428 if (lprcLabel
) *lprcLabel
= Label
;
2429 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2432 /************************************************************/
2433 /* compute SELECT bounding box */
2434 /************************************************************/
2437 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2439 SelectBox
.left
= Icon
.left
;
2440 SelectBox
.top
= Box
.top
;
2441 SelectBox
.bottom
= Box
.bottom
;
2444 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2446 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2450 UnionRect(&SelectBox
, &Icon
, &Label
);
2452 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2453 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2456 /* Fix the Box if necessary */
2459 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2460 else *lprcBox
= Box
;
2462 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2466 * DESCRIPTION: [INTERNAL]
2469 * [I] infoPtr : valid pointer to the listview structure
2470 * [I] nItem : item number
2471 * [O] lprcBox : ptr to Box rectangle
2476 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2478 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2479 POINT Position
, Origin
;
2482 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2483 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2485 /* Be smart and try to figure out the minimum we have to do */
2487 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2488 lvItem
.mask
|= LVIF_TEXT
;
2489 lvItem
.iItem
= nItem
;
2490 lvItem
.iSubItem
= 0;
2491 lvItem
.pszText
= szDispText
;
2492 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2493 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2494 if (infoPtr
->uView
== LV_VIEW_ICON
)
2496 lvItem
.mask
|= LVIF_STATE
;
2497 lvItem
.stateMask
= LVIS_FOCUSED
;
2498 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2500 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2502 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2503 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2505 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2508 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2511 /* LISTVIEW_MapIdToIndex helper */
2512 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2514 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2515 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2517 if (id1
->id
== id2
->id
) return 0;
2519 return (id1
->id
< id2
->id
) ? -1 : 1;
2524 * Returns the item index for id specified.
2527 * [I] infoPtr : valid pointer to the listview structure
2528 * [I] iID : item id to get index for
2531 * Item index, or -1 on failure.
2533 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2538 TRACE("iID=%d\n", iID
);
2540 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2541 if (infoPtr
->nItemCount
== 0) return -1;
2544 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, &MapIdSearchCompare
, 0, DPAS_SORTED
);
2548 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2549 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2557 * Returns the item id for index given.
2560 * [I] infoPtr : valid pointer to the listview structure
2561 * [I] iItem : item index to get id for
2566 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2571 TRACE("iItem=%d\n", iItem
);
2573 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2574 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2576 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2577 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2579 return lpItem
->id
->id
;
2584 * Returns the current icon position, and advances it along the top.
2585 * The returned position is not offset by Origin.
2588 * [I] infoPtr : valid pointer to the listview structure
2589 * [O] lpPos : will get the current icon position
2594 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2596 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2598 *lpPos
= infoPtr
->currIconPos
;
2600 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2601 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2603 infoPtr
->currIconPos
.x
= 0;
2604 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2610 * Returns the current icon position, and advances it down the left edge.
2611 * The returned position is not offset by Origin.
2614 * [I] infoPtr : valid pointer to the listview structure
2615 * [O] lpPos : will get the current icon position
2620 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2622 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2624 *lpPos
= infoPtr
->currIconPos
;
2626 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2627 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2629 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2630 infoPtr
->currIconPos
.y
= 0;
2636 * Moves an icon to the specified position.
2637 * It takes care of invalidating the item, etc.
2640 * [I] infoPtr : valid pointer to the listview structure
2641 * [I] nItem : the item to move
2642 * [I] lpPos : the new icon position
2643 * [I] isNew : flags the item as being new
2649 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2655 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2656 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2658 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2659 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2662 /* Allocating a POINTER for every item is too resource intensive,
2663 * so we'll keep the (x,y) in different arrays */
2664 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2665 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2667 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2674 * Arranges listview items in icon display mode.
2677 * [I] infoPtr : valid pointer to the listview structure
2678 * [I] nAlignCode : alignment code
2684 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2686 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2690 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2692 TRACE("nAlignCode=%d\n", nAlignCode
);
2694 if (nAlignCode
== LVA_DEFAULT
)
2696 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2697 else nAlignCode
= LVA_ALIGNTOP
;
2702 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2703 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2704 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2705 default: return FALSE
;
2708 infoPtr
->bAutoarrange
= TRUE
;
2709 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2710 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2712 next_pos(infoPtr
, &pos
);
2713 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2721 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2722 * For LVS_REPORT always returns empty rectangle.
2725 * [I] infoPtr : valid pointer to the listview structure
2726 * [O] lprcView : bounding rectangle
2732 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2736 SetRectEmpty(lprcView
);
2738 switch (infoPtr
->uView
)
2741 case LV_VIEW_SMALLICON
:
2742 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2744 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2745 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2746 lprcView
->right
= max(lprcView
->right
, x
);
2747 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2749 if (infoPtr
->nItemCount
> 0)
2751 lprcView
->right
+= infoPtr
->nItemWidth
;
2752 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2757 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2758 x
= infoPtr
->nItemCount
/ y
;
2759 if (infoPtr
->nItemCount
% y
) x
++;
2760 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2761 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2768 * Retrieves the bounding rectangle of all the items.
2771 * [I] infoPtr : valid pointer to the listview structure
2772 * [O] lprcView : bounding rectangle
2778 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2782 TRACE("(lprcView=%p)\n", lprcView
);
2784 if (!lprcView
) return FALSE
;
2786 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2788 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2790 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2791 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2794 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2801 * Retrieves the subitem pointer associated with the subitem index.
2804 * [I] hdpaSubItems : DPA handle for a specific item
2805 * [I] nSubItem : index of subitem
2808 * SUCCESS : subitem pointer
2811 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2813 SUBITEM_INFO
*lpSubItem
;
2816 /* we should binary search here if need be */
2817 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2819 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2820 if (lpSubItem
->iSubItem
== nSubItem
)
2830 * Calculates the desired item width.
2833 * [I] infoPtr : valid pointer to the listview structure
2836 * The desired item width.
2838 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2842 TRACE("uView=%d\n", infoPtr
->uView
);
2844 if (infoPtr
->uView
== LV_VIEW_ICON
)
2845 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2846 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2848 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2853 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2854 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2856 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2857 nItemWidth
= rcHeader
.right
;
2860 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2862 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2866 lvItem
.mask
= LVIF_TEXT
;
2867 lvItem
.iSubItem
= 0;
2869 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2872 lvItem
.pszText
= szDispText
;
2873 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2874 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2875 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2879 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2880 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2882 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2890 * Calculates the desired item height.
2893 * [I] infoPtr : valid pointer to the listview structure
2896 * The desired item height.
2898 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2902 TRACE("uView=%d\n", infoPtr
->uView
);
2904 if (infoPtr
->uView
== LV_VIEW_ICON
)
2905 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2908 nItemHeight
= infoPtr
->ntmHeight
;
2909 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
2911 if (infoPtr
->himlState
)
2912 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2913 if (infoPtr
->himlSmall
)
2914 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2915 if (infoPtr
->himlState
|| infoPtr
->himlSmall
)
2916 nItemHeight
+= HEIGHT_PADDING
;
2917 if (infoPtr
->nMeasureItemHeight
> 0)
2918 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2921 return max(nItemHeight
, 1);
2926 * Updates the width, and height of an item.
2929 * [I] infoPtr : valid pointer to the listview structure
2934 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2936 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2937 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2943 * Retrieves and saves important text metrics info for the current
2947 * [I] infoPtr : valid pointer to the listview structure
2950 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2952 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2953 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2954 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2958 if (GetTextMetricsW(hdc
, &tm
))
2960 infoPtr
->ntmHeight
= tm
.tmHeight
;
2961 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
2964 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
2965 infoPtr
->nEllipsisWidth
= sz
.cx
;
2967 SelectObject(hdc
, hOldFont
);
2968 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2970 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
2975 * A compare function for ranges
2978 * [I] range1 : pointer to range 1;
2979 * [I] range2 : pointer to range 2;
2983 * > 0 : if range 1 > range 2
2984 * < 0 : if range 2 > range 1
2985 * = 0 : if range intersects range 2
2987 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
2991 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
2993 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
2998 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3003 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
3005 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *func
, int line
)
3010 TRACE("*** Checking %s:%d:%s ***\n", func
, line
, desc
);
3012 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3013 ranges_dump(ranges
);
3014 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3016 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3017 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3018 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3020 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3021 assert (prev
->upper
<= curr
->lower
);
3022 assert (curr
->lower
< curr
->upper
);
3026 TRACE("--- Done checking---\n");
3029 static RANGES
ranges_create(int count
)
3031 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3032 if (!ranges
) return NULL
;
3033 ranges
->hdpa
= DPA_Create(count
);
3034 if (ranges
->hdpa
) return ranges
;
3039 static void ranges_clear(RANGES ranges
)
3043 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3044 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3045 DPA_DeleteAllPtrs(ranges
->hdpa
);
3049 static void ranges_destroy(RANGES ranges
)
3051 if (!ranges
) return;
3052 ranges_clear(ranges
);
3053 DPA_Destroy(ranges
->hdpa
);
3057 static RANGES
ranges_clone(RANGES ranges
)
3062 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3064 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3066 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3067 if (!newrng
) goto fail
;
3068 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3069 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3074 TRACE ("clone failed\n");
3075 ranges_destroy(clone
);
3079 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3083 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3084 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3089 static void ranges_dump(RANGES ranges
)
3093 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3094 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3097 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3099 RANGE srchrng
= { nItem
, nItem
+ 1 };
3101 TRACE("(nItem=%d)\n", nItem
);
3102 ranges_check(ranges
, "before contain");
3103 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3106 static INT
ranges_itemcount(RANGES ranges
)
3110 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3112 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3113 count
+= sel
->upper
- sel
->lower
;
3119 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3121 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3124 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3125 if (index
== -1) return TRUE
;
3127 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3129 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3130 if (chkrng
->lower
>= nItem
)
3131 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3132 if (chkrng
->upper
> nItem
)
3133 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3138 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3143 TRACE("(%s)\n", debugrange(&range
));
3144 ranges_check(ranges
, "before add");
3146 /* try find overlapping regions first */
3147 srchrgn
.lower
= range
.lower
- 1;
3148 srchrgn
.upper
= range
.upper
+ 1;
3149 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3155 TRACE("Adding new range\n");
3157 /* create the brand new range to insert */
3158 newrgn
= Alloc(sizeof(RANGE
));
3159 if(!newrgn
) goto fail
;
3162 /* figure out where to insert it */
3163 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3164 TRACE("index=%d\n", index
);
3165 if (index
== -1) index
= 0;
3167 /* and get it over with */
3168 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3176 RANGE
*chkrgn
, *mrgrgn
;
3177 INT fromindex
, mergeindex
;
3179 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3180 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3182 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3183 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3185 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3187 /* merge now common ranges */
3189 srchrgn
.lower
= chkrgn
->lower
- 1;
3190 srchrgn
.upper
= chkrgn
->upper
+ 1;
3194 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3195 if (mergeindex
== -1) break;
3196 if (mergeindex
== index
)
3198 fromindex
= index
+ 1;
3202 TRACE("Merge with index %i\n", mergeindex
);
3204 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3205 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3206 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3208 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3209 if (mergeindex
< index
) index
--;
3213 ranges_check(ranges
, "after add");
3217 ranges_check(ranges
, "failed add");
3221 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3226 TRACE("(%s)\n", debugrange(&range
));
3227 ranges_check(ranges
, "before del");
3229 /* we don't use DPAS_SORTED here, since we need *
3230 * to find the first overlapping range */
3231 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3234 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3236 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3238 /* case 1: Same range */
3239 if ( (chkrgn
->upper
== range
.upper
) &&
3240 (chkrgn
->lower
== range
.lower
) )
3242 DPA_DeletePtr(ranges
->hdpa
, index
);
3246 /* case 2: engulf */
3247 else if ( (chkrgn
->upper
<= range
.upper
) &&
3248 (chkrgn
->lower
>= range
.lower
) )
3250 DPA_DeletePtr(ranges
->hdpa
, index
);
3253 /* case 3: overlap upper */
3254 else if ( (chkrgn
->upper
<= range
.upper
) &&
3255 (chkrgn
->lower
< range
.lower
) )
3257 chkrgn
->upper
= range
.lower
;
3259 /* case 4: overlap lower */
3260 else if ( (chkrgn
->upper
> range
.upper
) &&
3261 (chkrgn
->lower
>= range
.lower
) )
3263 chkrgn
->lower
= range
.upper
;
3266 /* case 5: fully internal */
3271 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3272 newrgn
->lower
= chkrgn
->lower
;
3273 newrgn
->upper
= range
.lower
;
3274 chkrgn
->lower
= range
.upper
;
3275 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3283 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3286 ranges_check(ranges
, "after del");
3290 ranges_check(ranges
, "failed del");
3296 * Removes all selection ranges
3299 * [I] infoPtr : valid pointer to the listview structure
3300 * [I] toSkip : item range to skip removing the selection
3306 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3315 lvItem
.stateMask
= LVIS_SELECTED
;
3317 /* need to clone the DPA because callbacks can change it */
3318 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3319 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3320 while(iterator_next(&i
))
3321 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3322 /* note that the iterator destructor will free the cloned range */
3323 iterator_destroy(&i
);
3328 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3332 if (!(toSkip
= ranges_create(1))) return FALSE
;
3333 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3334 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3335 ranges_destroy(toSkip
);
3339 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3341 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3346 * Retrieves the number of items that are marked as selected.
3349 * [I] infoPtr : valid pointer to the listview structure
3352 * Number of items selected.
3354 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3356 INT nSelectedCount
= 0;
3358 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3361 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3363 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3368 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3370 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3371 return nSelectedCount
;
3376 * Manages the item focus.
3379 * [I] infoPtr : valid pointer to the listview structure
3380 * [I] nItem : item index
3383 * TRUE : focused item changed
3384 * FALSE : focused item has NOT changed
3386 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3388 INT oldFocus
= infoPtr
->nFocusedItem
;
3391 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3393 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3394 lvItem
.stateMask
= LVIS_FOCUSED
;
3395 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3397 return oldFocus
!= infoPtr
->nFocusedItem
;
3400 /* Helper function for LISTVIEW_ShiftIndices *only* */
3401 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3403 if (nShiftItem
< nItem
) return nShiftItem
;
3405 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3407 if (direction
> 0) return nShiftItem
+ direction
;
3409 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3414 * Updates the various indices after an item has been inserted or deleted.
3417 * [I] infoPtr : valid pointer to the listview structure
3418 * [I] nItem : item index
3419 * [I] direction : Direction of shift, +1 or -1.
3424 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3429 /* temporarily disable change notification while shifting items */
3430 bOldChange
= infoPtr
->bDoChangeNotify
;
3431 infoPtr
->bDoChangeNotify
= FALSE
;
3433 TRACE("Shifting %iu, %i steps\n", nItem
, direction
);
3435 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3437 assert(abs(direction
) == 1);
3439 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3441 nNewFocus
= shift_item(infoPtr
, infoPtr
->nFocusedItem
, nItem
, direction
);
3442 if (nNewFocus
!= infoPtr
->nFocusedItem
)
3443 LISTVIEW_SetItemFocus(infoPtr
, nNewFocus
);
3445 /* But we are not supposed to modify nHotItem! */
3447 infoPtr
->bDoChangeNotify
= bOldChange
;
3453 * Adds a block of selections.
3456 * [I] infoPtr : valid pointer to the listview structure
3457 * [I] nItem : item index
3460 * Whether the window is still valid.
3462 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3464 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3465 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3466 HWND hwndSelf
= infoPtr
->hwndSelf
;
3467 NMLVODSTATECHANGE nmlv
;
3472 /* Temporarily disable change notification
3473 * If the control is LVS_OWNERDATA, we need to send
3474 * only one LVN_ODSTATECHANGED notification.
3475 * See MSDN documentation for LVN_ITEMCHANGED.
3477 bOldChange
= infoPtr
->bDoChangeNotify
;
3478 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3480 if (nFirst
== -1) nFirst
= nItem
;
3482 item
.state
= LVIS_SELECTED
;
3483 item
.stateMask
= LVIS_SELECTED
;
3485 for (i
= nFirst
; i
<= nLast
; i
++)
3486 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3488 ZeroMemory(&nmlv
, sizeof(nmlv
));
3489 nmlv
.iFrom
= nFirst
;
3492 nmlv
.uOldState
= item
.state
;
3494 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3495 if (!IsWindow(hwndSelf
))
3497 infoPtr
->bDoChangeNotify
= bOldChange
;
3504 * Sets a single group selection.
3507 * [I] infoPtr : valid pointer to the listview structure
3508 * [I] nItem : item index
3513 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3520 if (!(selection
= ranges_create(100))) return;
3522 item
.state
= LVIS_SELECTED
;
3523 item
.stateMask
= LVIS_SELECTED
;
3525 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3527 if (infoPtr
->nSelectionMark
== -1)
3529 infoPtr
->nSelectionMark
= nItem
;
3530 ranges_additem(selection
, nItem
);
3536 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3537 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3538 ranges_add(selection
, sel
);
3543 RECT rcItem
, rcSel
, rcSelMark
;
3546 rcItem
.left
= LVIR_BOUNDS
;
3547 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return;
3548 rcSelMark
.left
= LVIR_BOUNDS
;
3549 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) return;
3550 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3551 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3552 while(iterator_next(&i
))
3554 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3555 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3557 iterator_destroy(&i
);
3560 /* disable per item notifications on LVS_OWNERDATA style
3561 FIXME: single LVN_ODSTATECHANGED should be used */
3562 bOldChange
= infoPtr
->bDoChangeNotify
;
3563 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3565 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3568 iterator_rangesitems(&i
, selection
);
3569 while(iterator_next(&i
))
3570 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3571 /* this will also destroy the selection */
3572 iterator_destroy(&i
);
3574 infoPtr
->bDoChangeNotify
= bOldChange
;
3576 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3581 * Sets a single selection.
3584 * [I] infoPtr : valid pointer to the listview structure
3585 * [I] nItem : item index
3590 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3594 TRACE("nItem=%d\n", nItem
);
3596 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3598 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3599 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3600 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3602 infoPtr
->nSelectionMark
= nItem
;
3607 * Set selection(s) with keyboard.
3610 * [I] infoPtr : valid pointer to the listview structure
3611 * [I] nItem : item index
3612 * [I] space : VK_SPACE code sent
3615 * SUCCESS : TRUE (needs to be repainted)
3616 * FAILURE : FALSE (nothing has changed)
3618 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3620 /* FIXME: pass in the state */
3621 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3622 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3623 BOOL bResult
= FALSE
;
3625 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3626 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3630 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3631 LISTVIEW_SetSelection(infoPtr
, nItem
);
3635 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3639 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3640 lvItem
.stateMask
= LVIS_SELECTED
;
3643 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3644 if (lvItem
.state
& LVIS_SELECTED
)
3645 infoPtr
->nSelectionMark
= nItem
;
3647 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3650 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3653 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3657 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3659 LVHITTESTINFO lvHitTestInfo
;
3661 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3662 lvHitTestInfo
.pt
.x
= pt
.x
;
3663 lvHitTestInfo
.pt
.y
= pt
.y
;
3665 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3667 lpLVItem
->mask
= LVIF_PARAM
;
3668 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3669 lpLVItem
->iSubItem
= 0;
3671 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3674 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3676 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3677 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3678 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3683 * Called when the mouse is being actively tracked and has hovered for a specified
3687 * [I] infoPtr : valid pointer to the listview structure
3688 * [I] fwKeys : key indicator
3689 * [I] x,y : mouse position
3692 * 0 if the message was processed, non-zero if there was an error
3695 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3696 * over the item for a certain period of time.
3699 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3703 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3705 if (LISTVIEW_IsHotTracking(infoPtr
))
3713 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3714 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3716 SetFocus(infoPtr
->hwndSelf
);
3722 #define SCROLL_LEFT 0x1
3723 #define SCROLL_RIGHT 0x2
3724 #define SCROLL_UP 0x4
3725 #define SCROLL_DOWN 0x8
3729 * Utility routine to draw and highlight items within a marquee selection rectangle.
3732 * [I] infoPtr : valid pointer to the listview structure
3733 * [I] coords_orig : original co-ordinates of the cursor
3734 * [I] coords_offs : offsetted coordinates of the cursor
3735 * [I] offset : offset amount
3736 * [I] scroll : Bitmask of which directions we should scroll, if at all
3741 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3742 const POINT
*coords_offs
, const POINT
*offset
,
3745 BOOL controlDown
= FALSE
;
3750 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3752 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3753 rect
.right
= coords_offs
->x
;
3757 rect
.left
= coords_offs
->x
;
3758 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3761 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3763 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3764 rect
.bottom
= coords_offs
->y
;
3768 rect
.top
= coords_offs
->y
;
3769 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3772 /* Cancel out the old marquee rectangle and draw the new one */
3773 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3775 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3776 the cursor is further away */
3778 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3779 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3781 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3782 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3784 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3785 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3787 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3788 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3790 /* Invert the items in the old marquee rectangle */
3791 iterator_frameditems_absolute(&i
, infoPtr
, &infoPtr
->marqueeRect
);
3793 while (iterator_next(&i
))
3797 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3800 item
.state
= LVIS_SELECTED
;
3802 item
.stateMask
= LVIS_SELECTED
;
3804 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3808 iterator_destroy(&i
);
3810 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3812 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3813 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3815 /* Iterate over the items within our marquee rectangle */
3816 iterator_frameditems_absolute(&i
, infoPtr
, &infoPtr
->marqueeRect
);
3818 if (GetKeyState(VK_CONTROL
) & 0x8000)
3821 while (iterator_next(&i
))
3825 /* If CTRL is pressed, invert. If not, always select the item. */
3826 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
)))
3829 item
.state
= LVIS_SELECTED
;
3831 item
.stateMask
= LVIS_SELECTED
;
3833 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3837 iterator_destroy(&i
);
3838 LISTVIEW_InvalidateRect(infoPtr
, &rect
);
3843 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3844 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3847 * [I] hwnd : Handle to the listview
3848 * [I] uMsg : WM_TIMER (ignored)
3849 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3850 * [I] dwTimer : The elapsed time (ignored)
3855 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3857 LISTVIEW_INFO
*infoPtr
;
3858 SCROLLINFO scrollInfo
;
3864 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3869 /* Get the current cursor position and convert to client coordinates */
3870 GetCursorPos(&coords_orig
);
3871 ScreenToClient(hWnd
, &coords_orig
);
3873 /* Ensure coordinates are within client bounds */
3874 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3875 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3878 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3880 /* Offset coordinates by the appropriate amount */
3881 coords_offs
.x
-= offset
.x
;
3882 coords_offs
.y
-= offset
.y
;
3884 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3885 scrollInfo
.fMask
= SIF_ALL
;
3887 /* Work out in which directions we can scroll */
3888 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3890 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3891 scroll
|= SCROLL_UP
;
3893 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3894 scroll
|= SCROLL_DOWN
;
3897 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3899 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3900 scroll
|= SCROLL_LEFT
;
3902 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3903 scroll
|= SCROLL_RIGHT
;
3906 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3907 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3908 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3909 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3911 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3917 * Called whenever WM_MOUSEMOVE is received.
3920 * [I] infoPtr : valid pointer to the listview structure
3921 * [I] fwKeys : key indicator
3922 * [I] x,y : mouse position
3925 * 0 if the message is processed, non-zero if there was an error
3927 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3929 if (!(fwKeys
& MK_LBUTTON
))
3930 infoPtr
->bLButtonDown
= FALSE
;
3932 if (infoPtr
->bLButtonDown
)
3936 LVHITTESTINFO lvHitTestInfo
;
3937 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3938 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3940 if (infoPtr
->bMarqueeSelect
)
3950 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3952 /* Ensure coordinates are within client bounds */
3953 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
3954 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
3956 /* Offset coordinates by the appropriate amount */
3957 coords_offs
.x
-= offset
.x
;
3958 coords_offs
.y
-= offset
.y
;
3960 /* Enable the timer if we're going outside our bounds, in case the user doesn't
3961 move the mouse again */
3963 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
3964 (y
>= infoPtr
->rcList
.bottom
))
3966 if (!infoPtr
->bScrolling
)
3968 infoPtr
->bScrolling
= TRUE
;
3969 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
3974 infoPtr
->bScrolling
= FALSE
;
3975 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
3978 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
3982 rect
.left
= infoPtr
->ptClickPos
.x
- wDragWidth
;
3983 rect
.right
= infoPtr
->ptClickPos
.x
+ wDragWidth
;
3984 rect
.top
= infoPtr
->ptClickPos
.y
- wDragHeight
;
3985 rect
.bottom
= infoPtr
->ptClickPos
.y
+ wDragHeight
;
3990 lvHitTestInfo
.pt
= tmp
;
3991 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
3993 /* reset item marker */
3994 if (infoPtr
->nLButtonDownItem
!= lvHitTestInfo
.iItem
)
3995 infoPtr
->nLButtonDownItem
= -1;
3997 if (!PtInRect(&rect
, tmp
))
3999 /* this path covers the following:
4000 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4001 2. change focus with keys
4002 3. move mouse over item from step 1 selects it and moves focus on it */
4003 if (infoPtr
->nLButtonDownItem
!= -1 &&
4004 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4008 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4009 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4011 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4012 infoPtr
->nLButtonDownItem
= -1;
4015 if (!infoPtr
->bDragging
)
4017 lvHitTestInfo
.pt
= infoPtr
->ptClickPos
;
4018 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
4020 /* If the click is outside the range of an item, begin a
4021 highlight. If not, begin an item drag. */
4022 if (lvHitTestInfo
.iItem
== -1)
4026 /* If we're allowing multiple selections, send notification.
4027 If return value is non-zero, cancel. */
4028 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4030 /* Store the absolute coordinates of the click */
4032 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4034 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4035 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4037 /* Begin selection and capture mouse */
4038 infoPtr
->bMarqueeSelect
= TRUE
;
4039 SetCapture(infoPtr
->hwndSelf
);
4046 ZeroMemory(&nmlv
, sizeof(nmlv
));
4047 nmlv
.iItem
= lvHitTestInfo
.iItem
;
4048 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4050 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4051 infoPtr
->bDragging
= TRUE
;
4059 /* see if we are supposed to be tracking mouse hovering */
4060 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4061 TRACKMOUSEEVENT trackinfo
;
4063 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4064 trackinfo
.dwFlags
= TME_QUERY
;
4066 /* see if we are already tracking this hwnd */
4067 _TrackMouseEvent(&trackinfo
);
4069 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4070 trackinfo
.dwFlags
= TME_HOVER
;
4071 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4072 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4074 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4075 _TrackMouseEvent(&trackinfo
);
4084 * Tests whether the item is assignable to a list with style lStyle
4086 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4088 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4089 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4090 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4098 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
4101 * [I] infoPtr : valid pointer to the listview structure
4102 * [I] lpLVItem : valid pointer to new item attributes
4103 * [I] isNew : the item being set is being inserted
4104 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4105 * [O] bChanged : will be set to TRUE if the item really changed
4111 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4117 /* stateMask is ignored for LVM_INSERTITEM */
4118 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4122 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4124 if (lpLVItem
->mask
== 0) return TRUE
;
4126 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4128 /* a virtual listview only stores selection and focus */
4129 if (lpLVItem
->mask
& ~LVIF_STATE
)
4135 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4136 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4140 /* we need to get the lParam and state of the item */
4141 item
.iItem
= lpLVItem
->iItem
;
4142 item
.iSubItem
= lpLVItem
->iSubItem
;
4143 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4144 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4148 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4150 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4151 /* determine what fields will change */
4152 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4153 uChanged
|= LVIF_STATE
;
4155 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4156 uChanged
|= LVIF_IMAGE
;
4158 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4159 uChanged
|= LVIF_PARAM
;
4161 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4162 uChanged
|= LVIF_INDENT
;
4164 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4165 uChanged
|= LVIF_TEXT
;
4167 TRACE("uChanged=0x%x\n", uChanged
);
4168 if (!uChanged
) return TRUE
;
4171 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
4172 nmlv
.iItem
= lpLVItem
->iItem
;
4173 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4174 nmlv
.uOldState
= item
.state
;
4175 nmlv
.uChanged
= uChanged
;
4176 nmlv
.lParam
= item
.lParam
;
4178 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
4179 /* and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications */
4181 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4183 HWND hwndSelf
= infoPtr
->hwndSelf
;
4185 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4187 if (!IsWindow(hwndSelf
))
4191 /* copy information */
4192 if (lpLVItem
->mask
& LVIF_TEXT
)
4193 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4195 if (lpLVItem
->mask
& LVIF_IMAGE
)
4196 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4198 if (lpLVItem
->mask
& LVIF_PARAM
)
4199 lpItem
->lParam
= lpLVItem
->lParam
;
4201 if (lpLVItem
->mask
& LVIF_INDENT
)
4202 lpItem
->iIndent
= lpLVItem
->iIndent
;
4204 if (uChanged
& LVIF_STATE
)
4206 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4208 lpItem
->state
&= ~stateMask
;
4209 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4211 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4213 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4214 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4216 else if (stateMask
& LVIS_SELECTED
)
4218 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4220 /* if we are asked to change focus, and we manage it, do it */
4221 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4223 if (lpLVItem
->state
& LVIS_FOCUSED
)
4225 if (infoPtr
->nFocusedItem
!= -1)
4227 /* remove current focus */
4228 item
.mask
= LVIF_STATE
;
4230 item
.stateMask
= LVIS_FOCUSED
;
4232 /* recurse with redrawing an item */
4233 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4236 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4237 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4239 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4241 infoPtr
->nFocusedItem
= -1;
4246 /* if we're inserting the item, we're done */
4247 if (isNew
) return TRUE
;
4249 /* send LVN_ITEMCHANGED notification */
4250 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4251 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4258 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4261 * [I] infoPtr : valid pointer to the listview structure
4262 * [I] lpLVItem : valid pointer to new subitem attributes
4263 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4264 * [O] bChanged : will be set to TRUE if the item really changed
4270 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4273 SUBITEM_INFO
*lpSubItem
;
4275 /* we do not support subitems for virtual listviews */
4276 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4278 /* set subitem only if column is present */
4279 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4281 /* First do some sanity checks */
4282 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4283 particularly useful. We currently do not actually do anything with
4284 the flag on subitems.
4286 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
)) return FALSE
;
4287 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4289 /* get the subitem structure, and create it if not there */
4290 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4291 assert (hdpaSubItems
);
4293 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4296 SUBITEM_INFO
*tmpSubItem
;
4299 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4300 if (!lpSubItem
) return FALSE
;
4301 /* we could binary search here, if need be...*/
4302 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4304 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4305 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4307 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4312 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4313 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4317 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4319 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4323 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4325 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4334 * Sets item attributes.
4337 * [I] infoPtr : valid pointer to the listview structure
4338 * [I] lpLVItem : new item attributes
4339 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4345 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4347 HWND hwndSelf
= infoPtr
->hwndSelf
;
4348 LPWSTR pszText
= NULL
;
4349 BOOL bResult
, bChanged
= FALSE
;
4351 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4353 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4356 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4357 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4359 pszText
= lpLVItem
->pszText
;
4360 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4363 /* actually set the fields */
4364 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4366 if (lpLVItem
->iSubItem
)
4367 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4369 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4370 if (!IsWindow(hwndSelf
))
4373 /* redraw item, if necessary */
4374 if (bChanged
&& !infoPtr
->bIsDrawing
)
4376 /* this little optimization eliminates some nasty flicker */
4377 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4378 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4379 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4380 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4382 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4387 textfreeT(lpLVItem
->pszText
, isW
);
4388 lpLVItem
->pszText
= pszText
;
4396 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4399 * [I] infoPtr : valid pointer to the listview structure
4404 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4407 SCROLLINFO scrollInfo
;
4409 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4410 scrollInfo
.fMask
= SIF_POS
;
4412 if (infoPtr
->uView
== LV_VIEW_LIST
)
4414 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4415 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4417 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4419 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4420 nItem
= scrollInfo
.nPos
;
4424 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4425 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4428 TRACE("nItem=%d\n", nItem
);
4436 * Erases the background of the given rectangle
4439 * [I] infoPtr : valid pointer to the listview structure
4440 * [I] hdc : device context handle
4441 * [I] lprcBox : clipping rectangle
4447 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4449 if (!infoPtr
->hBkBrush
) return FALSE
;
4451 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4453 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4461 * [I] infoPtr : valid pointer to the listview structure
4462 * [I] hdc : device context handle
4463 * [I] nItem : item index
4464 * [I] nSubItem : subitem index
4465 * [I] pos : item position in client coordinates
4466 * [I] cdmode : custom draw mode
4472 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
4475 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4476 static WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4477 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4479 RECT rcSelect
, rcBox
, rcIcon
, rcLabel
, rcStateIcon
;
4480 NMLVCUSTOMDRAW nmlvcd
;
4485 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, wine_dbgstr_point(&pos
));
4487 /* get information needed for drawing the item */
4488 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
4489 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
;
4490 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4491 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
;
4492 lvItem
.iItem
= nItem
;
4493 lvItem
.iSubItem
= nSubItem
;
4496 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4497 lvItem
.pszText
= szDispText
;
4498 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4499 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4500 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4501 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
4502 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4504 /* now check if we need to update the focus rectangle */
4505 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4507 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4508 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4509 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4510 OffsetRect(&rcSelect
, pos
.x
, pos
.y
);
4511 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
4512 OffsetRect(&rcStateIcon
, pos
.x
, pos
.y
);
4513 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
4514 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4515 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4516 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4518 /* fill in the custom draw structure */
4519 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4521 hOldFont
= GetCurrentObject(hdc
, OBJ_FONT
);
4522 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
4523 if (cdmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4524 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4525 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4526 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
4527 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4528 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
4529 if (nSubItem
== 0 && cdsubitemmode
== CDRF_NOTIFYITEMDRAW
)
4531 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4532 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4534 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4535 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4536 else if ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) == FALSE
)
4537 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4539 /* in full row select, subitems, will just use main item's colors */
4540 if (nSubItem
&& infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4541 nmlvcd
.clrTextBk
= CLR_NONE
;
4543 /* FIXME: temporary hack */
4544 rcSelect
.left
= rcLabel
.left
;
4546 /* draw the selection background, if we're drawing the main item */
4549 /* in icon mode, the label rect is really what we want to draw the
4551 if (infoPtr
->uView
== LV_VIEW_ICON
)
4554 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4556 /* we have to update left focus bound too if item isn't in leftmost column
4557 and reduce right box bound */
4558 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4562 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4564 INT Originx
= pos
.x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4565 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4566 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4568 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4569 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4573 rcSelect
.right
= rcBox
.right
;
4576 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
4577 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4578 /* store new focus rectangle */
4579 if (infoPtr
->nFocusedItem
== nItem
) infoPtr
->rcFocus
= rcSelect
;
4583 if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && (nSubItem
== 0))
4585 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
4588 TRACE("uStateImage=%d\n", uStateImage
);
4589 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
,
4590 rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4595 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4596 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4600 TRACE("iImage=%d\n", lvItem
.iImage
);
4602 if (lvItem
.state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4603 style
= ILD_SELECTED
;
4607 ImageList_DrawEx(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
4608 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4609 lvItem
.state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4613 /* Don't bother painting item being edited */
4614 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
4616 /* figure out the text drawing flags */
4617 uFormat
= (infoPtr
->uView
== LV_VIEW_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4618 if (infoPtr
->uView
== LV_VIEW_ICON
)
4619 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4622 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4624 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
4625 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
4626 default: uFormat
|= DT_LEFT
;
4629 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
4631 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4632 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4634 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4636 /* for GRIDLINES reduce the bottom so the text formats correctly */
4637 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4640 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
4643 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4644 notify_postpaint(infoPtr
, &nmlvcd
);
4645 if (cdsubitemmode
& CDRF_NEWFONT
)
4646 SelectObject(hdc
, hOldFont
);
4652 * Draws listview items when in owner draw mode.
4655 * [I] infoPtr : valid pointer to the listview structure
4656 * [I] hdc : device context handle
4661 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4663 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4664 DWORD cditemmode
= CDRF_DODEFAULT
;
4665 NMLVCUSTOMDRAW nmlvcd
;
4666 POINT Origin
, Position
;
4672 ZeroMemory(&dis
, sizeof(dis
));
4674 /* Get scroll info once before loop */
4675 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4677 /* iterate through the invalidated rows */
4678 while(iterator_next(i
))
4680 item
.iItem
= i
->nItem
;
4682 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4683 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4684 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4686 dis
.CtlType
= ODT_LISTVIEW
;
4688 dis
.itemID
= item
.iItem
;
4689 dis
.itemAction
= ODA_DRAWENTIRE
;
4691 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4692 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4693 dis
.hwndItem
= infoPtr
->hwndSelf
;
4695 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4696 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4697 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4698 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4699 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4700 dis
.itemData
= item
.lParam
;
4702 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4705 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4706 * structure for the rest. of the paint cycle
4708 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4709 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4710 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4712 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4714 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4715 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4718 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4719 notify_postpaint(infoPtr
, &nmlvcd
);
4725 * Draws listview items when in report display mode.
4728 * [I] infoPtr : valid pointer to the listview structure
4729 * [I] hdc : device context handle
4730 * [I] cdmode : custom draw mode
4735 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4738 RECT rcClip
, rcItem
;
4739 POINT Origin
, Position
;
4746 /* figure out what to draw */
4747 rgntype
= GetClipBox(hdc
, &rcClip
);
4748 if (rgntype
== NULLREGION
) return;
4750 /* Get scroll info once before loop */
4751 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4753 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4755 /* narrow down the columns we need to paint */
4756 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4758 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4760 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4761 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4762 ranges_additem(colRanges
, index
);
4764 iterator_rangesitems(&j
, colRanges
);
4766 /* in full row select, we _have_ to draw the main item */
4767 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4770 /* iterate through the invalidated rows */
4771 while(iterator_next(i
))
4773 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4774 Position
.y
+= Origin
.y
;
4776 /* iterate through the invalidated columns */
4777 while(iterator_next(&j
))
4779 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4780 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4782 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4785 rcItem
.bottom
= infoPtr
->nItemHeight
;
4786 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4787 if (!RectVisible(hdc
, &rcItem
)) continue;
4790 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
4793 iterator_destroy(&j
);
4798 * Draws the gridlines if necessary when in report display mode.
4801 * [I] infoPtr : valid pointer to the listview structure
4802 * [I] hdc : device context handle
4807 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4813 RECT rcClip
, rcItem
= {0};
4821 /* figure out what to draw */
4822 rgntype
= GetClipBox(hdc
, &rcClip
);
4823 if (rgntype
== NULLREGION
) return;
4825 /* Get scroll info once before loop */
4826 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4828 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4830 /* narrow down the columns we need to paint */
4831 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4833 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4835 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4836 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4837 ranges_additem(colRanges
, index
);
4840 /* is right most vertical line visible? */
4841 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4843 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4844 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4845 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
4848 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
4850 hOldPen
= SelectObject ( hdc
, hPen
);
4852 /* draw the vertical lines for the columns */
4853 iterator_rangesitems(&j
, colRanges
);
4854 while(iterator_next(&j
))
4856 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4857 if (rcItem
.left
== 0) continue; /* skip leftmost column */
4858 rcItem
.left
+= Origin
.x
;
4859 rcItem
.right
+= Origin
.x
;
4860 rcItem
.top
= infoPtr
->rcList
.top
;
4861 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
4862 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
4863 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4864 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
4866 iterator_destroy(&j
);
4867 /* draw rightmost grid line if visible */
4870 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4871 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4872 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4874 rcItem
.right
+= Origin
.x
;
4876 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
4877 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
4880 /* draw the horizontial lines for the rows */
4881 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
4882 rcItem
.left
= infoPtr
->rcList
.left
;
4883 rcItem
.right
= infoPtr
->rcList
.right
;
4884 rcItem
.bottom
= rcItem
.top
= Origin
.y
- 1;
4885 MoveToEx(hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4886 LineTo(hdc
, rcItem
.right
, rcItem
.top
);
4887 for(y
=itemheight
-1+Origin
.y
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
4889 rcItem
.bottom
= rcItem
.top
= y
;
4890 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
4891 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4892 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
4895 SelectObject( hdc
, hOldPen
);
4896 DeleteObject( hPen
);
4902 * Draws listview items when in list display mode.
4905 * [I] infoPtr : valid pointer to the listview structure
4906 * [I] hdc : device context handle
4907 * [I] cdmode : custom draw mode
4912 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4914 POINT Origin
, Position
;
4916 /* Get scroll info once before loop */
4917 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4919 while(iterator_prev(i
))
4921 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4922 Position
.x
+= Origin
.x
;
4923 Position
.y
+= Origin
.y
;
4925 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
4932 * Draws listview items.
4935 * [I] infoPtr : valid pointer to the listview structure
4936 * [I] hdc : device context handle
4937 * [I] prcErase : rect to be erased before refresh (may be NULL)
4942 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
4944 COLORREF oldTextColor
= 0, oldBkColor
= 0, oldClrTextBk
, oldClrText
;
4945 NMLVCUSTOMDRAW nmlvcd
;
4952 HBITMAP hbmp
= NULL
;
4955 LISTVIEW_DUMP(infoPtr
);
4957 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4958 TRACE("double buffering\n");
4960 hdc
= CreateCompatibleDC(hdcOrig
);
4962 ERR("Failed to create DC for backbuffer\n");
4965 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
4966 infoPtr
->rcList
.bottom
);
4968 ERR("Failed to create bitmap for backbuffer\n");
4973 SelectObject(hdc
, hbmp
);
4974 SelectObject(hdc
, infoPtr
->hFont
);
4976 /* Save dc values we're gonna trash while drawing
4977 * FIXME: Should be done in LISTVIEW_DrawItem() */
4978 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4979 oldBkMode
= GetBkMode(hdc
);
4980 oldBkColor
= GetBkColor(hdc
);
4981 oldTextColor
= GetTextColor(hdc
);
4984 infoPtr
->bIsDrawing
= TRUE
;
4987 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
4988 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4989 /* If no erasing was done (usually because RedrawWindow was called
4990 * with RDW_INVALIDATE only) we need to copy the old contents into
4991 * the backbuffer before continuing. */
4992 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
4993 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
4994 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
4995 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
4998 /* FIXME: Shouldn't need to do this */
4999 oldClrTextBk
= infoPtr
->clrTextBk
;
5000 oldClrText
= infoPtr
->clrText
;
5002 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
5004 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5005 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5006 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5007 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5008 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
5010 /* Use these colors to draw the items */
5011 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
5012 infoPtr
->clrText
= nmlvcd
.clrText
;
5014 /* nothing to draw */
5015 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5017 /* figure out what we need to draw */
5018 iterator_visibleitems(&i
, infoPtr
, hdc
);
5019 range
= iterator_range(&i
);
5021 /* send cache hint notification */
5022 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5026 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5027 nmlv
.iFrom
= range
.lower
;
5028 nmlv
.iTo
= range
.upper
- 1;
5029 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5032 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5033 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5036 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5037 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5038 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5039 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5041 /* if we have a focus rect and it's visible, draw it */
5042 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5043 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5044 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5046 iterator_destroy(&i
);
5049 /* For LVS_EX_GRIDLINES go and draw lines */
5050 /* This includes the case where there were *no* items */
5051 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5052 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5054 /* Draw marquee rectangle if appropriate */
5055 if (infoPtr
->bMarqueeSelect
)
5057 SetBkColor(hdc
, RGB(255, 255, 255));
5058 SetTextColor(hdc
, RGB(0, 0, 0));
5059 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5062 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5063 notify_postpaint(infoPtr
, &nmlvcd
);
5065 infoPtr
->clrTextBk
= oldClrTextBk
;
5066 infoPtr
->clrText
= oldClrText
;
5069 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5070 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5071 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5072 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5077 SelectObject(hdc
, hOldFont
);
5078 SetBkMode(hdc
, oldBkMode
);
5079 SetBkColor(hdc
, oldBkColor
);
5080 SetTextColor(hdc
, oldTextColor
);
5083 infoPtr
->bIsDrawing
= FALSE
;
5089 * Calculates the approximate width and height of a given number of items.
5092 * [I] infoPtr : valid pointer to the listview structure
5093 * [I] nItemCount : number of items
5094 * [I] wWidth : width
5095 * [I] wHeight : height
5098 * Returns a DWORD. The width in the low word and the height in high word.
5100 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5101 WORD wWidth
, WORD wHeight
)
5103 DWORD dwViewRect
= 0;
5105 if (nItemCount
== -1)
5106 nItemCount
= infoPtr
->nItemCount
;
5108 if (infoPtr
->uView
== LV_VIEW_LIST
)
5110 INT nItemCountPerColumn
= 1;
5111 INT nColumnCount
= 0;
5113 if (wHeight
== 0xFFFF)
5115 /* use current height */
5116 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5119 if (wHeight
< infoPtr
->nItemHeight
)
5120 wHeight
= infoPtr
->nItemHeight
;
5124 if (infoPtr
->nItemHeight
> 0)
5126 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5127 if (nItemCountPerColumn
== 0)
5128 nItemCountPerColumn
= 1;
5130 if (nItemCount
% nItemCountPerColumn
!= 0)
5131 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5133 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5137 /* Microsoft padding magic */
5138 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5139 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5141 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5143 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5147 if (infoPtr
->nItemCount
> 0)
5149 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5150 wWidth
= rcBox
.right
- rcBox
.left
;
5151 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5155 /* use current height and width */
5156 if (wHeight
== 0xffff)
5157 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5158 if (wWidth
== 0xffff)
5159 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5162 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5164 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5170 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5171 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5173 if (wWidth
== 0xffff)
5174 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5176 if (wWidth
< nItemWidth
)
5177 wWidth
= nItemWidth
;
5179 cols
= wWidth
/ nItemWidth
;
5180 if (cols
> nItemCount
)
5187 rows
= nItemCount
/ cols
;
5188 if (nItemCount
% cols
)
5194 wHeight
= (nItemHeight
* rows
)+2;
5195 wWidth
= (nItemWidth
* cols
)+2;
5197 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5199 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5200 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5207 * Cancel edit label with saving item text.
5210 * [I] infoPtr : valid pointer to the listview structure
5213 * Always returns TRUE.
5215 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5217 if (infoPtr
->hwndEdit
)
5219 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5220 HWND edit
= infoPtr
->hwndEdit
;
5222 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5223 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5231 * Create a drag image list for the specified item.
5234 * [I] infoPtr : valid pointer to the listview structure
5235 * [I] iItem : index of item
5236 * [O] lppt : Upper-left corner of the image
5239 * Returns a handle to the image list if successful, NULL otherwise.
5241 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5247 HBITMAP hbmp
, hOldbmp
;
5248 HIMAGELIST dragList
= 0;
5249 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5251 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5254 rcItem
.left
= LVIR_BOUNDS
;
5255 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5258 lppt
->x
= rcItem
.left
;
5259 lppt
->y
= rcItem
.top
;
5261 size
.cx
= rcItem
.right
- rcItem
.left
;
5262 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5264 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5265 hdc
= CreateCompatibleDC(hdcOrig
);
5266 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5267 hOldbmp
= SelectObject(hdc
, hbmp
);
5269 rcItem
.left
= rcItem
.top
= 0;
5270 rcItem
.right
= size
.cx
;
5271 rcItem
.bottom
= size
.cy
;
5272 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5275 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
5277 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5278 SelectObject(hdc
, hOldbmp
);
5279 ImageList_Add(dragList
, hbmp
, 0);
5282 SelectObject(hdc
, hOldbmp
);
5286 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5288 TRACE("ret=%p\n", dragList
);
5296 * Removes all listview items and subitems.
5299 * [I] infoPtr : valid pointer to the listview structure
5305 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5308 HDPA hdpaSubItems
= NULL
;
5317 /* we do it directly, to avoid notifications */
5318 ranges_clear(infoPtr
->selectionRanges
);
5319 infoPtr
->nSelectionMark
= -1;
5320 infoPtr
->nFocusedItem
= -1;
5321 SetRectEmpty(&infoPtr
->rcFocus
);
5322 /* But we are supposed to leave nHotItem as is! */
5325 /* send LVN_DELETEALLITEMS notification */
5326 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
5328 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5330 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5332 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5334 /* send LVN_DELETEITEM notification, if not suppressed
5335 and if it is not a virtual listview */
5336 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
5337 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5338 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5339 /* free id struct */
5340 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5341 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5342 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5344 /* both item and subitem start with ITEMHDR header */
5345 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5347 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5348 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5351 DPA_Destroy(hdpaSubItems
);
5352 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5354 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5355 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5356 infoPtr
->nItemCount
--;
5361 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5362 LISTVIEW_UpdateScroll(infoPtr
);
5364 LISTVIEW_InvalidateList(infoPtr
);
5371 * Scrolls, and updates the columns, when a column is changing width.
5374 * [I] infoPtr : valid pointer to the listview structure
5375 * [I] nColumn : column to scroll
5376 * [I] dx : amount of scroll, in pixels
5381 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5383 COLUMN_INFO
*lpColumnInfo
;
5389 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5390 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5391 rcCol
= lpColumnInfo
->rcHeader
;
5392 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5393 rcCol
.left
= rcCol
.right
;
5395 /* adjust the other columns */
5396 hdi
.mask
= HDI_ORDER
;
5397 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5399 INT nOrder
= hdi
.iOrder
;
5400 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5402 hdi
.mask
= HDI_ORDER
;
5403 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5404 if (hdi
.iOrder
>= nOrder
) {
5405 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5406 lpColumnInfo
->rcHeader
.left
+= dx
;
5407 lpColumnInfo
->rcHeader
.right
+= dx
;
5412 /* do not update screen if not in report mode */
5413 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5415 /* Need to reset the item width when inserting a new column */
5416 infoPtr
->nItemWidth
+= dx
;
5418 LISTVIEW_UpdateScroll(infoPtr
);
5419 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5421 /* scroll to cover the deleted column, and invalidate for redraw */
5422 rcOld
= infoPtr
->rcList
;
5423 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5424 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5429 * Removes a column from the listview control.
5432 * [I] infoPtr : valid pointer to the listview structure
5433 * [I] nColumn : column index
5439 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5443 TRACE("nColumn=%d\n", nColumn
);
5445 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5446 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5448 /* While the MSDN specifically says that column zero should not be deleted,
5449 what actually happens is that the column itself is deleted but no items or subitems
5453 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5455 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5458 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5459 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5461 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5463 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5465 INT nItem
, nSubItem
, i
;
5467 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5469 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5472 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5474 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5475 if (lpSubItem
->iSubItem
== nColumn
)
5478 lpDelItem
= lpSubItem
;
5480 else if (lpSubItem
->iSubItem
> nColumn
)
5482 lpSubItem
->iSubItem
--;
5486 /* if we found our subitem, zapp it */
5490 if (is_text(lpDelItem
->hdr
.pszText
))
5491 Free(lpDelItem
->hdr
.pszText
);
5496 /* free dpa memory */
5497 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5502 /* update the other column info */
5503 LISTVIEW_UpdateItemSize(infoPtr
);
5504 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5505 LISTVIEW_InvalidateList(infoPtr
);
5507 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5514 * Invalidates the listview after an item's insertion or deletion.
5517 * [I] infoPtr : valid pointer to the listview structure
5518 * [I] nItem : item index
5519 * [I] dir : -1 if deleting, 1 if inserting
5524 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5526 INT nPerCol
, nItemCol
, nItemRow
;
5530 /* if we don't refresh, what's the point of scrolling? */
5531 if (!is_redrawing(infoPtr
)) return;
5533 assert (abs(dir
) == 1);
5535 /* arrange icons if autoarrange is on */
5536 if (is_autoarrange(infoPtr
))
5538 BOOL arrange
= TRUE
;
5539 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5540 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5541 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5544 /* scrollbars need updating */
5545 LISTVIEW_UpdateScroll(infoPtr
);
5547 /* figure out the item's position */
5548 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5549 nPerCol
= infoPtr
->nItemCount
+ 1;
5550 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5551 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5552 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5555 nItemCol
= nItem
/ nPerCol
;
5556 nItemRow
= nItem
% nPerCol
;
5557 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5559 /* move the items below up a slot */
5560 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5561 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5562 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5563 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5564 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5565 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5566 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5568 TRACE("Scrolling rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5569 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5570 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5573 /* report has only that column, so we're done */
5574 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5576 /* now for LISTs, we have to deal with the columns to the right */
5577 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5579 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5580 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5581 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5582 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5583 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5584 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5589 * Removes an item from the listview control.
5592 * [I] infoPtr : valid pointer to the listview structure
5593 * [I] nItem : item index
5599 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5602 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5604 TRACE("(nItem=%d)\n", nItem
);
5606 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5608 /* remove selection, and focus */
5610 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5611 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5613 /* send LVN_DELETEITEM notification. */
5614 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5616 /* we need to do this here, because we'll be deleting stuff */
5618 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5620 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5628 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5629 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5631 /* free id struct */
5632 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5633 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5634 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5636 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5638 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5639 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5642 DPA_Destroy(hdpaSubItems
);
5647 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5648 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5651 infoPtr
->nItemCount
--;
5652 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5654 /* now is the invalidation fun */
5656 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5663 * Callback implementation for editlabel control
5666 * [I] infoPtr : valid pointer to the listview structure
5667 * [I] storeText : store edit box text as item text
5668 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5674 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5676 HWND hwndSelf
= infoPtr
->hwndSelf
;
5677 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5678 NMLVDISPINFOW dispInfo
;
5679 INT editedItem
= infoPtr
->nEditLabelItem
;
5681 WCHAR
*pszText
= NULL
;
5686 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5690 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5692 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5693 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5698 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5700 infoPtr
->nEditLabelItem
= -1;
5701 infoPtr
->hwndEdit
= 0;
5703 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5704 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5705 dispInfo
.item
.iItem
= editedItem
;
5706 dispInfo
.item
.iSubItem
= 0;
5707 dispInfo
.item
.stateMask
= ~0;
5708 dispInfo
.item
.pszText
= szDispText
;
5709 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5710 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5717 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5720 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5721 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5722 textfreeT(tmp
, FALSE
);
5725 /* add the text from the edit in */
5726 dispInfo
.item
.mask
|= LVIF_TEXT
;
5727 dispInfo
.item
.pszText
= bSame
? NULL
: pszText
;
5728 dispInfo
.item
.cchTextMax
= bSame
? 0 : textlenT(pszText
, isW
);
5730 /* Do we need to update the Item Text */
5731 if (!notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
))
5736 if (!IsWindow(hwndSelf
))
5741 if (!pszText
) return TRUE
;
5748 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5750 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5751 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5752 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5754 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5760 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5761 dispInfo
.item
.mask
= LVIF_TEXT
;
5762 dispInfo
.item
.iItem
= editedItem
;
5763 dispInfo
.item
.iSubItem
= 0;
5764 dispInfo
.item
.pszText
= pszText
;
5765 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5766 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5776 * Subclassed edit control windproc function
5779 * [I] hwnd : the edit window handle
5780 * [I] uMsg : the message that is to be processed
5781 * [I] wParam : first message parameter
5782 * [I] lParam : second message parameter
5783 * [I] isW : TRUE if input is Unicode
5788 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5790 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5793 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5794 hwnd
, uMsg
, wParam
, lParam
, isW
);
5799 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5803 WNDPROC editProc
= infoPtr
->EditWndProc
;
5804 infoPtr
->EditWndProc
= 0;
5805 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5806 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5810 if (VK_ESCAPE
== (INT
)wParam
)
5815 else if (VK_RETURN
== (INT
)wParam
)
5819 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5823 if (infoPtr
->hwndEdit
)
5824 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5826 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
5832 * Subclassed edit control Unicode windproc function
5835 * [I] hwnd : the edit window handle
5836 * [I] uMsg : the message that is to be processed
5837 * [I] wParam : first message parameter
5838 * [I] lParam : second message parameter
5842 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5844 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
5849 * Subclassed edit control ANSI windproc function
5852 * [I] hwnd : the edit window handle
5853 * [I] uMsg : the message that is to be processed
5854 * [I] wParam : first message parameter
5855 * [I] lParam : second message parameter
5859 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5861 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
5866 * Creates a subclassed edit control
5869 * [I] infoPtr : valid pointer to the listview structure
5870 * [I] text : initial text for the edit
5871 * [I] style : the window style
5872 * [I] isW : TRUE if input is Unicode
5876 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
5878 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
5879 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
5882 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
5884 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
5886 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5888 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5890 if (!hedit
) return 0;
5892 infoPtr
->EditWndProc
= (WNDPROC
)
5893 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
5894 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
5896 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
5897 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
5904 * Begin in place editing of specified list view item
5907 * [I] infoPtr : valid pointer to the listview structure
5908 * [I] nItem : item index
5909 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
5915 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
5917 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
5918 HWND hwndSelf
= infoPtr
->hwndSelf
;
5919 NMLVDISPINFOW dispInfo
;
5920 HFONT hOldFont
= NULL
;
5926 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
5928 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
5930 /* remove existing edit box */
5931 if (infoPtr
->hwndEdit
)
5933 SetFocus(infoPtr
->hwndSelf
);
5934 infoPtr
->hwndEdit
= 0;
5937 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5939 infoPtr
->nEditLabelItem
= nItem
;
5941 LISTVIEW_SetSelection(infoPtr
, nItem
);
5942 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
5943 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5945 rect
.left
= LVIR_LABEL
;
5946 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
5948 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5949 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5950 dispInfo
.item
.iItem
= nItem
;
5951 dispInfo
.item
.iSubItem
= 0;
5952 dispInfo
.item
.stateMask
= ~0;
5953 dispInfo
.item
.pszText
= disptextW
;
5954 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5955 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
5957 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
5958 if (!infoPtr
->hwndEdit
) return 0;
5960 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
5962 if (!IsWindow(hwndSelf
))
5964 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
5965 infoPtr
->hwndEdit
= 0;
5969 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
5971 /* position and display edit box */
5972 hdc
= GetDC(infoPtr
->hwndSelf
);
5974 /* select the font to get appropriate metric dimensions */
5976 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5978 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
5979 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
5980 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
5982 /* get string length in pixels */
5983 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
5985 /* add extra spacing for the next character */
5986 GetTextMetricsW(hdc
, &tm
);
5987 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
5990 SelectObject(hdc
, hOldFont
);
5992 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
5994 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
5997 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
5998 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
5999 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6000 SetFocus(infoPtr
->hwndEdit
);
6001 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6002 return infoPtr
->hwndEdit
;
6008 * Ensures the specified item is visible, scrolling into view if necessary.
6011 * [I] infoPtr : valid pointer to the listview structure
6012 * [I] nItem : item index
6013 * [I] bPartial : partially or entirely visible
6019 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6021 INT nScrollPosHeight
= 0;
6022 INT nScrollPosWidth
= 0;
6023 INT nHorzAdjust
= 0;
6024 INT nVertAdjust
= 0;
6027 RECT rcItem
, rcTemp
;
6029 rcItem
.left
= LVIR_BOUNDS
;
6030 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6032 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6034 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6036 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6037 if (infoPtr
->uView
== LV_VIEW_LIST
)
6038 nScrollPosWidth
= infoPtr
->nItemWidth
;
6039 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6040 nScrollPosWidth
= 1;
6042 if (rcItem
.left
< infoPtr
->rcList
.left
)
6045 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6050 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6054 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6056 /* scroll up/down, but not in LVS_LIST mode */
6057 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6058 nScrollPosHeight
= infoPtr
->nItemHeight
;
6059 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6060 nScrollPosHeight
= 1;
6062 if (rcItem
.top
< infoPtr
->rcList
.top
)
6065 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6070 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6074 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6076 if (nScrollPosWidth
)
6078 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6079 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6080 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6083 if (nScrollPosHeight
)
6085 INT diff
= nVertDiff
/ nScrollPosHeight
;
6086 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6087 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6095 * Searches for an item with specific characteristics.
6098 * [I] hwnd : window handle
6099 * [I] nStart : base item index
6100 * [I] lpFindInfo : item information to look for
6103 * SUCCESS : index of item
6106 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6107 const LVFINDINFOW
*lpFindInfo
)
6109 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6110 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6111 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6112 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6113 POINT Position
, Destination
;
6116 /* Search in virtual listviews should be done by application, not by
6117 listview control, so we just send LVN_ODFINDITEMW and return the result */
6118 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6122 nmlv
.iStart
= nStart
;
6123 nmlv
.lvfi
= *lpFindInfo
;
6124 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6127 if (!lpFindInfo
|| nItem
< 0) return -1;
6130 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6131 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6133 lvItem
.mask
|= LVIF_TEXT
;
6134 lvItem
.pszText
= szDispText
;
6135 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6138 if (lpFindInfo
->flags
& LVFI_WRAP
)
6141 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6142 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6147 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6148 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6149 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6150 switch(lpFindInfo
->vkDirection
)
6152 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6153 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6154 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6155 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6156 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6157 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6158 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6160 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6161 Destination
.x
= rcArea
.right
;
6162 Destination
.y
= rcArea
.bottom
;
6164 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6168 else Destination
.x
= Destination
.y
= 0;
6170 /* if LVFI_PARAM is specified, all other flags are ignored */
6171 if (lpFindInfo
->flags
& LVFI_PARAM
)
6173 lvItem
.mask
|= LVIF_PARAM
;
6175 lvItem
.mask
&= ~LVIF_TEXT
;
6179 for (; nItem
< nLast
; nItem
++)
6181 lvItem
.iItem
= nItem
;
6182 lvItem
.iSubItem
= 0;
6183 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6185 if (lvItem
.mask
& LVIF_PARAM
)
6187 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6193 if (lvItem
.mask
& LVIF_TEXT
)
6195 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6197 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6198 if (!p
|| p
!= lvItem
.pszText
) continue;
6202 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6206 if (!bNearest
) return nItem
;
6208 /* This is very inefficient. To do a good job here,
6209 * we need a sorted array of (x,y) item positions */
6210 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6212 /* compute the distance^2 to the destination */
6213 xdist
= Destination
.x
- Position
.x
;
6214 ydist
= Destination
.y
- Position
.y
;
6215 dist
= xdist
* xdist
+ ydist
* ydist
;
6217 /* remember the distance, and item if it's closer */
6221 nNearestItem
= nItem
;
6228 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6233 return nNearestItem
;
6238 * Searches for an item with specific characteristics.
6241 * [I] hwnd : window handle
6242 * [I] nStart : base item index
6243 * [I] lpFindInfo : item information to look for
6246 * SUCCESS : index of item
6249 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6250 const LVFINDINFOA
*lpFindInfo
)
6252 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6253 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6258 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6259 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6260 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6261 textfreeT(strW
, FALSE
);
6267 * Retrieves column attributes.
6270 * [I] infoPtr : valid pointer to the listview structure
6271 * [I] nColumn : column index
6272 * [IO] lpColumn : column information
6273 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6274 * otherwise it is in fact a LPLVCOLUMNA
6280 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6282 COLUMN_INFO
*lpColumnInfo
;
6285 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6286 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6288 /* initialize memory */
6289 ZeroMemory(&hdi
, sizeof(hdi
));
6291 if (lpColumn
->mask
& LVCF_TEXT
)
6293 hdi
.mask
|= HDI_TEXT
;
6294 hdi
.pszText
= lpColumn
->pszText
;
6295 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6298 if (lpColumn
->mask
& LVCF_IMAGE
)
6299 hdi
.mask
|= HDI_IMAGE
;
6301 if (lpColumn
->mask
& LVCF_ORDER
)
6302 hdi
.mask
|= HDI_ORDER
;
6304 if (lpColumn
->mask
& LVCF_SUBITEM
)
6305 hdi
.mask
|= HDI_LPARAM
;
6307 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6309 if (lpColumn
->mask
& LVCF_FMT
)
6310 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6312 if (lpColumn
->mask
& LVCF_WIDTH
)
6313 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6315 if (lpColumn
->mask
& LVCF_IMAGE
)
6316 lpColumn
->iImage
= hdi
.iImage
;
6318 if (lpColumn
->mask
& LVCF_ORDER
)
6319 lpColumn
->iOrder
= hdi
.iOrder
;
6321 if (lpColumn
->mask
& LVCF_SUBITEM
)
6322 lpColumn
->iSubItem
= hdi
.lParam
;
6324 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6325 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6331 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6333 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
6338 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6343 * Retrieves the column width.
6346 * [I] infoPtr : valid pointer to the listview structure
6347 * [I] int : column index
6350 * SUCCESS : column width
6353 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6355 INT nColumnWidth
= 0;
6358 TRACE("nColumn=%d\n", nColumn
);
6360 /* we have a 'column' in LIST and REPORT mode only */
6361 switch(infoPtr
->uView
)
6364 nColumnWidth
= infoPtr
->nItemWidth
;
6366 case LV_VIEW_DETAILS
:
6367 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6368 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6369 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6371 * TODO: should we do the same in LVM_GETCOLUMN?
6373 hdItem
.mask
= HDI_WIDTH
;
6374 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6376 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6379 nColumnWidth
= hdItem
.cxy
;
6383 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6384 return nColumnWidth
;
6389 * In list or report display mode, retrieves the number of items that can fit
6390 * vertically in the visible area. In icon or small icon display mode,
6391 * retrieves the total number of visible items.
6394 * [I] infoPtr : valid pointer to the listview structure
6397 * Number of fully visible items.
6399 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6401 switch (infoPtr
->uView
)
6404 case LV_VIEW_SMALLICON
:
6405 return infoPtr
->nItemCount
;
6406 case LV_VIEW_DETAILS
:
6407 return LISTVIEW_GetCountPerColumn(infoPtr
);
6409 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6417 * Retrieves an image list handle.
6420 * [I] infoPtr : valid pointer to the listview structure
6421 * [I] nImageList : image list identifier
6424 * SUCCESS : image list handle
6427 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6431 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6432 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6433 case LVSIL_STATE
: return infoPtr
->himlState
;
6434 case LVSIL_GROUPHEADER
:
6435 FIXME("LVSIL_GROUPHEADER not supported\n");
6438 WARN("got unknown imagelist index - %d\n", nImageList
);
6443 /* LISTVIEW_GetISearchString */
6447 * Retrieves item attributes.
6450 * [I] hwnd : window handle
6451 * [IO] lpLVItem : item info
6452 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6453 * if FALSE, then lpLVItem is a LPLVITEMA.
6456 * This is the internal 'GetItem' interface -- it tries to
6457 * be smart and avoid text copies, if possible, by modifying
6458 * lpLVItem->pszText to point to the text string. Please note
6459 * that this is not always possible (e.g. OWNERDATA), so on
6460 * entry you *must* supply valid values for pszText, and cchTextMax.
6461 * The only difference to the documented interface is that upon
6462 * return, you should use *only* the lpLVItem->pszText, rather than
6463 * the buffer pointer you provided on input. Most code already does
6464 * that, so it's not a problem.
6465 * For the two cases when the text must be copied (that is,
6466 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6472 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6474 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6475 NMLVDISPINFOW dispInfo
;
6481 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6483 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6486 if (lpLVItem
->mask
== 0) return TRUE
;
6487 TRACE("mask=%x\n", lpLVItem
->mask
);
6489 /* make a local copy */
6490 isubitem
= lpLVItem
->iSubItem
;
6492 /* a quick optimization if all we're asked is the focus state
6493 * these queries are worth optimising since they are common,
6494 * and can be answered in constant time, without the heavy accesses */
6495 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6496 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6498 lpLVItem
->state
= 0;
6499 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6500 lpLVItem
->state
|= LVIS_FOCUSED
;
6504 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6506 /* if the app stores all the data, handle it separately */
6507 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6509 dispInfo
.item
.state
= 0;
6511 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6512 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6513 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6515 UINT mask
= lpLVItem
->mask
;
6517 /* NOTE: copy only fields which we _know_ are initialized, some apps
6518 * depend on the uninitialized fields being 0 */
6519 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6520 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6521 dispInfo
.item
.iSubItem
= isubitem
;
6522 if (lpLVItem
->mask
& LVIF_TEXT
)
6524 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6526 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6529 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6530 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6533 if (lpLVItem
->mask
& LVIF_STATE
)
6534 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6535 /* could be zeroed on LVIF_NORECOMPUTE case */
6536 if (dispInfo
.item
.mask
)
6538 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6539 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6540 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6542 /* full size structure expected - _WIN32IE >= 0x560 */
6543 *lpLVItem
= dispInfo
.item
;
6545 else if (lpLVItem
->mask
& LVIF_INDENT
)
6547 /* indent member expected - _WIN32IE >= 0x300 */
6548 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6552 /* minimal structure expected */
6553 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6555 lpLVItem
->mask
= mask
;
6556 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6560 /* make sure lParam is zeroed out */
6561 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6563 /* callback marked pointer required here */
6564 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6565 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6567 /* we store only a little state, so if we're not asked, we're done */
6568 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6570 /* if focus is handled by us, report it */
6571 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6573 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6574 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6575 lpLVItem
->state
|= LVIS_FOCUSED
;
6578 /* and do the same for selection, if we handle it */
6579 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6581 lpLVItem
->state
&= ~LVIS_SELECTED
;
6582 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6583 lpLVItem
->state
|= LVIS_SELECTED
;
6589 /* find the item and subitem structures before we proceed */
6590 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6591 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6596 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6597 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6600 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6605 pItemHdr
= &lpItem
->hdr
;
6607 /* Do we need to query the state from the app? */
6608 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6610 dispInfo
.item
.mask
|= LVIF_STATE
;
6611 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6614 /* Do we need to enquire about the image? */
6615 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6616 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6618 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6619 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6622 /* Only items support indentation */
6623 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6626 dispInfo
.item
.mask
|= LVIF_INDENT
;
6627 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6630 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6631 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6632 !is_text(pItemHdr
->pszText
))
6634 dispInfo
.item
.mask
|= LVIF_TEXT
;
6635 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6636 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6637 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6638 *dispInfo
.item
.pszText
= '\0';
6641 /* If we don't have all the requested info, query the application */
6642 if (dispInfo
.item
.mask
)
6644 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6645 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6646 dispInfo
.item
.lParam
= lpItem
->lParam
;
6647 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6648 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6651 /* we should not store values for subitems */
6652 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6654 /* Now, handle the iImage field */
6655 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6657 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6658 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6659 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6661 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6663 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6664 lpLVItem
->iImage
= pItemHdr
->iImage
;
6666 lpLVItem
->iImage
= 0;
6669 /* The pszText field */
6670 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6672 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6673 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6675 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6677 else if (lpLVItem
->mask
& LVIF_TEXT
)
6679 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6680 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6681 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6684 /* Next is the lParam field */
6685 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6687 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6688 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6689 lpItem
->lParam
= dispInfo
.item
.lParam
;
6691 else if (lpLVItem
->mask
& LVIF_PARAM
)
6692 lpLVItem
->lParam
= lpItem
->lParam
;
6694 /* if this is a subitem, we're done */
6695 if (isubitem
) return TRUE
;
6697 /* ... the state field (this one is different due to uCallbackmask) */
6698 if (lpLVItem
->mask
& LVIF_STATE
)
6700 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6701 if (dispInfo
.item
.mask
& LVIF_STATE
)
6703 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6704 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6706 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6708 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6709 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6710 lpLVItem
->state
|= LVIS_FOCUSED
;
6712 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6714 lpLVItem
->state
&= ~LVIS_SELECTED
;
6715 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6716 lpLVItem
->state
|= LVIS_SELECTED
;
6720 /* and last, but not least, the indent field */
6721 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6723 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6724 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6725 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6727 else if (lpLVItem
->mask
& LVIF_INDENT
)
6729 lpLVItem
->iIndent
= lpItem
->iIndent
;
6737 * Retrieves item attributes.
6740 * [I] hwnd : window handle
6741 * [IO] lpLVItem : item info
6742 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6743 * if FALSE, then lpLVItem is a LPLVITEMA.
6746 * This is the external 'GetItem' interface -- it properly copies
6747 * the text in the provided buffer.
6753 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6758 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6761 pszText
= lpLVItem
->pszText
;
6762 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6763 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6765 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6766 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6768 pszText
= LPSTR_TEXTCALLBACKW
;
6770 lpLVItem
->pszText
= pszText
;
6778 * Retrieves the position (upper-left) of the listview control item.
6779 * Note that for LVS_ICON style, the upper-left is that of the icon
6780 * and not the bounding box.
6783 * [I] infoPtr : valid pointer to the listview structure
6784 * [I] nItem : item index
6785 * [O] lpptPosition : coordinate information
6791 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6795 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6797 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6799 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6800 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6802 if (infoPtr
->uView
== LV_VIEW_ICON
)
6804 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6805 lpptPosition
->y
+= ICON_TOP_PADDING
;
6807 lpptPosition
->x
+= Origin
.x
;
6808 lpptPosition
->y
+= Origin
.y
;
6810 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6817 * Retrieves the bounding rectangle for a listview control item.
6820 * [I] infoPtr : valid pointer to the listview structure
6821 * [I] nItem : item index
6822 * [IO] lprc : bounding rectangle coordinates
6823 * lprc->left specifies the portion of the item for which the bounding
6824 * rectangle will be retrieved.
6826 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6827 * including the icon and label.
6830 * * Experiment shows that native control returns:
6831 * * width = min (48, length of text line)
6832 * * .left = position.x - (width - iconsize.cx)/2
6833 * * .right = .left + width
6834 * * height = #lines of text * ntmHeight + icon height + 8
6835 * * .top = position.y - 2
6836 * * .bottom = .top + height
6837 * * separation between items .y = itemSpacing.cy - height
6838 * * .x = itemSpacing.cx - width
6839 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6842 * * Experiment shows that native control returns:
6843 * * width = iconSize.cx + 16
6844 * * .left = position.x - (width - iconsize.cx)/2
6845 * * .right = .left + width
6846 * * height = iconSize.cy + 4
6847 * * .top = position.y - 2
6848 * * .bottom = .top + height
6849 * * separation between items .y = itemSpacing.cy - height
6850 * * .x = itemSpacing.cx - width
6851 * LVIR_LABEL Returns the bounding rectangle of the item text.
6854 * * Experiment shows that native control returns:
6855 * * width = text length
6856 * * .left = position.x - width/2
6857 * * .right = .left + width
6858 * * height = ntmH * linecount + 2
6859 * * .top = position.y + iconSize.cy + 6
6860 * * .bottom = .top + height
6861 * * separation between items .y = itemSpacing.cy - height
6862 * * .x = itemSpacing.cx - width
6863 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6864 * rectangles, but excludes columns in report view.
6871 * Note that the bounding rectangle of the label in the LVS_ICON view depends
6872 * upon whether the window has the focus currently and on whether the item
6873 * is the one with the focus. Ensure that the control's record of which
6874 * item has the focus agrees with the items' records.
6876 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6878 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6879 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
6880 POINT Position
, Origin
;
6884 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
6886 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6888 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6889 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6891 /* Be smart and try to figure out the minimum we have to do */
6892 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
6893 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
6894 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
6895 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
6896 oversizedBox
= TRUE
;
6898 /* get what we need from the item before hand, so we make
6899 * only one request. This can speed up things, if data
6900 * is stored on the app side */
6902 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6903 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
6904 lvItem
.iItem
= nItem
;
6905 lvItem
.iSubItem
= 0;
6906 lvItem
.pszText
= szDispText
;
6907 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6908 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6909 /* we got the state already up, simulate it here, to avoid a reget */
6910 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
6912 lvItem
.mask
|= LVIF_STATE
;
6913 lvItem
.stateMask
= LVIS_FOCUSED
;
6914 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
6917 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
6918 lprc
->left
= LVIR_BOUNDS
;
6924 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
6928 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
6932 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
6935 case LVIR_SELECTBOUNDS
:
6936 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
6940 WARN("Unknown value: %d\n", lprc
->left
);
6944 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6946 if (mode
!= LVIR_BOUNDS
)
6947 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
6948 Position
.y
+ Origin
.y
);
6950 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
6953 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
6955 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
6962 * Retrieves the spacing between listview control items.
6965 * [I] infoPtr : valid pointer to the listview structure
6966 * [IO] lprc : rectangle to receive the output
6967 * on input, lprc->top = nSubItem
6968 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
6970 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
6971 * not only those of the first column.
6972 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
6978 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6980 POINT Position
, Origin
;
6984 if (!lprc
) return FALSE
;
6986 nColumn
= lprc
->top
;
6988 TRACE("(nItem=%d, nSubItem=%d, type=%d)\n", nItem
, lprc
->top
, lprc
->left
);
6989 /* On WinNT, a subitem of '0' calls LISTVIEW_GetItemRect */
6991 return LISTVIEW_GetItemRect(infoPtr
, nItem
, lprc
);
6993 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
6995 /* special case for header items */
6998 if (lprc
->left
!= LVIR_BOUNDS
)
7000 FIXME("Only LVIR_BOUNDS is implemented for header, got %d\n", lprc
->left
);
7004 if (infoPtr
->hwndHeader
)
7005 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)lprc
);
7008 memset(lprc
, 0, sizeof(RECT
));
7013 if (!LISTVIEW_GetItemPosition(infoPtr
, nItem
, &Position
)) return FALSE
;
7014 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7016 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
7019 lvItem
.iItem
= nItem
;
7020 lvItem
.iSubItem
= nColumn
;
7025 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7030 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7034 ERR("Unknown bounds=%d\n", lprc
->left
);
7038 OffsetRect(lprc
, Origin
.x
, Position
.y
);
7039 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7046 * Retrieves the spacing between listview control items.
7049 * [I] infoPtr : valid pointer to the listview structure
7050 * [I] bSmall : flag for small or large icon
7053 * Horizontal + vertical spacing
7055 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7061 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7065 if (infoPtr
->uView
== LV_VIEW_ICON
)
7066 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7068 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7075 * Retrieves the state of a listview control item.
7078 * [I] infoPtr : valid pointer to the listview structure
7079 * [I] nItem : item index
7080 * [I] uMask : state mask
7083 * State specified by the mask.
7085 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7089 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7091 lvItem
.iItem
= nItem
;
7092 lvItem
.iSubItem
= 0;
7093 lvItem
.mask
= LVIF_STATE
;
7094 lvItem
.stateMask
= uMask
;
7095 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7097 return lvItem
.state
& uMask
;
7102 * Retrieves the text of a listview control item or subitem.
7105 * [I] hwnd : window handle
7106 * [I] nItem : item index
7107 * [IO] lpLVItem : item information
7108 * [I] isW : TRUE if lpLVItem is Unicode
7111 * SUCCESS : string length
7114 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7116 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7118 lpLVItem
->mask
= LVIF_TEXT
;
7119 lpLVItem
->iItem
= nItem
;
7120 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7122 return textlenT(lpLVItem
->pszText
, isW
);
7127 * Searches for an item based on properties + relationships.
7130 * [I] infoPtr : valid pointer to the listview structure
7131 * [I] nItem : item index
7132 * [I] uFlags : relationship flag
7135 * SUCCESS : item index
7138 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7141 LVFINDINFOW lvFindInfo
;
7142 INT nCountPerColumn
;
7146 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7147 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7149 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7151 if (uFlags
& LVNI_CUT
)
7154 if (uFlags
& LVNI_DROPHILITED
)
7155 uMask
|= LVIS_DROPHILITED
;
7157 if (uFlags
& LVNI_FOCUSED
)
7158 uMask
|= LVIS_FOCUSED
;
7160 if (uFlags
& LVNI_SELECTED
)
7161 uMask
|= LVIS_SELECTED
;
7163 /* if we're asked for the focused item, that's only one,
7164 * so it's worth optimizing */
7165 if (uFlags
& LVNI_FOCUSED
)
7167 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7168 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7171 if (uFlags
& LVNI_ABOVE
)
7173 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7178 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7184 /* Special case for autoarrange - move 'til the top of a list */
7185 if (is_autoarrange(infoPtr
))
7187 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7188 while (nItem
- nCountPerRow
>= 0)
7190 nItem
-= nCountPerRow
;
7191 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7196 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7197 lvFindInfo
.vkDirection
= VK_UP
;
7198 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7199 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7201 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7206 else if (uFlags
& LVNI_BELOW
)
7208 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7210 while (nItem
< infoPtr
->nItemCount
)
7213 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7219 /* Special case for autoarrange - move 'til the bottom of a list */
7220 if (is_autoarrange(infoPtr
))
7222 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7223 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7225 nItem
+= nCountPerRow
;
7226 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7231 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7232 lvFindInfo
.vkDirection
= VK_DOWN
;
7233 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7234 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7236 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7241 else if (uFlags
& LVNI_TOLEFT
)
7243 if (infoPtr
->uView
== LV_VIEW_LIST
)
7245 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7246 while (nItem
- nCountPerColumn
>= 0)
7248 nItem
-= nCountPerColumn
;
7249 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7253 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7255 /* Special case for autoarrange - move 'til the beginning of a row */
7256 if (is_autoarrange(infoPtr
))
7258 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7259 while (nItem
% nCountPerRow
> 0)
7262 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7267 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7268 lvFindInfo
.vkDirection
= VK_LEFT
;
7269 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7270 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7272 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7277 else if (uFlags
& LVNI_TORIGHT
)
7279 if (infoPtr
->uView
== LV_VIEW_LIST
)
7281 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7282 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7284 nItem
+= nCountPerColumn
;
7285 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7289 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7291 /* Special case for autoarrange - move 'til the end of a row */
7292 if (is_autoarrange(infoPtr
))
7294 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7295 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7298 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7303 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7304 lvFindInfo
.vkDirection
= VK_RIGHT
;
7305 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7306 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7308 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7317 /* search by index */
7318 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7320 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7328 /* LISTVIEW_GetNumberOfWorkAreas */
7332 * Retrieves the origin coordinates when in icon or small icon display mode.
7335 * [I] infoPtr : valid pointer to the listview structure
7336 * [O] lpptOrigin : coordinate information
7341 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7343 INT nHorzPos
= 0, nVertPos
= 0;
7344 SCROLLINFO scrollInfo
;
7346 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7347 scrollInfo
.fMask
= SIF_POS
;
7349 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7350 nHorzPos
= scrollInfo
.nPos
;
7351 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7352 nVertPos
= scrollInfo
.nPos
;
7354 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7356 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7357 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7358 if (infoPtr
->uView
== LV_VIEW_LIST
)
7359 nHorzPos
*= infoPtr
->nItemWidth
;
7360 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7361 nVertPos
*= infoPtr
->nItemHeight
;
7363 lpptOrigin
->x
-= nHorzPos
;
7364 lpptOrigin
->y
-= nVertPos
;
7366 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7371 * Retrieves the width of a string.
7374 * [I] hwnd : window handle
7375 * [I] lpszText : text string to process
7376 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7379 * SUCCESS : string width (in pixels)
7382 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7387 if (is_text(lpszText
))
7389 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7390 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7391 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7394 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7396 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7397 SelectObject(hdc
, hOldFont
);
7398 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7400 return stringSize
.cx
;
7405 * Determines which listview item is located at the specified position.
7408 * [I] infoPtr : valid pointer to the listview structure
7409 * [IO] lpht : hit test information
7410 * [I] subitem : fill out iSubItem.
7411 * [I] select : return the index only if the hit selects the item
7414 * (mm 20001022): We must not allow iSubItem to be touched, for
7415 * an app might pass only a structure with space up to iItem!
7416 * (MS Office 97 does that for instance in the file open dialog)
7419 * SUCCESS : item index
7422 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7424 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7425 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7426 POINT Origin
, Position
, opt
;
7431 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7435 if (subitem
) lpht
->iSubItem
= 0;
7437 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7439 /* set whole list relation flags */
7440 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7442 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7443 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7444 lpht
->flags
|= LVHT_TOLEFT
;
7446 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7447 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7451 if (infoPtr
->rcList
.bottom
< opt
.y
)
7452 lpht
->flags
|= LVHT_BELOW
;
7456 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7457 lpht
->flags
|= LVHT_TOLEFT
;
7458 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7459 lpht
->flags
|= LVHT_TORIGHT
;
7461 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7462 lpht
->flags
|= LVHT_ABOVE
;
7463 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7464 lpht
->flags
|= LVHT_BELOW
;
7467 /* even if item is invalid try to find subitem */
7468 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7473 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7475 lpht
->iSubItem
= -1;
7476 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7478 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7480 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7486 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7488 /* if we're outside horizontal columns bounds there's nothing to test further */
7489 if (lpht
->iSubItem
== -1)
7492 lpht
->flags
= LVHT_NOWHERE
;
7497 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7498 if (lpht
->flags
) return -1;
7500 lpht
->flags
|= LVHT_NOWHERE
;
7502 /* first deal with the large items */
7503 rcSearch
.left
= lpht
->pt
.x
;
7504 rcSearch
.top
= lpht
->pt
.y
;
7505 rcSearch
.right
= rcSearch
.left
+ 1;
7506 rcSearch
.bottom
= rcSearch
.top
+ 1;
7508 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7509 iterator_next(&i
); /* go to first item in the sequence */
7511 iterator_destroy(&i
);
7513 TRACE("lpht->iItem=%d\n", iItem
);
7514 if (iItem
== -1) return -1;
7516 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7517 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7518 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7519 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7520 lvItem
.iItem
= iItem
;
7521 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7522 lvItem
.pszText
= szDispText
;
7523 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7524 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7525 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7527 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7528 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7529 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7531 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7532 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7534 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7536 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7539 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7540 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7544 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7545 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7547 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7548 if (!PtInRect(&rcBounds
, opt
)) return -1;
7550 if (PtInRect(&rcIcon
, opt
))
7551 lpht
->flags
|= LVHT_ONITEMICON
;
7552 else if (PtInRect(&rcLabel
, opt
))
7553 lpht
->flags
|= LVHT_ONITEMLABEL
;
7554 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7555 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7556 /* special case for LVS_EX_FULLROWSELECT */
7557 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
7558 !(lpht
->flags
& LVHT_ONITEM
))
7560 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7562 if (lpht
->flags
& LVHT_ONITEM
)
7563 lpht
->flags
&= ~LVHT_NOWHERE
;
7564 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7566 if (select
&& !(infoPtr
->uView
== LV_VIEW_DETAILS
&&
7567 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
7568 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
7570 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7572 /* get main item bounds */
7573 lvItem
.iSubItem
= 0;
7574 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7575 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7576 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7578 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7580 return lpht
->iItem
= iItem
;
7585 * Inserts a new item in the listview control.
7588 * [I] infoPtr : valid pointer to the listview structure
7589 * [I] lpLVItem : item information
7590 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7593 * SUCCESS : new item index
7596 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7603 BOOL is_sorted
, has_changed
;
7605 HWND hwndSelf
= infoPtr
->hwndSelf
;
7607 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7609 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7611 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7612 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7614 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7616 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7618 /* insert item in listview control data structure */
7619 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7620 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7622 /* link with id struct */
7623 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7625 lpID
->item
= hdpaSubItems
;
7626 lpID
->id
= get_next_itemid(infoPtr
);
7627 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7629 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7630 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7632 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7634 /* calculate new item index */
7641 while (i
< infoPtr
->nItemCount
)
7643 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7644 item_s
= DPA_GetPtr(hItem
, 0);
7646 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7647 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7649 if (cmpv
>= 0) break;
7655 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7657 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7658 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7659 if (nItem
== -1) goto fail
;
7660 infoPtr
->nItemCount
++;
7662 /* shift indices first so they don't get tangled */
7663 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7665 /* set the item attributes */
7666 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7668 /* full size structure expected - _WIN32IE >= 0x560 */
7671 else if (lpLVItem
->mask
& LVIF_INDENT
)
7673 /* indent member expected - _WIN32IE >= 0x300 */
7674 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7678 /* minimal structure expected */
7679 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7682 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7684 item
.mask
|= LVIF_STATE
;
7685 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7686 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7687 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7689 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7691 /* make room for the position, if we are in the right mode */
7692 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7694 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7696 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7698 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7703 /* send LVN_INSERTITEM notification */
7704 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
7706 nmlv
.lParam
= lpItem
->lParam
;
7707 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7708 if (!IsWindow(hwndSelf
))
7711 /* align items (set position of each item) */
7712 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7716 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7717 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7719 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7721 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7724 /* now is the invalidation fun */
7725 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7729 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7730 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7731 infoPtr
->nItemCount
--;
7733 DPA_DeletePtr(hdpaSubItems
, 0);
7734 DPA_Destroy (hdpaSubItems
);
7741 * Checks item visibility.
7744 * [I] infoPtr : valid pointer to the listview structure
7745 * [I] nFirst : item index to check for
7748 * Item visible : TRUE
7749 * Item invisible or failure : FALSE
7751 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7753 POINT Origin
, Position
;
7758 TRACE("nItem=%d\n", nItem
);
7760 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7762 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7763 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7764 rcItem
.left
= Position
.x
+ Origin
.x
;
7765 rcItem
.top
= Position
.y
+ Origin
.y
;
7766 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7767 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7769 hdc
= GetDC(infoPtr
->hwndSelf
);
7770 if (!hdc
) return FALSE
;
7771 ret
= RectVisible(hdc
, &rcItem
);
7772 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7779 * Redraws a range of items.
7782 * [I] infoPtr : valid pointer to the listview structure
7783 * [I] nFirst : first item
7784 * [I] nLast : last item
7790 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7794 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7795 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7798 for (i
= nFirst
; i
<= nLast
; i
++)
7799 LISTVIEW_InvalidateItem(infoPtr
, i
);
7806 * Scroll the content of a listview.
7809 * [I] infoPtr : valid pointer to the listview structure
7810 * [I] dx : horizontal scroll amount in pixels
7811 * [I] dy : vertical scroll amount in pixels
7818 * If the control is in report view (LV_VIEW_DETAILS) the control can
7819 * be scrolled only in line increments. "dy" will be rounded to the
7820 * nearest number of pixels that are a whole line. Ex: if line height
7821 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7822 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7824 * For: (per experimentation with native control and CSpy ListView)
7825 * LV_VIEW_ICON dy=1 = 1 pixel (vertical only)
7827 * LV_VIEW_SMALLICON dy=1 = 1 pixel (vertical only)
7829 * LV_VIEW_LIST dx=1 = 1 column (horizontal only)
7830 * but will only scroll 1 column per message
7831 * no matter what the value.
7832 * dy must be 0 or FALSE returned.
7833 * LV_VIEW_DETAILS dx=1 = 1 pixel
7837 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7839 switch(infoPtr
->uView
) {
7840 case LV_VIEW_DETAILS
:
7841 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7842 dy
/= infoPtr
->nItemHeight
;
7845 if (dy
!= 0) return FALSE
;
7852 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
7853 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
7860 * Sets the background color.
7863 * [I] infoPtr : valid pointer to the listview structure
7864 * [I] clrBk : background color
7870 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrBk
)
7872 TRACE("(clrBk=%x)\n", clrBk
);
7874 if(infoPtr
->clrBk
!= clrBk
) {
7875 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7876 infoPtr
->clrBk
= clrBk
;
7877 if (clrBk
== CLR_NONE
)
7878 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
7881 infoPtr
->hBkBrush
= CreateSolidBrush(clrBk
);
7882 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
7884 LISTVIEW_InvalidateList(infoPtr
);
7890 /* LISTVIEW_SetBkImage */
7892 /*** Helper for {Insert,Set}ColumnT *only* */
7893 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
7894 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7896 if (lpColumn
->mask
& LVCF_FMT
)
7898 /* format member is valid */
7899 lphdi
->mask
|= HDI_FORMAT
;
7901 /* set text alignment (leftmost column must be left-aligned) */
7902 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7903 lphdi
->fmt
|= HDF_LEFT
;
7904 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
7905 lphdi
->fmt
|= HDF_RIGHT
;
7906 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
7907 lphdi
->fmt
|= HDF_CENTER
;
7909 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
7910 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
7912 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
7914 lphdi
->fmt
|= HDF_IMAGE
;
7915 lphdi
->iImage
= I_IMAGECALLBACK
;
7918 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
7919 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
7922 if (lpColumn
->mask
& LVCF_WIDTH
)
7924 lphdi
->mask
|= HDI_WIDTH
;
7925 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
7927 /* make it fill the remainder of the controls width */
7931 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
7933 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
7934 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
7937 /* retrieve the layout of the header */
7938 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
7939 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
7941 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
7944 lphdi
->cxy
= lpColumn
->cx
;
7947 if (lpColumn
->mask
& LVCF_TEXT
)
7949 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
7950 lphdi
->fmt
|= HDF_STRING
;
7951 lphdi
->pszText
= lpColumn
->pszText
;
7952 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
7955 if (lpColumn
->mask
& LVCF_IMAGE
)
7957 lphdi
->mask
|= HDI_IMAGE
;
7958 lphdi
->iImage
= lpColumn
->iImage
;
7961 if (lpColumn
->mask
& LVCF_ORDER
)
7963 lphdi
->mask
|= HDI_ORDER
;
7964 lphdi
->iOrder
= lpColumn
->iOrder
;
7971 * Inserts a new column.
7974 * [I] infoPtr : valid pointer to the listview structure
7975 * [I] nColumn : column index
7976 * [I] lpColumn : column information
7977 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
7980 * SUCCESS : new column index
7983 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
7984 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7986 COLUMN_INFO
*lpColumnInfo
;
7990 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
7992 if (!lpColumn
|| nColumn
< 0) return -1;
7993 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
7995 ZeroMemory(&hdi
, sizeof(HDITEMW
));
7996 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
7999 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8000 * (can be seen in SPY) otherwise column never gets added.
8002 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8003 hdi
.mask
|= HDI_WIDTH
;
8008 * when the iSubItem is available Windows copies it to the header lParam. It seems
8009 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8011 if (lpColumn
->mask
& LVCF_SUBITEM
)
8013 hdi
.mask
|= HDI_LPARAM
;
8014 hdi
.lParam
= lpColumn
->iSubItem
;
8017 /* create header if not present */
8018 LISTVIEW_CreateHeader(infoPtr
);
8019 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8020 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8022 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8025 /* insert item in header control */
8026 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8027 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8028 nColumn
, (LPARAM
)&hdi
);
8029 if (nNewColumn
== -1) return -1;
8030 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8032 /* create our own column info */
8033 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8034 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8036 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8037 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8038 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8041 /* now we have to actually adjust the data */
8042 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8044 SUBITEM_INFO
*lpSubItem
;
8050 item
.iSubItem
= nNewColumn
;
8051 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8052 item
.iImage
= I_IMAGECALLBACK
;
8053 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8055 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8057 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8058 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8060 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8061 if (lpSubItem
->iSubItem
>= nNewColumn
)
8062 lpSubItem
->iSubItem
++;
8065 /* add new subitem for each item */
8067 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8071 /* make space for the new column */
8072 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8073 LISTVIEW_UpdateItemSize(infoPtr
);
8078 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8081 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8089 * Sets the attributes of a header item.
8092 * [I] infoPtr : valid pointer to the listview structure
8093 * [I] nColumn : column index
8094 * [I] lpColumn : column attributes
8095 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8101 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8102 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8104 HDITEMW hdi
, hdiget
;
8107 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8109 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8111 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8112 if (lpColumn
->mask
& LVCF_FMT
)
8114 hdi
.mask
|= HDI_FORMAT
;
8115 hdiget
.mask
= HDI_FORMAT
;
8116 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8117 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8119 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8121 /* set header item attributes */
8122 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8123 if (!bResult
) return FALSE
;
8125 if (lpColumn
->mask
& LVCF_FMT
)
8127 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8128 INT oldFmt
= lpColumnInfo
->fmt
;
8130 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8131 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8133 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8137 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8138 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8145 * Sets the column order array
8148 * [I] infoPtr : valid pointer to the listview structure
8149 * [I] iCount : number of elements in column order array
8150 * [I] lpiArray : pointer to column order array
8156 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8158 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
8160 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
8162 infoPtr
->colRectsDirty
= TRUE
;
8164 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8169 * Sets the width of a column
8172 * [I] infoPtr : valid pointer to the listview structure
8173 * [I] nColumn : column index
8174 * [I] cx : column width
8180 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8182 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8186 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
8188 /* set column width only if in report or list mode */
8189 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8191 /* take care of invalid cx values */
8192 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
8193 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
8195 /* resize all columns if in LV_VIEW_LIST mode */
8196 if(infoPtr
->uView
== LV_VIEW_LIST
)
8198 infoPtr
->nItemWidth
= cx
;
8199 LISTVIEW_InvalidateList(infoPtr
);
8203 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8205 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8210 lvItem
.mask
= LVIF_TEXT
;
8212 lvItem
.iSubItem
= nColumn
;
8213 lvItem
.pszText
= szDispText
;
8214 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8215 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8217 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8218 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8219 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8221 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8222 max_cx
+= infoPtr
->iconSize
.cx
;
8223 max_cx
+= TRAILING_LABEL_PADDING
;
8226 /* autosize based on listview items width */
8227 if(cx
== LVSCW_AUTOSIZE
)
8229 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8231 /* if iCol is the last column make it fill the remainder of the controls width */
8232 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8237 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8238 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8240 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8244 /* Despite what the MS docs say, if this is not the last
8245 column, then MS resizes the column to the width of the
8246 largest text string in the column, including headers
8247 and items. This is different from LVSCW_AUTOSIZE in that
8248 LVSCW_AUTOSIZE ignores the header string length. */
8251 /* retrieve header text */
8252 hdi
.mask
= HDI_TEXT
;
8253 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8254 hdi
.pszText
= szDispText
;
8255 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8257 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8258 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8261 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8262 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8263 /* FIXME: Take into account the header image, if one is present */
8264 SelectObject(hdc
, old_font
);
8265 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8267 cx
= max (cx
, max_cx
);
8271 if (cx
< 0) return FALSE
;
8273 /* call header to update the column change */
8274 hdi
.mask
= HDI_WIDTH
;
8275 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8276 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8277 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8281 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8284 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8287 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8289 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8290 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8293 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8294 ILC_COLOR
| ILC_MASK
, 2, 2);
8295 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8296 hdc
= CreateCompatibleDC(hdc_wnd
);
8297 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8298 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8299 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8301 rc
.left
= rc
.top
= 0;
8302 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8303 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8305 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8306 FillRect(hdc
, &rc
, hbr_white
);
8307 InflateRect(&rc
, -2, -2);
8308 FillRect(hdc
, &rc
, hbr_black
);
8310 SelectObject(hdc
, hbm_im
);
8311 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8312 SelectObject(hdc
, hbm_orig
);
8313 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8315 SelectObject(hdc
, hbm_im
);
8316 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8317 SelectObject(hdc
, hbm_orig
);
8318 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8320 DeleteObject(hbm_mask
);
8321 DeleteObject(hbm_im
);
8329 * Sets the extended listview style.
8332 * [I] infoPtr : valid pointer to the listview structure
8334 * [I] dwStyle : style
8337 * SUCCESS : previous style
8340 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD dwMask
, DWORD dwExStyle
)
8342 DWORD dwOldExStyle
= infoPtr
->dwLvExStyle
;
8346 infoPtr
->dwLvExStyle
= (dwOldExStyle
& ~dwMask
) | (dwExStyle
& dwMask
);
8348 infoPtr
->dwLvExStyle
= dwExStyle
;
8350 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_CHECKBOXES
)
8352 HIMAGELIST himl
= 0;
8353 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8356 item
.mask
= LVIF_STATE
;
8357 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8358 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8359 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8361 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8362 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8363 ImageList_Destroy(infoPtr
->himlState
);
8365 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8366 /* checkbox list replaces prevous custom list or... */
8367 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8368 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8369 /* ...previous was checkbox list */
8370 (dwOldExStyle
& LVS_EX_CHECKBOXES
))
8371 ImageList_Destroy(himl
);
8374 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_HEADERDRAGDROP
)
8378 /* if not already created */
8379 LISTVIEW_CreateHeader(infoPtr
);
8381 dwStyle
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8382 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8383 dwStyle
|= HDS_DRAGDROP
;
8385 dwStyle
&= ~HDS_DRAGDROP
;
8386 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, dwStyle
);
8389 /* GRIDLINES adds decoration at top so changes sizes */
8390 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_GRIDLINES
)
8392 LISTVIEW_UpdateSize(infoPtr
);
8395 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_TRANSPARENTBKGND
)
8397 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8398 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8401 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_HEADERINALLVIEWS
)
8403 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8404 LISTVIEW_CreateHeader(infoPtr
);
8406 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8407 LISTVIEW_UpdateSize(infoPtr
);
8408 LISTVIEW_UpdateScroll(infoPtr
);
8411 LISTVIEW_InvalidateList(infoPtr
);
8412 return dwOldExStyle
;
8417 * Sets the new hot cursor used during hot tracking and hover selection.
8420 * [I] infoPtr : valid pointer to the listview structure
8421 * [I] hCursor : the new hot cursor handle
8424 * Returns the previous hot cursor
8426 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8428 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8430 infoPtr
->hHotCursor
= hCursor
;
8438 * Sets the hot item index.
8441 * [I] infoPtr : valid pointer to the listview structure
8442 * [I] iIndex : index
8445 * SUCCESS : previous hot item index
8446 * FAILURE : -1 (no hot item)
8448 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8450 INT iOldIndex
= infoPtr
->nHotItem
;
8452 infoPtr
->nHotItem
= iIndex
;
8460 * Sets the amount of time the cursor must hover over an item before it is selected.
8463 * [I] infoPtr : valid pointer to the listview structure
8464 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8467 * Returns the previous hover time
8469 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8471 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8473 infoPtr
->dwHoverTime
= dwHoverTime
;
8475 return oldHoverTime
;
8480 * Sets spacing for icons of LVS_ICON style.
8483 * [I] infoPtr : valid pointer to the listview structure
8484 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8485 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8488 * MAKELONG(oldcx, oldcy)
8490 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8492 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8494 TRACE("requested=(%d,%d)\n", cx
, cy
);
8496 /* this is supported only for LVS_ICON style */
8497 if (infoPtr
->uView
!= LV_VIEW_ICON
) return oldspacing
;
8499 /* set to defaults, if instructed to */
8500 if (cx
== -1) cx
= GetSystemMetrics(SM_CXICONSPACING
);
8501 if (cy
== -1) cy
= GetSystemMetrics(SM_CYICONSPACING
);
8503 /* if 0 then compute width
8504 * FIXME: Should scan each item and determine max width of
8505 * icon or label, then make that the width */
8507 cx
= infoPtr
->iconSpacing
.cx
;
8509 /* if 0 then compute height */
8511 cy
= infoPtr
->iconSize
.cy
+ 2 * infoPtr
->ntmHeight
+
8512 ICON_BOTTOM_PADDING
+ ICON_TOP_PADDING
+ LABEL_VERT_PADDING
;
8515 infoPtr
->iconSpacing
.cx
= cx
;
8516 infoPtr
->iconSpacing
.cy
= cy
;
8518 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8519 LOWORD(oldspacing
), HIWORD(oldspacing
), cx
, cy
,
8520 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8521 infoPtr
->ntmHeight
);
8523 /* these depend on the iconSpacing */
8524 LISTVIEW_UpdateItemSize(infoPtr
);
8529 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8533 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8540 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8541 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8550 * [I] infoPtr : valid pointer to the listview structure
8551 * [I] nType : image list type
8552 * [I] himl : image list handle
8555 * SUCCESS : old image list
8558 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8560 INT oldHeight
= infoPtr
->nItemHeight
;
8561 HIMAGELIST himlOld
= 0;
8563 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
8568 himlOld
= infoPtr
->himlNormal
;
8569 infoPtr
->himlNormal
= himl
;
8570 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8571 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
8575 himlOld
= infoPtr
->himlSmall
;
8576 infoPtr
->himlSmall
= himl
;
8577 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8581 himlOld
= infoPtr
->himlState
;
8582 infoPtr
->himlState
= himl
;
8583 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8584 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8588 ERR("Unknown icon type=%d\n", nType
);
8592 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8593 if (infoPtr
->nItemHeight
!= oldHeight
)
8594 LISTVIEW_UpdateScroll(infoPtr
);
8601 * Preallocates memory (does *not* set the actual count of items !)
8604 * [I] infoPtr : valid pointer to the listview structure
8605 * [I] nItems : item count (projected number of items to allocate)
8606 * [I] dwFlags : update flags
8612 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8614 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8616 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8618 INT nOldCount
= infoPtr
->nItemCount
;
8620 if (nItems
< nOldCount
)
8622 RANGE range
= { nItems
, nOldCount
};
8623 ranges_del(infoPtr
->selectionRanges
, range
);
8624 if (infoPtr
->nFocusedItem
>= nItems
)
8626 LISTVIEW_SetItemFocus(infoPtr
, -1);
8627 SetRectEmpty(&infoPtr
->rcFocus
);
8631 infoPtr
->nItemCount
= nItems
;
8632 LISTVIEW_UpdateScroll(infoPtr
);
8634 /* the flags are valid only in ownerdata report and list modes */
8635 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8637 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8638 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8640 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8641 LISTVIEW_InvalidateList(infoPtr
);
8648 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8649 nFrom
= min(nOldCount
, nItems
);
8650 nTo
= max(nOldCount
, nItems
);
8652 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8655 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8656 rcErase
.right
= infoPtr
->nItemWidth
;
8657 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8658 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8659 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8660 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8662 else /* LV_VIEW_LIST */
8664 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8666 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8667 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8668 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8669 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8670 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8671 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8672 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8674 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8676 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8677 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8678 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8679 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8680 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8686 /* According to MSDN for non-LVS_OWNERDATA this is just
8687 * a performance issue. The control allocates its internal
8688 * data structures for the number of items specified. It
8689 * cuts down on the number of memory allocations. Therefore
8690 * we will just issue a WARN here
8692 WARN("for non-ownerdata performance option not implemented.\n");
8700 * Sets the position of an item.
8703 * [I] infoPtr : valid pointer to the listview structure
8704 * [I] nItem : item index
8705 * [I] pt : coordinate
8711 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8715 TRACE("(nItem=%d, pt=%s\n", nItem
, wine_dbgstr_point(pt
));
8717 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8718 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8721 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8723 /* This point value seems to be an undocumented feature.
8724 * The best guess is that it means either at the origin,
8725 * or at true beginning of the list. I will assume the origin. */
8726 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8729 if (infoPtr
->uView
== LV_VIEW_ICON
)
8731 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8732 Pt
.y
-= ICON_TOP_PADDING
;
8737 infoPtr
->bAutoarrange
= FALSE
;
8739 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8744 * Sets the state of one or many items.
8747 * [I] infoPtr : valid pointer to the listview structure
8748 * [I] nItem : item index
8749 * [I] lpLVItem : item or subitem info
8755 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
)
8757 BOOL bResult
= TRUE
;
8760 lvItem
.iItem
= nItem
;
8761 lvItem
.iSubItem
= 0;
8762 lvItem
.mask
= LVIF_STATE
;
8763 lvItem
.state
= lpLVItem
->state
;
8764 lvItem
.stateMask
= lpLVItem
->stateMask
;
8765 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8769 /* select all isn't allowed in LVS_SINGLESEL */
8770 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8773 /* focus all isn't allowed */
8774 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8776 /* apply to all items */
8777 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8778 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) bResult
= FALSE
;
8781 bResult
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8788 * Sets the text of an item or subitem.
8791 * [I] hwnd : window handle
8792 * [I] nItem : item index
8793 * [I] lpLVItem : item or subitem info
8794 * [I] isW : TRUE if input is Unicode
8800 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8804 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
8806 lvItem
.iItem
= nItem
;
8807 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
8808 lvItem
.mask
= LVIF_TEXT
;
8809 lvItem
.pszText
= lpLVItem
->pszText
;
8810 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
8812 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
8814 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
8819 * Set item index that marks the start of a multiple selection.
8822 * [I] infoPtr : valid pointer to the listview structure
8823 * [I] nIndex : index
8826 * Index number or -1 if there is no selection mark.
8828 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
8830 INT nOldIndex
= infoPtr
->nSelectionMark
;
8832 TRACE("(nIndex=%d)\n", nIndex
);
8834 infoPtr
->nSelectionMark
= nIndex
;
8841 * Sets the text background color.
8844 * [I] infoPtr : valid pointer to the listview structure
8845 * [I] clrTextBk : text background color
8851 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrTextBk
)
8853 TRACE("(clrTextBk=%x)\n", clrTextBk
);
8855 if (infoPtr
->clrTextBk
!= clrTextBk
)
8857 infoPtr
->clrTextBk
= clrTextBk
;
8858 LISTVIEW_InvalidateList(infoPtr
);
8866 * Sets the text foreground color.
8869 * [I] infoPtr : valid pointer to the listview structure
8870 * [I] clrText : text color
8876 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF clrText
)
8878 TRACE("(clrText=%x)\n", clrText
);
8880 if (infoPtr
->clrText
!= clrText
)
8882 infoPtr
->clrText
= clrText
;
8883 LISTVIEW_InvalidateList(infoPtr
);
8891 * Sets new ToolTip window to ListView control.
8894 * [I] infoPtr : valid pointer to the listview structure
8895 * [I] hwndNewToolTip : handle to new ToolTip
8900 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
8902 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
8903 infoPtr
->hwndToolTip
= hwndNewToolTip
;
8904 return hwndOldToolTip
;
8909 * sets the Unicode character format flag for the control
8911 * [I] infoPtr :valid pointer to the listview structure
8912 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
8915 * Old Unicode Format
8917 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
8919 SHORT rc
= infoPtr
->notifyFormat
;
8920 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
8921 return rc
== NFR_UNICODE
;
8926 * sets the control view mode
8928 * [I] infoPtr :valid pointer to the listview structure
8929 * [I] nView :new view mode value
8935 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
8937 SIZE oldIconSize
= infoPtr
->iconSize
;
8940 if (infoPtr
->uView
== nView
) return 1;
8942 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
8943 if (nView
== LV_VIEW_TILE
)
8945 FIXME("View LV_VIEW_TILE unimplemented\n");
8949 infoPtr
->uView
= nView
;
8951 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8952 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8954 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
8955 SetRectEmpty(&infoPtr
->rcFocus
);
8957 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
8958 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
8963 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
8965 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
8966 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
8967 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
8969 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8971 case LV_VIEW_SMALLICON
:
8972 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8974 case LV_VIEW_DETAILS
:
8979 LISTVIEW_CreateHeader( infoPtr
);
8981 hl
.prc
= &infoPtr
->rcList
;
8983 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
8984 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
8985 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
8992 LISTVIEW_UpdateItemSize(infoPtr
);
8993 LISTVIEW_UpdateSize(infoPtr
);
8994 LISTVIEW_UpdateScroll(infoPtr
);
8995 LISTVIEW_InvalidateList(infoPtr
);
8997 TRACE("nView=%d\n", nView
);
9002 /* LISTVIEW_SetWorkAreas */
9006 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9009 * [I] first : pointer to first ITEM_INFO to compare
9010 * [I] second : pointer to second ITEM_INFO to compare
9011 * [I] lParam : HWND of control
9014 * if first comes before second : negative
9015 * if first comes after second : positive
9016 * if first and second are equivalent : zero
9018 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9020 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9021 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9022 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9024 /* Forward the call to the client defined callback */
9025 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9030 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9033 * [I] first : pointer to first ITEM_INFO to compare
9034 * [I] second : pointer to second ITEM_INFO to compare
9035 * [I] lParam : HWND of control
9038 * if first comes before second : negative
9039 * if first comes after second : positive
9040 * if first and second are equivalent : zero
9042 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9044 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9045 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9046 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9048 /* Forward the call to the client defined callback */
9049 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9054 * Sorts the listview items.
9057 * [I] infoPtr : valid pointer to the listview structure
9058 * [I] pfnCompare : application-defined value
9059 * [I] lParamSort : pointer to comparison callback
9060 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9066 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9067 LPARAM lParamSort
, BOOL IsEx
)
9071 LPVOID selectionMarkItem
= NULL
;
9072 LPVOID focusedItem
= NULL
;
9075 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9077 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9079 if (!pfnCompare
) return FALSE
;
9080 if (!infoPtr
->hdpaItems
) return FALSE
;
9082 /* if there are 0 or 1 items, there is no need to sort */
9083 if (infoPtr
->nItemCount
< 2) return TRUE
;
9085 /* clear selection */
9086 ranges_clear(infoPtr
->selectionRanges
);
9088 /* save selection mark and focused item */
9089 if (infoPtr
->nSelectionMark
>= 0)
9090 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9091 if (infoPtr
->nFocusedItem
>= 0)
9092 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9094 infoPtr
->pfnCompare
= pfnCompare
;
9095 infoPtr
->lParamSort
= lParamSort
;
9097 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9099 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9101 /* restore selection ranges */
9102 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9104 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9105 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9107 if (lpItem
->state
& LVIS_SELECTED
)
9108 ranges_additem(infoPtr
->selectionRanges
, i
);
9110 /* restore selection mark and focused item */
9111 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9112 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9114 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9116 /* refresh the display */
9117 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
)
9118 LISTVIEW_InvalidateList(infoPtr
);
9125 * Update theme handle after a theme change.
9128 * [I] infoPtr : valid pointer to the listview structure
9132 * FAILURE : something else
9134 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9136 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9137 CloseThemeData(theme
);
9138 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9144 * Updates an items or rearranges the listview control.
9147 * [I] infoPtr : valid pointer to the listview structure
9148 * [I] nItem : item index
9154 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9156 TRACE("(nItem=%d)\n", nItem
);
9158 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9160 /* rearrange with default alignment style */
9161 if (is_autoarrange(infoPtr
))
9162 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9164 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9171 * Draw the track line at the place defined in the infoPtr structure.
9172 * The line is drawn with a XOR pen so drawing the line for the second time
9173 * in the same place erases the line.
9176 * [I] infoPtr : valid pointer to the listview structure
9182 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9188 if (infoPtr
->xTrackLine
== -1)
9191 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9193 hOldPen
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
9194 oldROP
= SetROP2(hdc
, R2_XORPEN
);
9195 MoveToEx(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
, NULL
);
9196 LineTo(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.bottom
);
9197 SetROP2(hdc
, oldROP
);
9198 SelectObject(hdc
, hOldPen
);
9199 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9205 * Called when an edit control should be displayed. This function is called after
9206 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9209 * [I] hwnd : Handle to the listview
9210 * [I] uMsg : WM_TIMER (ignored)
9211 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9212 * [I] dwTimer : The elapsed time (ignored)
9217 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9219 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9220 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9222 KillTimer(hwnd
, idEvent
);
9223 editItem
->fEnabled
= FALSE
;
9224 /* check if the item is still selected */
9225 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9226 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9231 * Creates the listview control - the WM_NCCREATE phase.
9234 * [I] hwnd : window handle
9235 * [I] lpcs : the create parameters
9241 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9243 LISTVIEW_INFO
*infoPtr
;
9246 TRACE("(lpcs=%p)\n", lpcs
);
9248 /* initialize info pointer */
9249 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9250 if (!infoPtr
) return FALSE
;
9252 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9254 infoPtr
->hwndSelf
= hwnd
;
9255 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9256 map_style_view(infoPtr
);
9257 /* determine the type of structures to use */
9258 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9259 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9261 /* initialize color information */
9262 infoPtr
->clrBk
= CLR_NONE
;
9263 infoPtr
->clrText
= CLR_DEFAULT
;
9264 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9265 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9267 /* set default values */
9268 infoPtr
->nFocusedItem
= -1;
9269 infoPtr
->nSelectionMark
= -1;
9270 infoPtr
->nHotItem
= -1;
9271 infoPtr
->bRedraw
= TRUE
;
9272 infoPtr
->bNoItemMetrics
= TRUE
;
9273 infoPtr
->bDoChangeNotify
= TRUE
;
9274 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
);
9275 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
);
9276 infoPtr
->nEditLabelItem
= -1;
9277 infoPtr
->nLButtonDownItem
= -1;
9278 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9279 infoPtr
->nMeasureItemHeight
= 0;
9280 infoPtr
->xTrackLine
= -1; /* no track line */
9281 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9282 infoPtr
->iVersion
= COMCTL32_VERSION
;
9283 infoPtr
->colRectsDirty
= FALSE
;
9285 /* get default font (icon title) */
9286 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9287 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9288 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9289 LISTVIEW_SaveTextMetrics(infoPtr
);
9291 /* allocate memory for the data structure */
9292 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9293 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9294 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9295 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9296 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9297 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9301 DestroyWindow(infoPtr
->hwndHeader
);
9302 ranges_destroy(infoPtr
->selectionRanges
);
9303 DPA_Destroy(infoPtr
->hdpaItems
);
9304 DPA_Destroy(infoPtr
->hdpaItemIds
);
9305 DPA_Destroy(infoPtr
->hdpaPosX
);
9306 DPA_Destroy(infoPtr
->hdpaPosY
);
9307 DPA_Destroy(infoPtr
->hdpaColumns
);
9314 * Creates the listview control - the WM_CREATE phase. Most of the data is
9315 * already set up in LISTVIEW_NCCreate
9318 * [I] hwnd : window handle
9319 * [I] lpcs : the create parameters
9325 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9327 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9329 TRACE("(lpcs=%p)\n", lpcs
);
9331 infoPtr
->dwStyle
= lpcs
->style
;
9332 map_style_view(infoPtr
);
9334 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9335 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9336 /* on error defaulting to ANSI notifications */
9337 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9338 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9340 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9342 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9345 infoPtr
->hwndHeader
= 0;
9347 /* init item size to avoid division by 0 */
9348 LISTVIEW_UpdateItemSize (infoPtr
);
9350 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9352 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9354 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9356 LISTVIEW_UpdateScroll(infoPtr
);
9357 /* send WM_MEASUREITEM notification */
9358 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9361 OpenThemeData(hwnd
, themeClass
);
9363 /* initialize the icon sizes */
9364 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9365 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9371 * Destroys the listview control.
9374 * [I] infoPtr : valid pointer to the listview structure
9380 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9382 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9383 CloseThemeData(theme
);
9385 /* delete all items */
9386 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9393 * Enables the listview control.
9396 * [I] infoPtr : valid pointer to the listview structure
9397 * [I] bEnable : specifies whether to enable or disable the window
9403 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9405 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9406 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9412 * Erases the background of the listview control.
9415 * [I] infoPtr : valid pointer to the listview structure
9416 * [I] hdc : device context handle
9422 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9426 TRACE("(hdc=%p)\n", hdc
);
9428 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9430 if (infoPtr
->clrBk
== CLR_NONE
)
9432 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9433 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9434 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9436 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9439 /* for double buffered controls we need to do this during refresh */
9440 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9442 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9448 * Helper function for LISTVIEW_[HV]Scroll *only*.
9449 * Performs vertical/horizontal scrolling by a give amount.
9452 * [I] infoPtr : valid pointer to the listview structure
9453 * [I] dx : amount of horizontal scroll
9454 * [I] dy : amount of vertical scroll
9456 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9458 /* now we can scroll the list */
9459 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9460 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9461 /* if we have focus, adjust rect */
9462 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9463 UpdateWindow(infoPtr
->hwndSelf
);
9468 * Performs vertical scrolling.
9471 * [I] infoPtr : valid pointer to the listview structure
9472 * [I] nScrollCode : scroll code
9473 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9474 * [I] hScrollWnd : scrollbar control window handle
9480 * SB_LINEUP/SB_LINEDOWN:
9481 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9482 * for LVS_REPORT is 1 line
9483 * for LVS_LIST cannot occur
9486 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9489 INT nOldScrollPos
, nNewScrollPos
;
9490 SCROLLINFO scrollInfo
;
9493 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9494 debugscrollcode(nScrollCode
), nScrollDiff
);
9496 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9498 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9499 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9501 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9503 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9505 nOldScrollPos
= scrollInfo
.nPos
;
9506 switch (nScrollCode
)
9512 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9516 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9520 nScrollDiff
= -scrollInfo
.nPage
;
9524 nScrollDiff
= scrollInfo
.nPage
;
9527 case SB_THUMBPOSITION
:
9529 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9536 /* quit right away if pos isn't changing */
9537 if (nScrollDiff
== 0) return 0;
9539 /* calculate new position, and handle overflows */
9540 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9541 if (nScrollDiff
> 0) {
9542 if (nNewScrollPos
< nOldScrollPos
||
9543 nNewScrollPos
> scrollInfo
.nMax
)
9544 nNewScrollPos
= scrollInfo
.nMax
;
9546 if (nNewScrollPos
> nOldScrollPos
||
9547 nNewScrollPos
< scrollInfo
.nMin
)
9548 nNewScrollPos
= scrollInfo
.nMin
;
9551 /* set the new position, and reread in case it changed */
9552 scrollInfo
.fMask
= SIF_POS
;
9553 scrollInfo
.nPos
= nNewScrollPos
;
9554 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9556 /* carry on only if it really changed */
9557 if (nNewScrollPos
== nOldScrollPos
) return 0;
9559 /* now adjust to client coordinates */
9560 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9561 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9563 /* and scroll the window */
9564 scroll_list(infoPtr
, 0, nScrollDiff
);
9571 * Performs horizontal scrolling.
9574 * [I] infoPtr : valid pointer to the listview structure
9575 * [I] nScrollCode : scroll code
9576 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9577 * [I] hScrollWnd : scrollbar control window handle
9583 * SB_LINELEFT/SB_LINERIGHT:
9584 * for LVS_ICON, LVS_SMALLICON 1 pixel
9585 * for LVS_REPORT is 1 pixel
9586 * for LVS_LIST is 1 column --> which is a 1 because the
9587 * scroll is based on columns not pixels
9590 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9593 INT nOldScrollPos
, nNewScrollPos
;
9594 SCROLLINFO scrollInfo
;
9596 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9597 debugscrollcode(nScrollCode
), nScrollDiff
);
9599 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9601 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9602 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9604 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9606 nOldScrollPos
= scrollInfo
.nPos
;
9608 switch (nScrollCode
)
9622 nScrollDiff
= -scrollInfo
.nPage
;
9626 nScrollDiff
= scrollInfo
.nPage
;
9629 case SB_THUMBPOSITION
:
9631 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9638 /* quit right away if pos isn't changing */
9639 if (nScrollDiff
== 0) return 0;
9641 /* calculate new position, and handle overflows */
9642 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9643 if (nScrollDiff
> 0) {
9644 if (nNewScrollPos
< nOldScrollPos
||
9645 nNewScrollPos
> scrollInfo
.nMax
)
9646 nNewScrollPos
= scrollInfo
.nMax
;
9648 if (nNewScrollPos
> nOldScrollPos
||
9649 nNewScrollPos
< scrollInfo
.nMin
)
9650 nNewScrollPos
= scrollInfo
.nMin
;
9653 /* set the new position, and reread in case it changed */
9654 scrollInfo
.fMask
= SIF_POS
;
9655 scrollInfo
.nPos
= nNewScrollPos
;
9656 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9658 /* carry on only if it really changed */
9659 if (nNewScrollPos
== nOldScrollPos
) return 0;
9661 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9663 /* now adjust to client coordinates */
9664 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9665 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9667 /* and scroll the window */
9668 scroll_list(infoPtr
, nScrollDiff
, 0);
9673 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9675 INT gcWheelDelta
= 0;
9676 INT pulScrollLines
= 3;
9678 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9680 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9681 gcWheelDelta
-= wheelDelta
;
9683 switch(infoPtr
->uView
)
9686 case LV_VIEW_SMALLICON
:
9688 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9689 * should be fixed in the future.
9691 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (gcWheelDelta
< 0) ?
9692 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9695 case LV_VIEW_DETAILS
:
9696 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
9698 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9699 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
9700 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, cLineScroll
);
9705 LISTVIEW_HScroll(infoPtr
, (gcWheelDelta
< 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9716 * [I] infoPtr : valid pointer to the listview structure
9717 * [I] nVirtualKey : virtual key
9718 * [I] lKeyData : key data
9723 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9725 HWND hwndSelf
= infoPtr
->hwndSelf
;
9727 NMLVKEYDOWN nmKeyDown
;
9729 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9731 /* send LVN_KEYDOWN notification */
9732 nmKeyDown
.wVKey
= nVirtualKey
;
9733 nmKeyDown
.flags
= 0;
9734 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9735 if (!IsWindow(hwndSelf
))
9738 switch (nVirtualKey
)
9741 nItem
= infoPtr
->nFocusedItem
;
9742 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9743 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9747 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9749 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9750 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9755 if (infoPtr
->nItemCount
> 0)
9760 if (infoPtr
->nItemCount
> 0)
9761 nItem
= infoPtr
->nItemCount
- 1;
9765 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9769 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9773 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9777 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9781 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9783 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9784 if (infoPtr
->nFocusedItem
== topidx
)
9785 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9790 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9791 * LISTVIEW_GetCountPerRow(infoPtr
);
9792 if(nItem
< 0) nItem
= 0;
9796 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9798 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9799 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9800 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9801 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9803 nItem
= topidx
+ cnt
- 1;
9806 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9807 * LISTVIEW_GetCountPerRow(infoPtr
);
9808 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9812 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9813 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
9823 * [I] infoPtr : valid pointer to the listview structure
9828 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
9832 /* if we did not have the focus, there's nothing to do */
9833 if (!infoPtr
->bFocus
) return 0;
9835 /* send NM_KILLFOCUS notification */
9836 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
9838 /* if we have a focus rectangle, get rid of it */
9839 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
9841 /* if have a marquee selection, stop it */
9842 if (infoPtr
->bMarqueeSelect
)
9844 /* Remove the marquee rectangle and release our mouse capture */
9845 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
9848 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
9850 infoPtr
->bMarqueeSelect
= FALSE
;
9851 infoPtr
->bScrolling
= FALSE
;
9852 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
9855 /* set window focus flag */
9856 infoPtr
->bFocus
= FALSE
;
9858 /* invalidate the selected items before resetting focus flag */
9859 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9866 * Processes double click messages (left mouse button).
9869 * [I] infoPtr : valid pointer to the listview structure
9870 * [I] wKey : key flag
9871 * [I] x,y : mouse coordinate
9876 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9878 LVHITTESTINFO htInfo
;
9880 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
9882 /* Cancel the item edition if any */
9883 if (infoPtr
->itemEdit
.fEnabled
)
9885 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
9886 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9889 /* send NM_RELEASEDCAPTURE notification */
9890 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9895 /* send NM_DBLCLK notification */
9896 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
9897 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
9899 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
9900 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
9907 * Processes mouse down messages (left mouse button).
9910 * infoPtr [I ] valid pointer to the listview structure
9911 * wKey [I ] key flag
9912 * x,y [I ] mouse coordinate
9917 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9919 LVHITTESTINFO lvHitTestInfo
;
9920 static BOOL bGroupSelect
= TRUE
;
9921 POINT pt
= { x
, y
};
9924 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
9926 /* send NM_RELEASEDCAPTURE notification */
9927 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9929 /* set left button down flag and record the click position */
9930 infoPtr
->bLButtonDown
= TRUE
;
9931 infoPtr
->ptClickPos
= pt
;
9932 infoPtr
->bDragging
= FALSE
;
9933 infoPtr
->bMarqueeSelect
= FALSE
;
9934 infoPtr
->bScrolling
= FALSE
;
9936 lvHitTestInfo
.pt
.x
= x
;
9937 lvHitTestInfo
.pt
.y
= y
;
9939 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
9940 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
9941 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
9943 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
9945 toggle_checkbox_state(infoPtr
, nItem
);
9949 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
9951 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9952 infoPtr
->nEditLabelItem
= nItem
;
9954 LISTVIEW_SetSelection(infoPtr
, nItem
);
9958 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
9962 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
9963 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9964 infoPtr
->nSelectionMark
= nItem
;
9970 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
9971 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9973 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
9974 infoPtr
->nSelectionMark
= nItem
;
9977 else if (wKey
& MK_CONTROL
)
9981 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
9983 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
9984 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9985 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
9986 infoPtr
->nSelectionMark
= nItem
;
9988 else if (wKey
& MK_SHIFT
)
9990 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
9994 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9996 infoPtr
->nEditLabelItem
= nItem
;
9997 infoPtr
->nLButtonDownItem
= nItem
;
9999 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10002 /* set selection (clears other pre-existing selections) */
10003 LISTVIEW_SetSelection(infoPtr
, nItem
);
10007 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10008 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10012 if (!infoPtr
->bFocus
)
10013 SetFocus(infoPtr
->hwndSelf
);
10015 /* remove all selections */
10016 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10017 LISTVIEW_DeselectAll(infoPtr
);
10026 * Processes mouse up messages (left mouse button).
10029 * infoPtr [I ] valid pointer to the listview structure
10030 * wKey [I ] key flag
10031 * x,y [I ] mouse coordinate
10036 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10038 LVHITTESTINFO lvHitTestInfo
;
10040 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10042 if (!infoPtr
->bLButtonDown
) return 0;
10044 lvHitTestInfo
.pt
.x
= x
;
10045 lvHitTestInfo
.pt
.y
= y
;
10047 /* send NM_CLICK notification */
10048 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10049 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10051 /* set left button flag */
10052 infoPtr
->bLButtonDown
= FALSE
;
10054 /* set a single selection, reset others */
10055 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10056 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10057 infoPtr
->nLButtonDownItem
= -1;
10059 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10061 /* Remove the marquee rectangle and release our mouse capture */
10062 if (infoPtr
->bMarqueeSelect
)
10064 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10068 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10069 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10071 infoPtr
->bDragging
= FALSE
;
10072 infoPtr
->bMarqueeSelect
= FALSE
;
10073 infoPtr
->bScrolling
= FALSE
;
10075 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10079 /* if we clicked on a selected item, edit the label */
10080 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10082 /* we want to make sure the user doesn't want to do a double click. So we will
10083 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10085 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10086 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10087 SetTimer(infoPtr
->hwndSelf
,
10088 (UINT_PTR
)&infoPtr
->itemEdit
,
10089 GetDoubleClickTime(),
10090 LISTVIEW_DelayedEditItem
);
10093 if (!infoPtr
->bFocus
)
10094 SetFocus(infoPtr
->hwndSelf
);
10101 * Destroys the listview control (called after WM_DESTROY).
10104 * [I] infoPtr : valid pointer to the listview structure
10109 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10115 /* destroy data structure */
10116 DPA_Destroy(infoPtr
->hdpaItems
);
10117 DPA_Destroy(infoPtr
->hdpaItemIds
);
10118 DPA_Destroy(infoPtr
->hdpaPosX
);
10119 DPA_Destroy(infoPtr
->hdpaPosY
);
10121 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10122 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10123 DPA_Destroy(infoPtr
->hdpaColumns
);
10124 ranges_destroy(infoPtr
->selectionRanges
);
10126 /* destroy image lists */
10127 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10129 ImageList_Destroy(infoPtr
->himlNormal
);
10130 ImageList_Destroy(infoPtr
->himlSmall
);
10131 ImageList_Destroy(infoPtr
->himlState
);
10134 /* destroy font, bkgnd brush */
10135 infoPtr
->hFont
= 0;
10136 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10137 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10139 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10141 /* free listview info pointer*/
10149 * Handles notifications.
10152 * [I] infoPtr : valid pointer to the listview structure
10153 * [I] lpnmhdr : notification information
10158 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, const NMHDR
*lpnmhdr
)
10160 HWND hwndSelf
= infoPtr
->hwndSelf
;
10161 const NMHEADERW
*lpnmh
;
10163 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10165 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10167 /* remember: HDN_LAST < HDN_FIRST */
10168 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10169 lpnmh
= (const NMHEADERW
*)lpnmhdr
;
10171 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10173 switch (lpnmhdr
->code
)
10178 COLUMN_INFO
*lpColumnInfo
;
10182 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10185 /* remove the old line (if any) */
10186 LISTVIEW_DrawTrackLine(infoPtr
);
10188 /* compute & draw the new line */
10189 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10190 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10191 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10192 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10193 LISTVIEW_DrawTrackLine(infoPtr
);
10197 case HDN_ENDTRACKA
:
10198 case HDN_ENDTRACKW
:
10199 /* remove the track line (if any) */
10200 LISTVIEW_DrawTrackLine(infoPtr
);
10201 infoPtr
->xTrackLine
= -1;
10204 case HDN_BEGINDRAG
:
10205 notify_forward_header(infoPtr
, lpnmh
);
10206 return (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0;
10209 infoPtr
->colRectsDirty
= TRUE
;
10210 LISTVIEW_InvalidateList(infoPtr
);
10211 notify_forward_header(infoPtr
, lpnmh
);
10214 case HDN_ITEMCHANGINGW
:
10215 case HDN_ITEMCHANGINGA
:
10216 return notify_forward_header(infoPtr
, lpnmh
);
10218 case HDN_ITEMCHANGEDW
:
10219 case HDN_ITEMCHANGEDA
:
10221 COLUMN_INFO
*lpColumnInfo
;
10225 notify_forward_header(infoPtr
, lpnmh
);
10226 if (!IsWindow(hwndSelf
))
10229 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10231 hdi
.mask
= HDI_WIDTH
;
10232 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10236 cxy
= lpnmh
->pitem
->cxy
;
10238 /* determine how much we change since the last know position */
10239 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10240 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10243 lpColumnInfo
->rcHeader
.right
+= dx
;
10245 hdi
.mask
= HDI_ORDER
;
10246 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10248 /* not the rightmost one */
10249 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10251 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10252 hdi
.iOrder
+ 1, 0);
10253 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10257 /* only needs to update the scrolls */
10258 infoPtr
->nItemWidth
+= dx
;
10259 LISTVIEW_UpdateScroll(infoPtr
);
10261 LISTVIEW_UpdateItemSize(infoPtr
);
10262 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10265 RECT rcCol
= lpColumnInfo
->rcHeader
;
10267 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10268 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10270 rcCol
.top
= infoPtr
->rcList
.top
;
10271 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10273 /* resizing left-aligned columns leaves most of the left side untouched */
10274 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10276 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10279 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10282 /* when shrinking the last column clear the now unused field */
10283 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10289 /* deal with right from rightmost column area */
10290 right
.left
= rcCol
.right
;
10291 right
.top
= rcCol
.top
;
10292 right
.bottom
= rcCol
.bottom
;
10293 right
.right
= infoPtr
->rcList
.right
;
10295 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10298 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10304 case HDN_ITEMCLICKW
:
10305 case HDN_ITEMCLICKA
:
10307 /* Handle sorting by Header Column */
10310 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10312 nmlv
.iSubItem
= lpnmh
->iItem
;
10313 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10314 notify_forward_header(infoPtr
, lpnmh
);
10318 case HDN_DIVIDERDBLCLICKW
:
10319 case HDN_DIVIDERDBLCLICKA
:
10320 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10321 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10322 split needed for that */
10323 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10324 notify_forward_header(infoPtr
, lpnmh
);
10333 * Paint non-client area of control.
10336 * [I] infoPtr : valid pointer to the listview structureof the sender
10337 * [I] region : update region
10340 * TRUE - frame was painted
10341 * FALSE - call default window proc
10343 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10345 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10349 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10350 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10353 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10355 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10357 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10358 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10359 if (region
!= (HRGN
)1)
10360 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10361 OffsetRect(&r
, -r
.left
, -r
.top
);
10363 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10364 OffsetRect(&r
, -r
.left
, -r
.top
);
10366 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10367 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10368 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10369 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10371 /* Call default proc to get the scrollbars etc. painted */
10372 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10379 * Determines the type of structure to use.
10382 * [I] infoPtr : valid pointer to the listview structureof the sender
10383 * [I] hwndFrom : listview window handle
10384 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10389 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10391 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10393 if (nCommand
== NF_REQUERY
)
10394 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10396 return infoPtr
->notifyFormat
;
10401 * Paints/Repaints the listview control. Internal use.
10404 * [I] infoPtr : valid pointer to the listview structure
10405 * [I] hdc : device context handle
10410 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10412 TRACE("(hdc=%p)\n", hdc
);
10414 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10416 infoPtr
->bNoItemMetrics
= FALSE
;
10417 LISTVIEW_UpdateItemSize(infoPtr
);
10418 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10419 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10420 LISTVIEW_UpdateScroll(infoPtr
);
10423 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10426 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10431 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10432 if (!hdc
) return 1;
10433 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10434 EndPaint(infoPtr
->hwndSelf
, &ps
);
10442 * Paints/Repaints the listview control, WM_PAINT handler.
10445 * [I] infoPtr : valid pointer to the listview structure
10446 * [I] hdc : device context handle
10451 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10453 TRACE("(hdc=%p)\n", hdc
);
10455 if (!is_redrawing(infoPtr
))
10456 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10458 return LISTVIEW_Paint(infoPtr
, hdc
);
10463 * Paints/Repaints the listview control.
10466 * [I] infoPtr : valid pointer to the listview structure
10467 * [I] hdc : device context handle
10468 * [I] options : drawing options
10473 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10475 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10477 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10480 if (options
& PRF_ERASEBKGND
)
10481 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10483 if (options
& PRF_CLIENT
)
10484 LISTVIEW_Paint(infoPtr
, hdc
);
10492 * Processes double click messages (right mouse button).
10495 * [I] infoPtr : valid pointer to the listview structure
10496 * [I] wKey : key flag
10497 * [I] x,y : mouse coordinate
10502 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10504 LVHITTESTINFO lvHitTestInfo
;
10506 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10508 /* send NM_RELEASEDCAPTURE notification */
10509 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10511 /* send NM_RDBLCLK notification */
10512 lvHitTestInfo
.pt
.x
= x
;
10513 lvHitTestInfo
.pt
.y
= y
;
10514 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10515 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10522 * Processes mouse down messages (right mouse button).
10525 * [I] infoPtr : valid pointer to the listview structure
10526 * [I] wKey : key flag
10527 * [I] x,y : mouse coordinate
10532 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10534 LVHITTESTINFO lvHitTestInfo
;
10537 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10539 /* send NM_RELEASEDCAPTURE notification */
10540 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10542 /* make sure the listview control window has the focus */
10543 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10545 /* set right button down flag */
10546 infoPtr
->bRButtonDown
= TRUE
;
10548 /* determine the index of the selected item */
10549 lvHitTestInfo
.pt
.x
= x
;
10550 lvHitTestInfo
.pt
.y
= y
;
10551 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10553 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10555 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10556 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10557 !LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10558 LISTVIEW_SetSelection(infoPtr
, nItem
);
10562 LISTVIEW_DeselectAll(infoPtr
);
10570 * Processes mouse up messages (right mouse button).
10573 * [I] infoPtr : valid pointer to the listview structure
10574 * [I] wKey : key flag
10575 * [I] x,y : mouse coordinate
10580 static LRESULT
LISTVIEW_RButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10582 LVHITTESTINFO lvHitTestInfo
;
10585 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10587 if (!infoPtr
->bRButtonDown
) return 0;
10589 /* set button flag */
10590 infoPtr
->bRButtonDown
= FALSE
;
10592 /* Send NM_RCLICK notification */
10593 lvHitTestInfo
.pt
.x
= x
;
10594 lvHitTestInfo
.pt
.y
= y
;
10595 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10596 if (!notify_click(infoPtr
, NM_RCLICK
, &lvHitTestInfo
)) return 0;
10598 /* Change to screen coordinate for WM_CONTEXTMENU */
10599 pt
= lvHitTestInfo
.pt
;
10600 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
10602 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
10603 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10604 (WPARAM
)infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
10615 * [I] infoPtr : valid pointer to the listview structure
10616 * [I] hwnd : window handle of window containing the cursor
10617 * [I] nHittest : hit-test code
10618 * [I] wMouseMsg : ideintifier of the mouse message
10621 * TRUE if cursor is set
10624 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10626 LVHITTESTINFO lvHitTestInfo
;
10628 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10630 if (!infoPtr
->hHotCursor
) goto forward
;
10632 GetCursorPos(&lvHitTestInfo
.pt
);
10633 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10635 SetCursor(infoPtr
->hHotCursor
);
10641 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10649 * [I] infoPtr : valid pointer to the listview structure
10650 * [I] hwndLoseFocus : handle of previously focused window
10655 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10657 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10659 /* if we have the focus already, there's nothing to do */
10660 if (infoPtr
->bFocus
) return 0;
10662 /* send NM_SETFOCUS notification */
10663 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10665 /* set window focus flag */
10666 infoPtr
->bFocus
= TRUE
;
10668 /* put the focus rect back on */
10669 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10671 /* redraw all visible selected items */
10672 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10682 * [I] infoPtr : valid pointer to the listview structure
10683 * [I] fRedraw : font handle
10684 * [I] fRedraw : redraw flag
10689 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10691 HFONT oldFont
= infoPtr
->hFont
;
10693 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10695 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10696 if (infoPtr
->hFont
== oldFont
) return 0;
10698 LISTVIEW_SaveTextMetrics(infoPtr
);
10700 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10702 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10703 LISTVIEW_UpdateSize(infoPtr
);
10704 LISTVIEW_UpdateScroll(infoPtr
);
10707 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10714 * Message handling for WM_SETREDRAW.
10715 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10718 * [I] infoPtr : valid pointer to the listview structure
10719 * [I] bRedraw: state of redraw flag
10722 * DefWinProc return value
10724 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10726 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10728 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10729 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10731 infoPtr
->bRedraw
= bRedraw
;
10733 if(!bRedraw
) return 0;
10735 if (is_autoarrange(infoPtr
))
10736 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10737 LISTVIEW_UpdateScroll(infoPtr
);
10739 /* despite what the WM_SETREDRAW docs says, apps expect us
10740 * to invalidate the listview here... stupid! */
10741 LISTVIEW_InvalidateList(infoPtr
);
10748 * Resizes the listview control. This function processes WM_SIZE
10749 * messages. At this time, the width and height are not used.
10752 * [I] infoPtr : valid pointer to the listview structure
10753 * [I] Width : new width
10754 * [I] Height : new height
10759 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10761 RECT rcOld
= infoPtr
->rcList
;
10763 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10765 LISTVIEW_UpdateSize(infoPtr
);
10766 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10768 /* do not bother with display related stuff if we're not redrawing */
10769 if (!is_redrawing(infoPtr
)) return 0;
10771 if (is_autoarrange(infoPtr
))
10772 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10774 LISTVIEW_UpdateScroll(infoPtr
);
10776 /* refresh all only for lists whose height changed significantly */
10777 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10778 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10779 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10780 LISTVIEW_InvalidateList(infoPtr
);
10787 * Sets the size information.
10790 * [I] infoPtr : valid pointer to the listview structure
10795 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10797 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
10799 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
10801 if (infoPtr
->uView
== LV_VIEW_LIST
)
10803 /* Apparently the "LIST" style is supposed to have the same
10804 * number of items in a column even if there is no scroll bar.
10805 * Since if a scroll bar already exists then the bottom is already
10806 * reduced, only reduce if the scroll bar does not currently exist.
10807 * The "2" is there to mimic the native control. I think it may be
10808 * related to either padding or edges. (GLA 7/2002)
10810 if (!(infoPtr
->dwStyle
& WS_HSCROLL
))
10811 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
10812 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
10815 /* if control created invisible header isn't created */
10816 if (infoPtr
->hwndHeader
)
10821 hl
.prc
= &infoPtr
->rcList
;
10823 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10824 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10826 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
10827 wp
.flags
|= SWP_SHOWWINDOW
;
10830 wp
.flags
|= SWP_HIDEWINDOW
;
10834 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
10835 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10837 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
10839 /* extra padding for grid */
10840 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
10841 infoPtr
->rcList
.top
+= 2;
10843 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
10848 * Processes WM_STYLECHANGED messages.
10851 * [I] infoPtr : valid pointer to the listview structure
10852 * [I] wStyleType : window style type (normal or extended)
10853 * [I] lpss : window style information
10858 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10859 const STYLESTRUCT
*lpss
)
10861 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
10862 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
10865 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10866 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10868 if (wStyleType
!= GWL_STYLE
) return 0;
10870 infoPtr
->dwStyle
= lpss
->styleNew
;
10871 map_style_view(infoPtr
);
10873 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
10874 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
10875 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
10877 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
10878 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
10879 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
10881 if (uNewView
!= uOldView
)
10883 SIZE oldIconSize
= infoPtr
->iconSize
;
10886 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
10887 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
10889 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
10890 SetRectEmpty(&infoPtr
->rcFocus
);
10892 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
10893 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
10895 if (uNewView
== LVS_ICON
)
10897 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
10899 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
10900 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
10901 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
10904 else if (uNewView
== LVS_REPORT
)
10909 LISTVIEW_CreateHeader( infoPtr
);
10911 hl
.prc
= &infoPtr
->rcList
;
10913 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10914 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
10915 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
10916 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
10919 LISTVIEW_UpdateItemSize(infoPtr
);
10922 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
10924 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
10926 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
10928 /* Turn off the header control */
10929 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
10930 TRACE("Hide header control, was 0x%08x\n", style
);
10931 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
10933 /* Turn on the header control */
10934 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
10936 TRACE("Show header control, was 0x%08x\n", style
);
10937 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
10943 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
10944 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
10945 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10947 /* update the size of the client area */
10948 LISTVIEW_UpdateSize(infoPtr
);
10950 /* add scrollbars if needed */
10951 LISTVIEW_UpdateScroll(infoPtr
);
10953 /* invalidate client area + erase background */
10954 LISTVIEW_InvalidateList(infoPtr
);
10961 * Processes WM_STYLECHANGING messages.
10964 * [I] wStyleType : window style type (normal or extended)
10965 * [I0] lpss : window style information
10970 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
10973 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10974 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10976 /* don't forward LVS_OWNERDATA only if not already set to */
10977 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
10979 if (lpss
->styleOld
& LVS_OWNERDATA
)
10980 lpss
->styleNew
|= LVS_OWNERDATA
;
10982 lpss
->styleNew
&= ~LVS_OWNERDATA
;
10990 * Processes WM_SHOWWINDOW messages.
10993 * [I] infoPtr : valid pointer to the listview structure
10994 * [I] bShown : window is being shown (FALSE when hidden)
10995 * [I] iStatus : window show status
11000 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11002 /* header delayed creation */
11003 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11005 LISTVIEW_CreateHeader(infoPtr
);
11007 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11008 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11011 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11016 * Processes CCM_GETVERSION messages.
11019 * [I] infoPtr : valid pointer to the listview structure
11024 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11026 return infoPtr
->iVersion
;
11031 * Processes CCM_SETVERSION messages.
11034 * [I] infoPtr : valid pointer to the listview structure
11035 * [I] iVersion : version to be set
11038 * -1 when requested version is greater than DLL version;
11039 * previous version otherwise
11041 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11043 INT iOldVersion
= infoPtr
->iVersion
;
11045 if (iVersion
> COMCTL32_VERSION
)
11048 infoPtr
->iVersion
= iVersion
;
11050 TRACE("new version %d\n", iVersion
);
11052 return iOldVersion
;
11057 * Window procedure of the listview control.
11060 static LRESULT WINAPI
11061 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11063 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11065 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11067 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11068 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11072 case LVM_APPROXIMATEVIEWRECT
:
11073 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11074 LOWORD(lParam
), HIWORD(lParam
));
11076 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11078 case LVM_CANCELEDITLABEL
:
11079 return LISTVIEW_CancelEditLabel(infoPtr
);
11081 case LVM_CREATEDRAGIMAGE
:
11082 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11084 case LVM_DELETEALLITEMS
:
11085 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11087 case LVM_DELETECOLUMN
:
11088 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11090 case LVM_DELETEITEM
:
11091 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11093 case LVM_EDITLABELA
:
11094 case LVM_EDITLABELW
:
11095 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11096 uMsg
== LVM_EDITLABELW
);
11097 /* case LVM_ENABLEGROUPVIEW: */
11099 case LVM_ENSUREVISIBLE
:
11100 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11102 case LVM_FINDITEMW
:
11103 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11105 case LVM_FINDITEMA
:
11106 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11108 case LVM_GETBKCOLOR
:
11109 return infoPtr
->clrBk
;
11111 /* case LVM_GETBKIMAGE: */
11113 case LVM_GETCALLBACKMASK
:
11114 return infoPtr
->uCallbackMask
;
11116 case LVM_GETCOLUMNA
:
11117 case LVM_GETCOLUMNW
:
11118 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11119 uMsg
== LVM_GETCOLUMNW
);
11121 case LVM_GETCOLUMNORDERARRAY
:
11122 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11124 case LVM_GETCOLUMNWIDTH
:
11125 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11127 case LVM_GETCOUNTPERPAGE
:
11128 return LISTVIEW_GetCountPerPage(infoPtr
);
11130 case LVM_GETEDITCONTROL
:
11131 return (LRESULT
)infoPtr
->hwndEdit
;
11133 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11134 return infoPtr
->dwLvExStyle
;
11136 /* case LVM_GETGROUPINFO: */
11138 /* case LVM_GETGROUPMETRICS: */
11140 case LVM_GETHEADER
:
11141 return (LRESULT
)infoPtr
->hwndHeader
;
11143 case LVM_GETHOTCURSOR
:
11144 return (LRESULT
)infoPtr
->hHotCursor
;
11146 case LVM_GETHOTITEM
:
11147 return infoPtr
->nHotItem
;
11149 case LVM_GETHOVERTIME
:
11150 return infoPtr
->dwHoverTime
;
11152 case LVM_GETIMAGELIST
:
11153 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11155 /* case LVM_GETINSERTMARK: */
11157 /* case LVM_GETINSERTMARKCOLOR: */
11159 /* case LVM_GETINSERTMARKRECT: */
11161 case LVM_GETISEARCHSTRINGA
:
11162 case LVM_GETISEARCHSTRINGW
:
11163 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11168 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11170 case LVM_GETITEMCOUNT
:
11171 return infoPtr
->nItemCount
;
11173 case LVM_GETITEMPOSITION
:
11174 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11176 case LVM_GETITEMRECT
:
11177 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11179 case LVM_GETITEMSPACING
:
11180 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11182 case LVM_GETITEMSTATE
:
11183 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11185 case LVM_GETITEMTEXTA
:
11186 case LVM_GETITEMTEXTW
:
11187 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11188 uMsg
== LVM_GETITEMTEXTW
);
11190 case LVM_GETNEXTITEM
:
11191 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11193 case LVM_GETNUMBEROFWORKAREAS
:
11194 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11197 case LVM_GETORIGIN
:
11198 if (!lParam
) return FALSE
;
11199 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11200 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11201 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11204 /* case LVM_GETOUTLINECOLOR: */
11206 /* case LVM_GETSELECTEDCOLUMN: */
11208 case LVM_GETSELECTEDCOUNT
:
11209 return LISTVIEW_GetSelectedCount(infoPtr
);
11211 case LVM_GETSELECTIONMARK
:
11212 return infoPtr
->nSelectionMark
;
11214 case LVM_GETSTRINGWIDTHA
:
11215 case LVM_GETSTRINGWIDTHW
:
11216 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11217 uMsg
== LVM_GETSTRINGWIDTHW
);
11219 case LVM_GETSUBITEMRECT
:
11220 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11222 case LVM_GETTEXTBKCOLOR
:
11223 return infoPtr
->clrTextBk
;
11225 case LVM_GETTEXTCOLOR
:
11226 return infoPtr
->clrText
;
11228 /* case LVM_GETTILEINFO: */
11230 /* case LVM_GETTILEVIEWINFO: */
11232 case LVM_GETTOOLTIPS
:
11233 if( !infoPtr
->hwndToolTip
)
11234 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11235 return (LRESULT
)infoPtr
->hwndToolTip
;
11237 case LVM_GETTOPINDEX
:
11238 return LISTVIEW_GetTopIndex(infoPtr
);
11240 case LVM_GETUNICODEFORMAT
:
11241 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11244 return infoPtr
->uView
;
11246 case LVM_GETVIEWRECT
:
11247 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11249 case LVM_GETWORKAREAS
:
11250 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11253 /* case LVM_HASGROUP: */
11256 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11258 case LVM_INSERTCOLUMNA
:
11259 case LVM_INSERTCOLUMNW
:
11260 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11261 uMsg
== LVM_INSERTCOLUMNW
);
11263 /* case LVM_INSERTGROUP: */
11265 /* case LVM_INSERTGROUPSORTED: */
11267 case LVM_INSERTITEMA
:
11268 case LVM_INSERTITEMW
:
11269 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11271 /* case LVM_INSERTMARKHITTEST: */
11273 /* case LVM_ISGROUPVIEWENABLED: */
11275 case LVM_ISITEMVISIBLE
:
11276 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11278 case LVM_MAPIDTOINDEX
:
11279 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11281 case LVM_MAPINDEXTOID
:
11282 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11284 /* case LVM_MOVEGROUP: */
11286 /* case LVM_MOVEITEMTOGROUP: */
11288 case LVM_REDRAWITEMS
:
11289 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11291 /* case LVM_REMOVEALLGROUPS: */
11293 /* case LVM_REMOVEGROUP: */
11296 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11298 case LVM_SETBKCOLOR
:
11299 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11301 /* case LVM_SETBKIMAGE: */
11303 case LVM_SETCALLBACKMASK
:
11304 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11307 case LVM_SETCOLUMNA
:
11308 case LVM_SETCOLUMNW
:
11309 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11310 uMsg
== LVM_SETCOLUMNW
);
11312 case LVM_SETCOLUMNORDERARRAY
:
11313 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11315 case LVM_SETCOLUMNWIDTH
:
11316 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11318 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11319 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11321 /* case LVM_SETGROUPINFO: */
11323 /* case LVM_SETGROUPMETRICS: */
11325 case LVM_SETHOTCURSOR
:
11326 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11328 case LVM_SETHOTITEM
:
11329 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11331 case LVM_SETHOVERTIME
:
11332 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11334 case LVM_SETICONSPACING
:
11335 return LISTVIEW_SetIconSpacing(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
11337 case LVM_SETIMAGELIST
:
11338 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11340 /* case LVM_SETINFOTIP: */
11342 /* case LVM_SETINSERTMARK: */
11344 /* case LVM_SETINSERTMARKCOLOR: */
11349 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11350 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11353 case LVM_SETITEMCOUNT
:
11354 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11356 case LVM_SETITEMPOSITION
:
11359 pt
.x
= (short)LOWORD(lParam
);
11360 pt
.y
= (short)HIWORD(lParam
);
11361 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11364 case LVM_SETITEMPOSITION32
:
11365 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11367 case LVM_SETITEMSTATE
:
11368 if (lParam
== 0) return FALSE
;
11369 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11371 case LVM_SETITEMTEXTA
:
11372 case LVM_SETITEMTEXTW
:
11373 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11374 uMsg
== LVM_SETITEMTEXTW
);
11376 /* case LVM_SETOUTLINECOLOR: */
11378 /* case LVM_SETSELECTEDCOLUMN: */
11380 case LVM_SETSELECTIONMARK
:
11381 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11383 case LVM_SETTEXTBKCOLOR
:
11384 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11386 case LVM_SETTEXTCOLOR
:
11387 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11389 /* case LVM_SETTILEINFO: */
11391 /* case LVM_SETTILEVIEWINFO: */
11393 /* case LVM_SETTILEWIDTH: */
11395 case LVM_SETTOOLTIPS
:
11396 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11398 case LVM_SETUNICODEFORMAT
:
11399 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11402 return LISTVIEW_SetView(infoPtr
, wParam
);
11404 /* case LVM_SETWORKAREAS: */
11406 /* case LVM_SORTGROUPS: */
11408 case LVM_SORTITEMS
:
11409 case LVM_SORTITEMSEX
:
11410 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11411 uMsg
== LVM_SORTITEMSEX
);
11412 case LVM_SUBITEMHITTEST
:
11413 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11416 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11418 case CCM_GETVERSION
:
11419 return LISTVIEW_GetVersion(infoPtr
);
11421 case CCM_SETVERSION
:
11422 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11425 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11428 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11431 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11434 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11437 return LISTVIEW_Destroy(infoPtr
);
11440 return LISTVIEW_Enable(infoPtr
);
11442 case WM_ERASEBKGND
:
11443 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11445 case WM_GETDLGCODE
:
11446 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11449 return (LRESULT
)infoPtr
->hFont
;
11452 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11455 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11458 return LISTVIEW_KillFocus(infoPtr
);
11460 case WM_LBUTTONDBLCLK
:
11461 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11463 case WM_LBUTTONDOWN
:
11464 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11467 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11470 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11472 case WM_MOUSEHOVER
:
11473 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11476 return LISTVIEW_NCDestroy(infoPtr
);
11479 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11482 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11484 case WM_NOTIFYFORMAT
:
11485 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11487 case WM_PRINTCLIENT
:
11488 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11491 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11493 case WM_RBUTTONDBLCLK
:
11494 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11496 case WM_RBUTTONDOWN
:
11497 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11500 return LISTVIEW_RButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11503 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11506 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11509 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11512 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11514 case WM_SHOWWINDOW
:
11515 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11518 return LISTVIEW_Size(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
11520 case WM_STYLECHANGED
:
11521 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11523 case WM_STYLECHANGING
:
11524 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11526 case WM_SYSCOLORCHANGE
:
11527 COMCTL32_RefreshSysColors();
11530 /* case WM_TIMER: */
11531 case WM_THEMECHANGED
:
11532 return LISTVIEW_ThemeChanged(infoPtr
);
11535 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11537 case WM_MOUSEWHEEL
:
11538 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11539 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11540 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11542 case WM_WINDOWPOSCHANGED
:
11543 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11545 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11546 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11548 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11550 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11553 LISTVIEW_UpdateSize(infoPtr
);
11554 LISTVIEW_UpdateScroll(infoPtr
);
11556 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11558 /* case WM_WININICHANGE: */
11561 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11562 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11564 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11571 * Registers the window class.
11579 void LISTVIEW_Register(void)
11581 WNDCLASSW wndClass
;
11583 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11584 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11585 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11586 wndClass
.cbClsExtra
= 0;
11587 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11588 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11589 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11590 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11591 RegisterClassW(&wndClass
);
11596 * Unregisters the window class.
11604 void LISTVIEW_Unregister(void)
11606 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11611 * Handle any WM_COMMAND messages
11614 * [I] infoPtr : valid pointer to the listview structure
11615 * [I] wParam : the first message parameter
11616 * [I] lParam : the second message parameter
11621 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11624 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11626 if (!infoPtr
->hwndEdit
) return 0;
11628 switch (HIWORD(wParam
))
11633 * Adjust the edit window size
11635 WCHAR buffer
[1024];
11636 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11637 HFONT hFont
, hOldFont
= 0;
11641 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11642 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11643 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11645 /* Select font to get the right dimension of the string */
11646 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11649 hOldFont
= SelectObject(hdc
, hFont
);
11652 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11654 TEXTMETRICW textMetric
;
11656 /* Add Extra spacing for the next character */
11657 GetTextMetricsW(hdc
, &textMetric
);
11658 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11660 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11661 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11664 SelectObject(hdc
, hOldFont
);
11666 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11672 LISTVIEW_CancelEditLabel(infoPtr
);
11677 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);