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 */
318 BOOL bDefaultBkColor
;
323 INT ntmHeight
; /* Some cached metrics of the font used */
324 INT ntmMaxCharWidth
; /* by the listview to draw items */
327 /* mouse operation */
331 POINT ptClickPos
; /* point where the user clicked */
332 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
336 /* keyboard operation */
337 DWORD lastKeyPressTimestamp
;
339 INT nSearchParamLength
;
340 WCHAR szSearchParam
[ MAX_PATH
];
343 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
344 BOOL bIsDrawing
; /* Drawing in progress */
345 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
346 BOOL bRedraw
; /* WM_SETREDRAW switch */
349 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
355 /* How many we debug buffer to allocate */
356 #define DEBUG_BUFFERS 20
357 /* The size of a single debug buffer */
358 #define DEBUG_BUFFER_SIZE 256
360 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
361 #define SB_INTERNAL -1
363 /* maximum size of a label */
364 #define DISP_TEXT_SIZE 260
366 /* padding for items in list and small icon display modes */
367 #define WIDTH_PADDING 12
369 /* padding for items in list, report and small icon display modes */
370 #define HEIGHT_PADDING 1
372 /* offset of items in report display mode */
373 #define REPORT_MARGINX 2
375 /* padding for icon in large icon display mode
376 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
377 * that HITTEST will see.
378 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
379 * ICON_TOP_PADDING - sum of the two above.
380 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
381 * LABEL_HOR_PADDING - between text and sides of box
382 * LABEL_VERT_PADDING - between bottom of text and end of box
384 * ICON_LR_PADDING - additional width above icon size.
385 * ICON_LR_HALF - half of the above value
387 #define ICON_TOP_PADDING_NOTHITABLE 2
388 #define ICON_TOP_PADDING_HITABLE 2
389 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
390 #define ICON_BOTTOM_PADDING 4
391 #define LABEL_HOR_PADDING 5
392 #define LABEL_VERT_PADDING 7
393 #define ICON_LR_PADDING 16
394 #define ICON_LR_HALF (ICON_LR_PADDING/2)
396 /* default label width for items in list and small icon display modes */
397 #define DEFAULT_LABEL_WIDTH 40
398 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
399 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
401 /* default column width for items in list display mode */
402 #define DEFAULT_COLUMN_WIDTH 128
404 /* Size of "line" scroll for V & H scrolls */
405 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
407 /* Padding between image and label */
408 #define IMAGE_PADDING 2
410 /* Padding behind the label */
411 #define TRAILING_LABEL_PADDING 12
412 #define TRAILING_HEADER_PADDING 11
414 /* Border for the icon caption */
415 #define CAPTION_BORDER 2
417 /* Standard DrawText flags */
418 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
419 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
420 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
422 /* Image index from state */
423 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
425 /* The time in milliseconds to reset the search in the list */
426 #define KEY_DELAY 450
428 /* Dump the LISTVIEW_INFO structure to the debug channel */
429 #define LISTVIEW_DUMP(iP) do { \
430 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
431 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
432 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
433 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
434 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
435 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
436 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
437 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
438 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
439 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
442 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
445 * forward declarations
447 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
448 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
449 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
450 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
451 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
452 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
453 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
454 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
455 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
456 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
457 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
458 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
459 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
460 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
461 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
462 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
463 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
464 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
465 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
466 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
468 /******** Text handling functions *************************************/
470 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
471 * text string. The string may be ANSI or Unicode, in which case
472 * the boolean isW tells us the type of the string.
474 * The name of the function tell what type of strings it expects:
475 * W: Unicode, T: ANSI/Unicode - function of isW
478 static inline BOOL
is_text(LPCWSTR text
)
480 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
483 static inline int textlenT(LPCWSTR text
, BOOL isW
)
485 return !is_text(text
) ? 0 :
486 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
489 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
492 if (isSrcW
) lstrcpynW(dest
, src
, max
);
493 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
495 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
496 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
499 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
501 LPWSTR wstr
= (LPWSTR
)text
;
503 if (!isW
&& is_text(text
))
505 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
506 wstr
= Alloc(len
* sizeof(WCHAR
));
507 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
509 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
513 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
515 if (!isW
&& is_text(wstr
)) Free (wstr
);
519 * dest is a pointer to a Unicode string
520 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
522 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
526 if (src
== LPSTR_TEXTCALLBACKW
)
528 if (is_text(*dest
)) Free(*dest
);
529 *dest
= LPSTR_TEXTCALLBACKW
;
533 LPWSTR pszText
= textdupTtoW(src
, isW
);
534 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
535 bResult
= Str_SetPtrW(dest
, pszText
);
536 textfreeT(pszText
, isW
);
542 * compares a Unicode to a Unicode/ANSI text string
544 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
546 if (!aw
) return bt
? -1 : 0;
548 if (aw
== LPSTR_TEXTCALLBACKW
)
549 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
550 if (bt
!= LPSTR_TEXTCALLBACKW
)
552 LPWSTR bw
= textdupTtoW(bt
, isW
);
553 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
561 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
565 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
566 res
= CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
);
567 return res
? res
- sizeof(WCHAR
) : res
;
570 /******** Debugging functions *****************************************/
572 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
574 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
575 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
578 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
580 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
581 n
= min(textlenT(text
, isW
), n
);
582 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
585 static char* debug_getbuf(void)
587 static int index
= 0;
588 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
589 return buffers
[index
++ % DEBUG_BUFFERS
];
592 static inline const char* debugrange(const RANGE
*lprng
)
594 if (!lprng
) return "(null)";
595 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
598 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
600 char* buf
= debug_getbuf(), *text
= buf
;
601 int len
, size
= DEBUG_BUFFER_SIZE
;
603 if (pScrollInfo
== NULL
) return "(null)";
604 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
605 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
606 if (pScrollInfo
->fMask
& SIF_RANGE
)
607 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
609 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
610 if (pScrollInfo
->fMask
& SIF_PAGE
)
611 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
613 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
614 if (pScrollInfo
->fMask
& SIF_POS
)
615 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
617 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
618 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
619 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
621 if (len
== -1) goto end
; buf
+= len
;
624 buf
= text
+ strlen(text
);
626 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
630 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
632 if (!plvnm
) return "(null)";
633 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
634 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
635 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
636 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
639 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
641 char* buf
= debug_getbuf(), *text
= buf
;
642 int len
, size
= DEBUG_BUFFER_SIZE
;
644 if (lpLVItem
== NULL
) return "(null)";
645 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
646 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
647 if (lpLVItem
->mask
& LVIF_STATE
)
648 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
650 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
651 if (lpLVItem
->mask
& LVIF_TEXT
)
652 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
654 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
655 if (lpLVItem
->mask
& LVIF_IMAGE
)
656 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
658 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
659 if (lpLVItem
->mask
& LVIF_PARAM
)
660 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
662 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
663 if (lpLVItem
->mask
& LVIF_INDENT
)
664 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
666 if (len
== -1) goto end
; buf
+= len
;
669 buf
= text
+ strlen(text
);
671 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
675 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
677 char* buf
= debug_getbuf(), *text
= buf
;
678 int len
, size
= DEBUG_BUFFER_SIZE
;
680 if (lpColumn
== NULL
) return "(null)";
681 len
= snprintf(buf
, size
, "{");
682 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
683 if (lpColumn
->mask
& LVCF_SUBITEM
)
684 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
686 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
687 if (lpColumn
->mask
& LVCF_FMT
)
688 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
690 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
691 if (lpColumn
->mask
& LVCF_WIDTH
)
692 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
694 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
695 if (lpColumn
->mask
& LVCF_TEXT
)
696 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
698 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
699 if (lpColumn
->mask
& LVCF_IMAGE
)
700 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
702 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
703 if (lpColumn
->mask
& LVCF_ORDER
)
704 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
706 if (len
== -1) goto end
; buf
+= len
;
709 buf
= text
+ strlen(text
);
711 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
715 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
717 if (!lpht
) return "(null)";
719 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
720 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
723 /* Return the corresponding text for a given scroll value */
724 static inline LPCSTR
debugscrollcode(int nScrollCode
)
728 case SB_LINELEFT
: return "SB_LINELEFT";
729 case SB_LINERIGHT
: return "SB_LINERIGHT";
730 case SB_PAGELEFT
: return "SB_PAGELEFT";
731 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
732 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
733 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
734 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
735 case SB_INTERNAL
: return "SB_INTERNAL";
736 default: return "unknown";
741 /******** Notification functions ************************************/
743 static int get_ansi_notification(UINT unicodeNotificationCode
)
745 switch (unicodeNotificationCode
)
747 case LVN_BEGINLABELEDITA
:
748 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
749 case LVN_ENDLABELEDITA
:
750 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
751 case LVN_GETDISPINFOA
:
752 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
753 case LVN_SETDISPINFOA
:
754 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
755 case LVN_ODFINDITEMA
:
756 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
757 case LVN_GETINFOTIPA
:
758 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
759 /* header forwards */
761 case HDN_TRACKW
: return HDN_TRACKA
;
763 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
764 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
765 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
766 case HDN_ITEMCHANGINGA
:
767 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
768 case HDN_ITEMCHANGEDA
:
769 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
771 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
772 case HDN_DIVIDERDBLCLICKA
:
773 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
776 FIXME("unknown notification %x\n", unicodeNotificationCode
);
777 return unicodeNotificationCode
;
780 /* forwards header notifications to listview parent */
781 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
785 HD_TEXTFILTERA textfilter
;
786 LPSTR text
= NULL
, filter
= NULL
;
789 /* on unicode format exit earlier */
790 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
791 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
794 /* header always supplies unicode notifications,
795 all we have to do is to convert strings to ANSI */
796 nmhA
= *(const NMHEADERA
*)lpnmh
;
799 hditema
= *(HDITEMA
*)lpnmh
->pitem
;
800 nmhA
.pitem
= &hditema
;
801 /* convert item text */
802 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
804 hditema
.pszText
= NULL
;
805 Str_SetPtrWtoA(&hditema
.pszText
, lpnmh
->pitem
->pszText
);
806 text
= hditema
.pszText
;
808 /* convert filter text */
809 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
810 lpnmh
->pitem
->pvFilter
)
812 hditema
.pvFilter
= &textfilter
;
813 textfilter
= *(HD_TEXTFILTERA
*)(lpnmh
->pitem
->pvFilter
);
814 textfilter
.pszText
= NULL
;
815 Str_SetPtrWtoA(&textfilter
.pszText
, ((HD_TEXTFILTERW
*)lpnmh
->pitem
->pvFilter
)->pszText
);
816 filter
= textfilter
.pszText
;
819 nmhA
.hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
821 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhA
.hdr
.idFrom
,
831 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
835 TRACE("(code=%d)\n", code
);
837 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
838 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
840 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
842 TRACE(" <= %ld\n", result
);
847 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
850 HWND hwnd
= infoPtr
->hwndSelf
;
851 notify_hdr(infoPtr
, code
, &nmh
);
852 return IsWindow(hwnd
);
855 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
866 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
867 item
.iItem
= htInfo
->iItem
;
869 item
.stateMask
= (UINT
)-1;
870 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
871 nmia
.lParam
= item
.lParam
;
872 nmia
.uOldState
= item
.state
;
873 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
874 nmia
.uChanged
= LVIF_STATE
;
877 nmia
.iItem
= htInfo
->iItem
;
878 nmia
.iSubItem
= htInfo
->iSubItem
;
879 nmia
.ptAction
= htInfo
->pt
;
881 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
882 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
883 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
885 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
888 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
890 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
891 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
894 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
898 HWND hwnd
= infoPtr
->hwndSelf
;
900 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
901 ZeroMemory(&nmia
, sizeof(nmia
));
902 nmia
.iItem
= lvht
->iItem
;
903 nmia
.iSubItem
= lvht
->iSubItem
;
904 nmia
.ptAction
= lvht
->pt
;
905 item
.mask
= LVIF_PARAM
;
906 item
.iItem
= lvht
->iItem
;
908 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
909 notify_hdr(infoPtr
, code
, (LPNMHDR
)&nmia
);
910 return IsWindow(hwnd
);
913 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
917 HWND hwnd
= infoPtr
->hwndSelf
;
919 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
921 item
.mask
= LVIF_PARAM
;
924 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
925 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
926 return IsWindow(hwnd
);
930 Send notification. depends on dispinfoW having same
931 structure as dispinfoA.
932 infoPtr : listview struct
933 code : *Unicode* notification code
934 pdi : dispinfo structure (can be unicode or ansi)
935 isW : TRUE if dispinfo is Unicode
937 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
939 INT length
= 0, ret_length
;
940 LPWSTR buffer
= NULL
, ret_text
;
941 BOOL return_ansi
= FALSE
;
942 BOOL return_unicode
= FALSE
;
945 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
947 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
948 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
951 ret_length
= pdi
->item
.cchTextMax
;
952 ret_text
= pdi
->item
.pszText
;
954 if (return_unicode
|| return_ansi
)
956 if (code
!= LVN_GETDISPINFOW
)
958 length
= return_ansi
?
959 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
960 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
964 length
= pdi
->item
.cchTextMax
;
965 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
968 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
969 if (!buffer
) return FALSE
;
972 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
975 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
978 pdi
->item
.pszText
= buffer
;
979 pdi
->item
.cchTextMax
= length
;
982 if (infoPtr
->notifyFormat
== NFR_ANSI
)
983 code
= get_ansi_notification(code
);
985 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
986 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
987 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
989 if (return_ansi
|| return_unicode
)
991 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
993 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
995 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
997 strcpyW(ret_text
, pdi
->item
.pszText
);
999 else if (return_ansi
) /* note : pointer can be changed by app ! */
1001 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
1002 ret_length
, NULL
, NULL
);
1005 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
1006 ret_text
, ret_length
);
1008 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
1009 pdi
->item
.cchTextMax
= ret_length
;
1015 /* if dipsinfo holder changed notification code then convert */
1016 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1018 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1020 buffer
= Alloc(length
* sizeof(CHAR
));
1021 if (!buffer
) return FALSE
;
1023 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1024 ret_length
, NULL
, NULL
);
1026 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1033 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1034 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1036 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1037 lpnmlvcd
->nmcd
.hdc
= hdc
;
1038 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1039 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1040 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1041 if (!lplvItem
) return;
1042 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1043 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1044 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1045 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1046 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1047 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1050 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1052 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1055 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1056 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1057 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1058 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1059 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1060 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1064 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1066 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
1067 lpnmlvcd
->clrTextBk
= comctl32_color
.clrWindow
;
1068 if (lpnmlvcd
->clrText
== CLR_DEFAULT
)
1069 lpnmlvcd
->clrText
= comctl32_color
.clrWindowText
;
1071 /* apparently, for selected items, we have to override the returned values */
1074 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1076 if (infoPtr
->bFocus
)
1078 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1079 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1081 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1083 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1084 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1089 /* Set the text attributes */
1090 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
1092 SetBkMode(hdc
, OPAQUE
);
1093 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1096 SetBkMode(hdc
, TRANSPARENT
);
1097 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1100 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1102 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1105 /* returns TRUE when repaint needed, FALSE otherwise */
1106 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1108 MEASUREITEMSTRUCT mis
;
1109 mis
.CtlType
= ODT_LISTVIEW
;
1110 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1114 mis
.itemHeight
= infoPtr
->nItemHeight
;
1115 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1116 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1118 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1124 /******** Item iterator functions **********************************/
1126 static RANGES
ranges_create(int count
);
1127 static void ranges_destroy(RANGES ranges
);
1128 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1129 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1130 static void ranges_dump(RANGES ranges
);
1132 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1134 RANGE range
= { nItem
, nItem
+ 1 };
1136 return ranges_add(ranges
, range
);
1139 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1141 RANGE range
= { nItem
, nItem
+ 1 };
1143 return ranges_del(ranges
, range
);
1147 * ITERATOR DOCUMENTATION
1149 * The iterator functions allow for easy, and convenient iteration
1150 * over items of interest in the list. Typically, you create a
1151 * iterator, use it, and destroy it, as such:
1154 * iterator_xxxitems(&i, ...);
1155 * while (iterator_{prev,next}(&i)
1157 * //code which uses i.nItem
1159 * iterator_destroy(&i);
1161 * where xxx is either: framed, or visible.
1162 * Note that it is important that the code destroys the iterator
1163 * after it's done with it, as the creation of the iterator may
1164 * allocate memory, which thus needs to be freed.
1166 * You can iterate both forwards, and backwards through the list,
1167 * by using iterator_next or iterator_prev respectively.
1169 * Lower numbered items are draw on top of higher number items in
1170 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1171 * items may overlap). So, to test items, you should use
1173 * which lists the items top to bottom (in Z-order).
1174 * For drawing items, you should use
1176 * which lists the items bottom to top (in Z-order).
1177 * If you keep iterating over the items after the end-of-items
1178 * marker (-1) is returned, the iterator will start from the
1179 * beginning. Typically, you don't need to test for -1,
1180 * because iterator_{next,prev} will return TRUE if more items
1181 * are to be iterated over, or FALSE otherwise.
1183 * Note: the iterator is defined to be bidirectional. That is,
1184 * any number of prev followed by any number of next, or
1185 * five versa, should leave the iterator at the same item:
1186 * prev * n, next * n = next * n, prev * n
1188 * The iterator has a notion of an out-of-order, special item,
1189 * which sits at the start of the list. This is used in
1190 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1191 * which needs to be first, as it may overlap other items.
1193 * The code is a bit messy because we have:
1194 * - a special item to deal with
1195 * - simple range, or composite range
1197 * If you find bugs, or want to add features, please make sure you
1198 * always check/modify *both* iterator_prev, and iterator_next.
1202 * This function iterates through the items in increasing order,
1203 * but prefixed by the special item, then -1. That is:
1204 * special, 1, 2, 3, ..., n, -1.
1205 * Each item is listed only once.
1207 static inline BOOL
iterator_next(ITERATOR
* i
)
1211 i
->nItem
= i
->nSpecial
;
1212 if (i
->nItem
!= -1) return TRUE
;
1214 if (i
->nItem
== i
->nSpecial
)
1216 if (i
->ranges
) i
->index
= 0;
1222 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1223 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1228 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1229 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1232 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1234 i
->nItem
= i
->range
.lower
;
1235 if (i
->nItem
>= 0) goto testitem
;
1242 * This function iterates through the items in decreasing order,
1243 * followed by the special item, then -1. That is:
1244 * n, n-1, ..., 3, 2, 1, special, -1.
1245 * Each item is listed only once.
1247 static inline BOOL
iterator_prev(ITERATOR
* i
)
1254 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1257 if (i
->nItem
== i
->nSpecial
)
1265 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1266 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1272 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1275 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1277 i
->nItem
= i
->range
.upper
;
1278 if (i
->nItem
> 0) goto testitem
;
1280 return (i
->nItem
= i
->nSpecial
) != -1;
1283 static RANGE
iterator_range(const ITERATOR
*i
)
1287 if (!i
->ranges
) return i
->range
;
1289 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1291 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1292 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1294 else range
.lower
= range
.upper
= 0;
1300 * Releases resources associated with this ierator.
1302 static inline void iterator_destroy(const ITERATOR
*i
)
1304 ranges_destroy(i
->ranges
);
1308 * Create an empty iterator.
1310 static inline BOOL
iterator_empty(ITERATOR
* i
)
1312 ZeroMemory(i
, sizeof(*i
));
1313 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1318 * Create an iterator over a range.
1320 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1328 * Create an iterator over a bunch of ranges.
1329 * Please note that the iterator will take ownership of the ranges,
1330 * and will free them upon destruction.
1332 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1340 * Creates an iterator over the items which intersect frame.
1341 * Uses absolute coordinates rather than compensating for the current offset.
1343 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1345 RECT rcItem
, rcTemp
;
1347 /* in case we fail, we want to return an empty iterator */
1348 if (!iterator_empty(i
)) return FALSE
;
1350 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1352 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1356 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1358 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1359 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1360 i
->nSpecial
= infoPtr
->nFocusedItem
;
1362 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1363 /* to do better here, we need to have PosX, and PosY sorted */
1364 TRACE("building icon ranges:\n");
1365 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1367 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1368 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1369 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1370 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1371 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1372 ranges_additem(i
->ranges
, nItem
);
1376 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1380 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1381 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1383 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1384 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1385 if (range
.upper
<= range
.lower
) return TRUE
;
1386 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1387 TRACE(" report=%s\n", debugrange(&i
->range
));
1391 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1392 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1393 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1400 if (infoPtr
->nItemWidth
)
1402 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1403 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1407 nFirstCol
= max(frame
->left
, 0);
1408 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1411 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1413 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1414 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1416 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1418 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1419 TRACE("building list ranges:\n");
1420 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1422 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1423 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1424 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1425 TRACE(" list=%s\n", debugrange(&item_range
));
1426 ranges_add(i
->ranges
, item_range
);
1434 * Creates an iterator over the items which intersect lprc.
1436 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1441 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1443 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1444 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1446 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1450 * Creates an iterator over the items which intersect the visible region of hdc.
1452 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1454 POINT Origin
, Position
;
1455 RECT rcItem
, rcClip
;
1458 rgntype
= GetClipBox(hdc
, &rcClip
);
1459 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1460 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1461 if (rgntype
== SIMPLEREGION
) return TRUE
;
1463 /* first deal with the special item */
1464 if (i
->nSpecial
!= -1)
1466 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1467 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1470 /* if we can't deal with the region, we'll just go with the simple range */
1471 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1472 TRACE("building visible range:\n");
1473 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1475 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1476 if (!ranges_add(i
->ranges
, i
->range
))
1478 ranges_destroy(i
->ranges
);
1484 /* now delete the invisible items from the list */
1485 while(iterator_next(i
))
1487 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1488 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1489 rcItem
.top
= Position
.y
+ Origin
.y
;
1490 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1491 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1492 if (!RectVisible(hdc
, &rcItem
))
1493 ranges_delitem(i
->ranges
, i
->nItem
);
1495 /* the iterator should restart on the next iterator_next */
1501 /******** Misc helper functions ************************************/
1503 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1504 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1506 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1507 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1510 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1512 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1513 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1516 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1518 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1519 if(state
== 1 || state
== 2)
1523 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1524 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1525 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1529 /* this should be called after window style got updated,
1530 it used to reset view state to match current window style */
1531 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1533 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1536 infoPtr
->uView
= LV_VIEW_ICON
;
1539 infoPtr
->uView
= LV_VIEW_DETAILS
;
1542 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1545 infoPtr
->uView
= LV_VIEW_LIST
;
1549 /* computes next item id value */
1550 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1552 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1556 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1557 return lpID
->id
+ 1;
1562 /******** Internal API functions ************************************/
1564 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1566 static COLUMN_INFO mainItem
;
1568 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1569 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1571 /* update cached column rectangles */
1572 if (infoPtr
->colRectsDirty
)
1575 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1578 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1579 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1580 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1582 Ptr
->colRectsDirty
= FALSE
;
1585 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1588 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1590 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1593 if (infoPtr
->hwndHeader
) return 0;
1595 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1597 /* setup creation flags */
1598 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1599 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1601 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1604 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1605 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1606 if (!infoPtr
->hwndHeader
) return -1;
1608 /* set header unicode format */
1609 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1611 /* set header font */
1612 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1614 LISTVIEW_UpdateSize(infoPtr
);
1619 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1621 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1624 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1626 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1627 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1628 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1631 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1633 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1636 /* used to handle collapse main item column case */
1637 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1641 if (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
)
1643 DWORD dwOldBkColor
, dwOldTextColor
;
1645 dwOldBkColor
= SetBkColor(hdc
, RGB(255, 255, 255));
1646 dwOldTextColor
= SetBkColor(hdc
, RGB(0, 0, 0));
1647 Ret
= DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1648 SetBkColor(hdc
, dwOldBkColor
);
1649 SetBkColor(hdc
, dwOldTextColor
);
1654 /* Listview invalidation functions: use _only_ these functions to invalidate */
1656 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1658 return infoPtr
->bRedraw
;
1661 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1663 if(!is_redrawing(infoPtr
)) return;
1664 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1665 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1668 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1672 if(!is_redrawing(infoPtr
)) return;
1673 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1674 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1677 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1679 POINT Origin
, Position
;
1682 if(!is_redrawing(infoPtr
)) return;
1683 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1684 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1685 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1686 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1688 rcBox
.bottom
= infoPtr
->nItemHeight
;
1689 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1690 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1693 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1695 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1698 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1702 if(!is_redrawing(infoPtr
)) return;
1703 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1704 rcCol
.top
= infoPtr
->rcList
.top
;
1705 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1706 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1711 * Retrieves the number of items that can fit vertically in the client area.
1714 * [I] infoPtr : valid pointer to the listview structure
1717 * Number of items per row.
1719 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1721 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1723 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1728 * Retrieves the number of items that can fit horizontally in the client
1732 * [I] infoPtr : valid pointer to the listview structure
1735 * Number of items per column.
1737 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1739 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1741 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1745 /*************************************************************************
1746 * LISTVIEW_ProcessLetterKeys
1748 * Processes keyboard messages generated by pressing the letter keys
1750 * What this does is perform a case insensitive search from the
1751 * current position with the following quirks:
1752 * - If two chars or more are pressed in quick succession we search
1753 * for the corresponding string (e.g. 'abc').
1754 * - If there is a delay we wipe away the current search string and
1755 * restart with just that char.
1756 * - If the user keeps pressing the same character, whether slowly or
1757 * fast, so that the search string is entirely composed of this
1758 * character ('aaaaa' for instance), then we search for first item
1759 * that starting with that character.
1760 * - If the user types the above character in quick succession, then
1761 * we must also search for the corresponding string ('aaaaa'), and
1762 * go to that string if there is a match.
1765 * [I] hwnd : handle to the window
1766 * [I] charCode : the character code, the actual character
1767 * [I] keyData : key data
1775 * - The current implementation has a list of characters it will
1776 * accept and it ignores everything else. In particular it will
1777 * ignore accentuated characters which seems to match what
1778 * Windows does. But I'm not sure it makes sense to follow
1780 * - We don't sound a beep when the search fails.
1784 * TREEVIEW_ProcessLetterKeys
1786 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1788 WCHAR buffer
[MAX_PATH
];
1789 INT endidx
, startidx
;
1795 /* simple parameter checking */
1796 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1798 /* only allow the valid WM_CHARs through */
1799 if (!isalnumW(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
!= '>' &&
1808 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1811 /* update the search parameters */
1812 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1813 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1814 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1816 if (diff
>= 0 && diff
< KEY_DELAY
)
1818 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1819 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1821 if (infoPtr
->charCode
!= charCode
)
1822 infoPtr
->charCode
= charCode
= 0;
1826 infoPtr
->charCode
= charCode
;
1827 infoPtr
->szSearchParam
[0] = charCode
;
1828 infoPtr
->nSearchParamLength
= 1;
1831 /* and search from the current position */
1833 endidx
= infoPtr
->nItemCount
;
1835 /* should start from next after focused item, so next item that matches
1836 will be selected, if there isn't any and focused matches it will be selected
1837 on second search stage from beginning of the list */
1838 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1839 startidx
= infoPtr
->nFocusedItem
+ 1;
1843 /* let application handle this for virtual listview */
1844 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1848 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1849 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1850 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1851 nmlv
.iStart
= startidx
;
1853 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1855 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1861 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1864 /* start from first item if not found with >= startidx */
1865 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1871 for (i
= startidx
; i
< endidx
; i
++)
1874 item
.mask
= LVIF_TEXT
;
1877 item
.pszText
= buffer
;
1878 item
.cchTextMax
= MAX_PATH
;
1879 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1881 if (lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
) == 0)
1886 else if (nItem
== -1 && lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1) == 0)
1888 /* this would work but we must keep looking for a longer match */
1893 if ( nItem
!= -1 || /* found something */
1894 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1895 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1901 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1906 /*************************************************************************
1907 * LISTVIEW_UpdateHeaderSize [Internal]
1909 * Function to resize the header control
1912 * [I] hwnd : handle to a window
1913 * [I] nNewScrollPos : scroll pos to set
1918 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1923 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1925 if (!infoPtr
->hwndHeader
) return;
1927 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1928 point
[0].x
= winRect
.left
;
1929 point
[0].y
= winRect
.top
;
1930 point
[1].x
= winRect
.right
;
1931 point
[1].y
= winRect
.bottom
;
1933 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1934 point
[0].x
= -nNewScrollPos
;
1935 point
[1].x
+= nNewScrollPos
;
1937 SetWindowPos(infoPtr
->hwndHeader
,0,
1938 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1939 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1940 SWP_NOZORDER
| SWP_NOACTIVATE
);
1945 * Update the scrollbars. This functions should be called whenever
1946 * the content, size or view changes.
1949 * [I] infoPtr : valid pointer to the listview structure
1954 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
1956 SCROLLINFO horzInfo
, vertInfo
;
1959 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
1961 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
1962 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
1963 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1965 /* for now, we'll set info.nMax to the _count_, and adjust it later */
1966 if (infoPtr
->uView
== LV_VIEW_LIST
)
1968 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
1969 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
1971 /* scroll by at least one column per page */
1972 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
1973 horzInfo
.nPage
= infoPtr
->nItemWidth
;
1975 if (infoPtr
->nItemWidth
)
1976 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
1978 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1980 horzInfo
.nMax
= infoPtr
->nItemWidth
;
1982 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
1986 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
1989 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
1991 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
1996 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
1997 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
1999 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2000 horzInfo
.nMax
= rcHeader
.right
;
2001 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2005 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2006 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2007 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2008 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2009 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2011 /* Setting the horizontal scroll can change the listview size
2012 * (and potentially everything else) so we need to recompute
2013 * everything again for the vertical scroll
2016 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2017 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2018 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2020 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2022 vertInfo
.nMax
= infoPtr
->nItemCount
;
2024 /* scroll by at least one page */
2025 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2026 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2028 if (infoPtr
->nItemHeight
> 0)
2029 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2031 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2035 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2038 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2039 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2040 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2041 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2042 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2044 /* Change of the range may have changed the scroll pos. If so move the content */
2045 if (dx
!= 0 || dy
!= 0)
2048 listRect
= infoPtr
->rcList
;
2049 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2050 SW_ERASE
| SW_INVALIDATE
);
2053 /* Update the Header Control */
2054 if (infoPtr
->hwndHeader
)
2056 horzInfo
.fMask
= SIF_POS
;
2057 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2058 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2065 * Shows/hides the focus rectangle.
2068 * [I] infoPtr : valid pointer to the listview structure
2069 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2074 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2078 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2080 if (infoPtr
->nFocusedItem
< 0) return;
2082 /* we need some gymnastics in ICON mode to handle large items */
2083 if (infoPtr
->uView
== LV_VIEW_ICON
)
2087 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2088 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2090 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2095 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2097 /* for some reason, owner draw should work only in report mode */
2098 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2103 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2104 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2106 item
.iItem
= infoPtr
->nFocusedItem
;
2108 item
.mask
= LVIF_PARAM
;
2109 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2111 ZeroMemory(&dis
, sizeof(dis
));
2112 dis
.CtlType
= ODT_LISTVIEW
;
2113 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2114 dis
.itemID
= item
.iItem
;
2115 dis
.itemAction
= ODA_FOCUS
;
2116 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2117 dis
.hwndItem
= infoPtr
->hwndSelf
;
2119 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2120 dis
.itemData
= item
.lParam
;
2122 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2124 SelectObject(hdc
, hOldFont
);
2128 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2131 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2135 * Invalidates all visible selected items.
2137 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2141 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2142 while(iterator_next(&i
))
2144 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2145 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2147 iterator_destroy(&i
);
2152 * DESCRIPTION: [INTERNAL]
2153 * Computes an item's (left,top) corner, relative to rcView.
2154 * That is, the position has NOT been made relative to the Origin.
2155 * This is deliberate, to avoid computing the Origin over, and
2156 * over again, when this function is called in a loop. Instead,
2157 * one can factor the computation of the Origin before the loop,
2158 * and offset the value returned by this function, on every iteration.
2161 * [I] infoPtr : valid pointer to the listview structure
2162 * [I] nItem : item number
2163 * [O] lpptOrig : item top, left corner
2168 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2170 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2172 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2174 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2175 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2177 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2179 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2180 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2181 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2183 else /* LV_VIEW_DETAILS */
2185 lpptPosition
->x
= REPORT_MARGINX
;
2186 /* item is always at zero indexed column */
2187 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2188 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2189 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2194 * DESCRIPTION: [INTERNAL]
2195 * Compute the rectangles of an item. This is to localize all
2196 * the computations in one place. If you are not interested in some
2197 * of these values, simply pass in a NULL -- the function is smart
2198 * enough to compute only what's necessary. The function computes
2199 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2200 * one, the BOX rectangle. This rectangle is very cheap to compute,
2201 * and is guaranteed to contain all the other rectangles. Computing
2202 * the ICON rect is also cheap, but all the others are potentially
2203 * expensive. This gives an easy and effective optimization when
2204 * searching (like point inclusion, or rectangle intersection):
2205 * first test against the BOX, and if TRUE, test against the desired
2207 * If the function does not have all the necessary information
2208 * to computed the requested rectangles, will crash with a
2209 * failed assertion. This is done so we catch all programming
2210 * errors, given that the function is called only from our code.
2212 * We have the following 'special' meanings for a few fields:
2213 * * If LVIS_FOCUSED is set, we assume the item has the focus
2214 * This is important in ICON mode, where it might get a larger
2215 * then usual rectangle
2217 * Please note that subitem support works only in REPORT mode.
2220 * [I] infoPtr : valid pointer to the listview structure
2221 * [I] lpLVItem : item to compute the measures for
2222 * [O] lprcBox : ptr to Box rectangle
2223 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2224 * [0] lprcSelectBox : ptr to select box rectangle
2225 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2226 * [O] lprcIcon : ptr to Icon rectangle
2227 * Same as LVM_GETITEMRECT with LVIR_ICON
2228 * [O] lprcStateIcon: ptr to State Icon rectangle
2229 * [O] lprcLabel : ptr to Label rectangle
2230 * Same as LVM_GETITEMRECT with LVIR_LABEL
2235 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2236 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2237 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2239 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2240 RECT Box
, SelectBox
, Icon
, Label
;
2241 COLUMN_INFO
*lpColumnInfo
= NULL
;
2242 SIZE labelSize
= { 0, 0 };
2244 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2246 /* Be smart and try to figure out the minimum we have to do */
2247 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2248 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2250 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2251 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2253 if (lprcSelectBox
) doSelectBox
= TRUE
;
2254 if (lprcLabel
) doLabel
= TRUE
;
2255 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2262 /************************************************************/
2263 /* compute the box rectangle (it should be cheap to do) */
2264 /************************************************************/
2265 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2266 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2268 if (lpLVItem
->iSubItem
)
2270 Box
= lpColumnInfo
->rcHeader
;
2275 Box
.right
= infoPtr
->nItemWidth
;
2278 Box
.bottom
= infoPtr
->nItemHeight
;
2280 /******************************************************************/
2281 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2282 /******************************************************************/
2285 LONG state_width
= 0;
2287 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2288 state_width
= infoPtr
->iconStateSize
.cx
;
2290 if (infoPtr
->uView
== LV_VIEW_ICON
)
2292 Icon
.left
= Box
.left
+ state_width
;
2293 if (infoPtr
->himlNormal
)
2294 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2295 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2296 Icon
.right
= Icon
.left
;
2297 Icon
.bottom
= Icon
.top
;
2298 if (infoPtr
->himlNormal
)
2300 Icon
.right
+= infoPtr
->iconSize
.cx
;
2301 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2304 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2306 Icon
.left
= Box
.left
+ state_width
;
2308 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2310 /* we need the indent in report mode */
2311 assert(lpLVItem
->mask
& LVIF_INDENT
);
2312 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2316 Icon
.right
= Icon
.left
;
2317 if (infoPtr
->himlSmall
&&
2318 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 || (lpColumnInfo
->fmt
& LVCFMT_IMAGE
) ||
2319 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2320 Icon
.right
+= infoPtr
->iconSize
.cx
;
2321 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2323 if(lprcIcon
) *lprcIcon
= Icon
;
2324 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2326 /* TODO: is this correct? */
2329 lprcStateIcon
->left
= Icon
.left
- state_width
;
2330 lprcStateIcon
->right
= Icon
.left
;
2331 lprcStateIcon
->top
= Icon
.top
;
2332 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2333 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2336 else Icon
.right
= 0;
2338 /************************************************************/
2339 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2340 /************************************************************/
2343 /* calculate how far to the right can the label stretch */
2344 Label
.right
= Box
.right
;
2345 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2347 if (lpLVItem
->iSubItem
== 0)
2349 /* we need a zero based rect here */
2350 Label
= lpColumnInfo
->rcHeader
;
2351 OffsetRect(&Label
, -Label
.left
, 0);
2355 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2357 labelSize
.cx
= infoPtr
->nItemWidth
;
2358 labelSize
.cy
= infoPtr
->nItemHeight
;
2362 /* we need the text in non owner draw mode */
2363 assert(lpLVItem
->mask
& LVIF_TEXT
);
2364 if (is_text(lpLVItem
->pszText
))
2366 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2367 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2368 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2372 /* compute rough rectangle where the label will go */
2373 SetRectEmpty(&rcText
);
2374 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2375 rcText
.bottom
= infoPtr
->nItemHeight
;
2376 if (infoPtr
->uView
== LV_VIEW_ICON
)
2377 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2379 /* now figure out the flags */
2380 if (infoPtr
->uView
== LV_VIEW_ICON
)
2381 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2383 uFormat
= LV_SL_DT_FLAGS
;
2385 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2387 if (rcText
.right
!= rcText
.left
)
2388 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2390 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2392 SelectObject(hdc
, hOldFont
);
2393 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2397 if (infoPtr
->uView
== LV_VIEW_ICON
)
2399 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2400 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2401 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2402 Label
.right
= Label
.left
+ labelSize
.cx
;
2403 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2404 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2406 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2407 labelSize
.cy
/= infoPtr
->ntmHeight
;
2408 labelSize
.cy
= max(labelSize
.cy
, 1);
2409 labelSize
.cy
*= infoPtr
->ntmHeight
;
2411 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2413 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2415 Label
.left
= Icon
.right
;
2416 Label
.top
= Box
.top
;
2417 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2418 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2419 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2421 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2423 Label
.left
= Icon
.right
;
2424 Label
.top
= Box
.top
;
2425 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2426 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2429 if (lprcLabel
) *lprcLabel
= Label
;
2430 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2433 /************************************************************/
2434 /* compute SELECT bounding box */
2435 /************************************************************/
2438 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2440 SelectBox
.left
= Icon
.left
;
2441 SelectBox
.top
= Box
.top
;
2442 SelectBox
.bottom
= Box
.bottom
;
2445 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2447 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2451 UnionRect(&SelectBox
, &Icon
, &Label
);
2453 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2454 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2457 /* Fix the Box if necessary */
2460 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2461 else *lprcBox
= Box
;
2463 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2467 * DESCRIPTION: [INTERNAL]
2470 * [I] infoPtr : valid pointer to the listview structure
2471 * [I] nItem : item number
2472 * [O] lprcBox : ptr to Box rectangle
2477 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2479 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2480 POINT Position
, Origin
;
2483 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2484 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2486 /* Be smart and try to figure out the minimum we have to do */
2488 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2489 lvItem
.mask
|= LVIF_TEXT
;
2490 lvItem
.iItem
= nItem
;
2491 lvItem
.iSubItem
= 0;
2492 lvItem
.pszText
= szDispText
;
2493 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2494 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2495 if (infoPtr
->uView
== LV_VIEW_ICON
)
2497 lvItem
.mask
|= LVIF_STATE
;
2498 lvItem
.stateMask
= LVIS_FOCUSED
;
2499 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2501 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2503 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2504 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2506 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2509 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2512 /* LISTVIEW_MapIdToIndex helper */
2513 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2515 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2516 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2518 if (id1
->id
== id2
->id
) return 0;
2520 return (id1
->id
< id2
->id
) ? -1 : 1;
2525 * Returns the item index for id specified.
2528 * [I] infoPtr : valid pointer to the listview structure
2529 * [I] iID : item id to get index for
2532 * Item index, or -1 on failure.
2534 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2539 TRACE("iID=%d\n", iID
);
2541 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2542 if (infoPtr
->nItemCount
== 0) return -1;
2545 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, &MapIdSearchCompare
, 0, DPAS_SORTED
);
2549 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2550 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2558 * Returns the item id for index given.
2561 * [I] infoPtr : valid pointer to the listview structure
2562 * [I] iItem : item index to get id for
2567 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2572 TRACE("iItem=%d\n", iItem
);
2574 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2575 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2577 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2578 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2580 return lpItem
->id
->id
;
2585 * Returns the current icon position, and advances it along the top.
2586 * The returned position is not offset by Origin.
2589 * [I] infoPtr : valid pointer to the listview structure
2590 * [O] lpPos : will get the current icon position
2595 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2597 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2599 *lpPos
= infoPtr
->currIconPos
;
2601 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2602 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2604 infoPtr
->currIconPos
.x
= 0;
2605 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2611 * Returns the current icon position, and advances it down the left edge.
2612 * The returned position is not offset by Origin.
2615 * [I] infoPtr : valid pointer to the listview structure
2616 * [O] lpPos : will get the current icon position
2621 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2623 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2625 *lpPos
= infoPtr
->currIconPos
;
2627 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2628 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2630 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2631 infoPtr
->currIconPos
.y
= 0;
2637 * Moves an icon to the specified position.
2638 * It takes care of invalidating the item, etc.
2641 * [I] infoPtr : valid pointer to the listview structure
2642 * [I] nItem : the item to move
2643 * [I] lpPos : the new icon position
2644 * [I] isNew : flags the item as being new
2650 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2656 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2657 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2659 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2660 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2663 /* Allocating a POINTER for every item is too resource intensive,
2664 * so we'll keep the (x,y) in different arrays */
2665 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2666 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2668 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2675 * Arranges listview items in icon display mode.
2678 * [I] infoPtr : valid pointer to the listview structure
2679 * [I] nAlignCode : alignment code
2685 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2687 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2691 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2693 TRACE("nAlignCode=%d\n", nAlignCode
);
2695 if (nAlignCode
== LVA_DEFAULT
)
2697 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2698 else nAlignCode
= LVA_ALIGNTOP
;
2703 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2704 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2705 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2706 default: return FALSE
;
2709 infoPtr
->bAutoarrange
= TRUE
;
2710 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2711 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2713 next_pos(infoPtr
, &pos
);
2714 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2722 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2723 * For LVS_REPORT always returns empty rectangle.
2726 * [I] infoPtr : valid pointer to the listview structure
2727 * [O] lprcView : bounding rectangle
2733 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2737 SetRectEmpty(lprcView
);
2739 switch (infoPtr
->uView
)
2742 case LV_VIEW_SMALLICON
:
2743 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2745 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2746 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2747 lprcView
->right
= max(lprcView
->right
, x
);
2748 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2750 if (infoPtr
->nItemCount
> 0)
2752 lprcView
->right
+= infoPtr
->nItemWidth
;
2753 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2758 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2759 x
= infoPtr
->nItemCount
/ y
;
2760 if (infoPtr
->nItemCount
% y
) x
++;
2761 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2762 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2769 * Retrieves the bounding rectangle of all the items.
2772 * [I] infoPtr : valid pointer to the listview structure
2773 * [O] lprcView : bounding rectangle
2779 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2783 TRACE("(lprcView=%p)\n", lprcView
);
2785 if (!lprcView
) return FALSE
;
2787 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2789 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2791 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2792 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2795 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2802 * Retrieves the subitem pointer associated with the subitem index.
2805 * [I] hdpaSubItems : DPA handle for a specific item
2806 * [I] nSubItem : index of subitem
2809 * SUCCESS : subitem pointer
2812 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2814 SUBITEM_INFO
*lpSubItem
;
2817 /* we should binary search here if need be */
2818 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2820 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2821 if (lpSubItem
->iSubItem
== nSubItem
)
2831 * Calculates the desired item width.
2834 * [I] infoPtr : valid pointer to the listview structure
2837 * The desired item width.
2839 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2843 TRACE("uView=%d\n", infoPtr
->uView
);
2845 if (infoPtr
->uView
== LV_VIEW_ICON
)
2846 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2847 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2849 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2854 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2855 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2857 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2858 nItemWidth
= rcHeader
.right
;
2861 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2863 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2867 lvItem
.mask
= LVIF_TEXT
;
2868 lvItem
.iSubItem
= 0;
2870 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2873 lvItem
.pszText
= szDispText
;
2874 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2875 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2876 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2880 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2881 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2883 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2891 * Calculates the desired item height.
2894 * [I] infoPtr : valid pointer to the listview structure
2897 * The desired item height.
2899 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2903 TRACE("uView=%d\n", infoPtr
->uView
);
2905 if (infoPtr
->uView
== LV_VIEW_ICON
)
2906 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2909 nItemHeight
= infoPtr
->ntmHeight
;
2910 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
2912 if (infoPtr
->himlState
)
2913 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2914 if (infoPtr
->himlSmall
)
2915 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2916 if (infoPtr
->himlState
|| infoPtr
->himlSmall
)
2917 nItemHeight
+= HEIGHT_PADDING
;
2918 if (infoPtr
->nMeasureItemHeight
> 0)
2919 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2922 return max(nItemHeight
, 1);
2927 * Updates the width, and height of an item.
2930 * [I] infoPtr : valid pointer to the listview structure
2935 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2937 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2938 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2944 * Retrieves and saves important text metrics info for the current
2948 * [I] infoPtr : valid pointer to the listview structure
2951 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2953 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2954 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2955 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2959 if (GetTextMetricsW(hdc
, &tm
))
2961 infoPtr
->ntmHeight
= tm
.tmHeight
;
2962 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
2965 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
2966 infoPtr
->nEllipsisWidth
= sz
.cx
;
2968 SelectObject(hdc
, hOldFont
);
2969 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2971 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
2976 * A compare function for ranges
2979 * [I] range1 : pointer to range 1;
2980 * [I] range2 : pointer to range 2;
2984 * > 0 : if range 1 > range 2
2985 * < 0 : if range 2 > range 1
2986 * = 0 : if range intersects range 2
2988 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
2992 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
2994 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
2999 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3004 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
3006 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *func
, int line
)
3011 TRACE("*** Checking %s:%d:%s ***\n", func
, line
, desc
);
3013 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3014 ranges_dump(ranges
);
3015 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3017 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3018 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3019 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3021 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3022 assert (prev
->upper
<= curr
->lower
);
3023 assert (curr
->lower
< curr
->upper
);
3027 TRACE("--- Done checking---\n");
3030 static RANGES
ranges_create(int count
)
3032 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3033 if (!ranges
) return NULL
;
3034 ranges
->hdpa
= DPA_Create(count
);
3035 if (ranges
->hdpa
) return ranges
;
3040 static void ranges_clear(RANGES ranges
)
3044 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3045 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3046 DPA_DeleteAllPtrs(ranges
->hdpa
);
3050 static void ranges_destroy(RANGES ranges
)
3052 if (!ranges
) return;
3053 ranges_clear(ranges
);
3054 DPA_Destroy(ranges
->hdpa
);
3058 static RANGES
ranges_clone(RANGES ranges
)
3063 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3065 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3067 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3068 if (!newrng
) goto fail
;
3069 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3070 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3075 TRACE ("clone failed\n");
3076 ranges_destroy(clone
);
3080 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3084 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3085 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3090 static void ranges_dump(RANGES ranges
)
3094 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3095 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3098 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3100 RANGE srchrng
= { nItem
, nItem
+ 1 };
3102 TRACE("(nItem=%d)\n", nItem
);
3103 ranges_check(ranges
, "before contain");
3104 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3107 static INT
ranges_itemcount(RANGES ranges
)
3111 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3113 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3114 count
+= sel
->upper
- sel
->lower
;
3120 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3122 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3125 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3126 if (index
== -1) return TRUE
;
3128 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3130 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3131 if (chkrng
->lower
>= nItem
)
3132 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3133 if (chkrng
->upper
> nItem
)
3134 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3139 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3144 TRACE("(%s)\n", debugrange(&range
));
3145 ranges_check(ranges
, "before add");
3147 /* try find overlapping regions first */
3148 srchrgn
.lower
= range
.lower
- 1;
3149 srchrgn
.upper
= range
.upper
+ 1;
3150 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3156 TRACE("Adding new range\n");
3158 /* create the brand new range to insert */
3159 newrgn
= Alloc(sizeof(RANGE
));
3160 if(!newrgn
) goto fail
;
3163 /* figure out where to insert it */
3164 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3165 TRACE("index=%d\n", index
);
3166 if (index
== -1) index
= 0;
3168 /* and get it over with */
3169 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3177 RANGE
*chkrgn
, *mrgrgn
;
3178 INT fromindex
, mergeindex
;
3180 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3181 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3183 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3184 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3186 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3188 /* merge now common ranges */
3190 srchrgn
.lower
= chkrgn
->lower
- 1;
3191 srchrgn
.upper
= chkrgn
->upper
+ 1;
3195 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3196 if (mergeindex
== -1) break;
3197 if (mergeindex
== index
)
3199 fromindex
= index
+ 1;
3203 TRACE("Merge with index %i\n", mergeindex
);
3205 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3206 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3207 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3209 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3210 if (mergeindex
< index
) index
--;
3214 ranges_check(ranges
, "after add");
3218 ranges_check(ranges
, "failed add");
3222 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3227 TRACE("(%s)\n", debugrange(&range
));
3228 ranges_check(ranges
, "before del");
3230 /* we don't use DPAS_SORTED here, since we need *
3231 * to find the first overlapping range */
3232 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3235 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3237 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3239 /* case 1: Same range */
3240 if ( (chkrgn
->upper
== range
.upper
) &&
3241 (chkrgn
->lower
== range
.lower
) )
3243 DPA_DeletePtr(ranges
->hdpa
, index
);
3247 /* case 2: engulf */
3248 else if ( (chkrgn
->upper
<= range
.upper
) &&
3249 (chkrgn
->lower
>= range
.lower
) )
3251 DPA_DeletePtr(ranges
->hdpa
, index
);
3254 /* case 3: overlap upper */
3255 else if ( (chkrgn
->upper
<= range
.upper
) &&
3256 (chkrgn
->lower
< range
.lower
) )
3258 chkrgn
->upper
= range
.lower
;
3260 /* case 4: overlap lower */
3261 else if ( (chkrgn
->upper
> range
.upper
) &&
3262 (chkrgn
->lower
>= range
.lower
) )
3264 chkrgn
->lower
= range
.upper
;
3267 /* case 5: fully internal */
3272 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3273 newrgn
->lower
= chkrgn
->lower
;
3274 newrgn
->upper
= range
.lower
;
3275 chkrgn
->lower
= range
.upper
;
3276 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3284 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3287 ranges_check(ranges
, "after del");
3291 ranges_check(ranges
, "failed del");
3297 * Removes all selection ranges
3300 * [I] infoPtr : valid pointer to the listview structure
3301 * [I] toSkip : item range to skip removing the selection
3307 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3316 lvItem
.stateMask
= LVIS_SELECTED
;
3318 /* need to clone the DPA because callbacks can change it */
3319 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3320 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3321 while(iterator_next(&i
))
3322 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3323 /* note that the iterator destructor will free the cloned range */
3324 iterator_destroy(&i
);
3329 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3333 if (!(toSkip
= ranges_create(1))) return FALSE
;
3334 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3335 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3336 ranges_destroy(toSkip
);
3340 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3342 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3347 * Retrieves the number of items that are marked as selected.
3350 * [I] infoPtr : valid pointer to the listview structure
3353 * Number of items selected.
3355 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3357 INT nSelectedCount
= 0;
3359 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3362 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3364 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3369 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3371 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3372 return nSelectedCount
;
3377 * Manages the item focus.
3380 * [I] infoPtr : valid pointer to the listview structure
3381 * [I] nItem : item index
3384 * TRUE : focused item changed
3385 * FALSE : focused item has NOT changed
3387 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3389 INT oldFocus
= infoPtr
->nFocusedItem
;
3392 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3394 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3395 lvItem
.stateMask
= LVIS_FOCUSED
;
3396 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3398 return oldFocus
!= infoPtr
->nFocusedItem
;
3401 /* Helper function for LISTVIEW_ShiftIndices *only* */
3402 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3404 if (nShiftItem
< nItem
) return nShiftItem
;
3406 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3408 if (direction
> 0) return nShiftItem
+ direction
;
3410 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3415 * Updates the various indices after an item has been inserted or deleted.
3418 * [I] infoPtr : valid pointer to the listview structure
3419 * [I] nItem : item index
3420 * [I] direction : Direction of shift, +1 or -1.
3425 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3430 /* temporarily disable change notification while shifting items */
3431 bOldChange
= infoPtr
->bDoChangeNotify
;
3432 infoPtr
->bDoChangeNotify
= FALSE
;
3434 TRACE("Shifting %iu, %i steps\n", nItem
, direction
);
3436 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3438 assert(abs(direction
) == 1);
3440 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3442 nNewFocus
= shift_item(infoPtr
, infoPtr
->nFocusedItem
, nItem
, direction
);
3443 if (nNewFocus
!= infoPtr
->nFocusedItem
)
3444 LISTVIEW_SetItemFocus(infoPtr
, nNewFocus
);
3446 /* But we are not supposed to modify nHotItem! */
3448 infoPtr
->bDoChangeNotify
= bOldChange
;
3454 * Adds a block of selections.
3457 * [I] infoPtr : valid pointer to the listview structure
3458 * [I] nItem : item index
3461 * Whether the window is still valid.
3463 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3465 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3466 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3467 HWND hwndSelf
= infoPtr
->hwndSelf
;
3468 NMLVODSTATECHANGE nmlv
;
3473 /* Temporarily disable change notification
3474 * If the control is LVS_OWNERDATA, we need to send
3475 * only one LVN_ODSTATECHANGED notification.
3476 * See MSDN documentation for LVN_ITEMCHANGED.
3478 bOldChange
= infoPtr
->bDoChangeNotify
;
3479 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3481 if (nFirst
== -1) nFirst
= nItem
;
3483 item
.state
= LVIS_SELECTED
;
3484 item
.stateMask
= LVIS_SELECTED
;
3486 for (i
= nFirst
; i
<= nLast
; i
++)
3487 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3489 ZeroMemory(&nmlv
, sizeof(nmlv
));
3490 nmlv
.iFrom
= nFirst
;
3493 nmlv
.uOldState
= item
.state
;
3495 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3496 if (!IsWindow(hwndSelf
))
3498 infoPtr
->bDoChangeNotify
= bOldChange
;
3505 * Sets a single group selection.
3508 * [I] infoPtr : valid pointer to the listview structure
3509 * [I] nItem : item index
3514 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3521 if (!(selection
= ranges_create(100))) return;
3523 item
.state
= LVIS_SELECTED
;
3524 item
.stateMask
= LVIS_SELECTED
;
3526 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3528 if (infoPtr
->nSelectionMark
== -1)
3530 infoPtr
->nSelectionMark
= nItem
;
3531 ranges_additem(selection
, nItem
);
3537 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3538 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3539 ranges_add(selection
, sel
);
3544 RECT rcItem
, rcSel
, rcSelMark
;
3547 rcItem
.left
= LVIR_BOUNDS
;
3548 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return;
3549 rcSelMark
.left
= LVIR_BOUNDS
;
3550 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) return;
3551 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3552 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3553 while(iterator_next(&i
))
3555 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3556 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3558 iterator_destroy(&i
);
3561 /* disable per item notifications on LVS_OWNERDATA style
3562 FIXME: single LVN_ODSTATECHANGED should be used */
3563 bOldChange
= infoPtr
->bDoChangeNotify
;
3564 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3566 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3569 iterator_rangesitems(&i
, selection
);
3570 while(iterator_next(&i
))
3571 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3572 /* this will also destroy the selection */
3573 iterator_destroy(&i
);
3575 infoPtr
->bDoChangeNotify
= bOldChange
;
3577 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3582 * Sets a single selection.
3585 * [I] infoPtr : valid pointer to the listview structure
3586 * [I] nItem : item index
3591 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3595 TRACE("nItem=%d\n", nItem
);
3597 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3599 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3600 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3601 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3603 infoPtr
->nSelectionMark
= nItem
;
3608 * Set selection(s) with keyboard.
3611 * [I] infoPtr : valid pointer to the listview structure
3612 * [I] nItem : item index
3613 * [I] space : VK_SPACE code sent
3616 * SUCCESS : TRUE (needs to be repainted)
3617 * FAILURE : FALSE (nothing has changed)
3619 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3621 /* FIXME: pass in the state */
3622 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3623 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3624 BOOL bResult
= FALSE
;
3626 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3627 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3631 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3632 LISTVIEW_SetSelection(infoPtr
, nItem
);
3636 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3640 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3641 lvItem
.stateMask
= LVIS_SELECTED
;
3644 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3645 if (lvItem
.state
& LVIS_SELECTED
)
3646 infoPtr
->nSelectionMark
= nItem
;
3648 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3651 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3654 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3658 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3660 LVHITTESTINFO lvHitTestInfo
;
3662 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3663 lvHitTestInfo
.pt
.x
= pt
.x
;
3664 lvHitTestInfo
.pt
.y
= pt
.y
;
3666 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3668 lpLVItem
->mask
= LVIF_PARAM
;
3669 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3670 lpLVItem
->iSubItem
= 0;
3672 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3675 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3677 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3678 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3679 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3684 * Called when the mouse is being actively tracked and has hovered for a specified
3688 * [I] infoPtr : valid pointer to the listview structure
3689 * [I] fwKeys : key indicator
3690 * [I] x,y : mouse position
3693 * 0 if the message was processed, non-zero if there was an error
3696 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3697 * over the item for a certain period of time.
3700 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3704 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3706 if (LISTVIEW_IsHotTracking(infoPtr
))
3714 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3715 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3717 SetFocus(infoPtr
->hwndSelf
);
3723 #define SCROLL_LEFT 0x1
3724 #define SCROLL_RIGHT 0x2
3725 #define SCROLL_UP 0x4
3726 #define SCROLL_DOWN 0x8
3730 * Utility routine to draw and highlight items within a marquee selection rectangle.
3733 * [I] infoPtr : valid pointer to the listview structure
3734 * [I] coords_orig : original co-ordinates of the cursor
3735 * [I] coords_offs : offsetted coordinates of the cursor
3736 * [I] offset : offset amount
3737 * [I] scroll : Bitmask of which directions we should scroll, if at all
3742 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3743 const POINT
*coords_offs
, const POINT
*offset
,
3746 BOOL controlDown
= FALSE
;
3751 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3753 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3754 rect
.right
= coords_offs
->x
;
3758 rect
.left
= coords_offs
->x
;
3759 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3762 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3764 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3765 rect
.bottom
= coords_offs
->y
;
3769 rect
.top
= coords_offs
->y
;
3770 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3773 /* Cancel out the old marquee rectangle and draw the new one */
3774 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3776 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3777 the cursor is further away */
3779 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3780 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3782 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3783 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3785 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3786 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3788 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3789 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3791 /* Invert the items in the old marquee rectangle */
3792 iterator_frameditems_absolute(&i
, infoPtr
, &infoPtr
->marqueeRect
);
3794 while (iterator_next(&i
))
3798 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3801 item
.state
= LVIS_SELECTED
;
3803 item
.stateMask
= LVIS_SELECTED
;
3805 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3809 iterator_destroy(&i
);
3811 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3813 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3814 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3816 /* Iterate over the items within our marquee rectangle */
3817 iterator_frameditems_absolute(&i
, infoPtr
, &infoPtr
->marqueeRect
);
3819 if (GetKeyState(VK_CONTROL
) & 0x8000)
3822 while (iterator_next(&i
))
3826 /* If CTRL is pressed, invert. If not, always select the item. */
3827 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
)))
3830 item
.state
= LVIS_SELECTED
;
3832 item
.stateMask
= LVIS_SELECTED
;
3834 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3838 iterator_destroy(&i
);
3839 LISTVIEW_InvalidateRect(infoPtr
, &rect
);
3844 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3845 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3848 * [I] hwnd : Handle to the listview
3849 * [I] uMsg : WM_TIMER (ignored)
3850 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3851 * [I] dwTimer : The elapsed time (ignored)
3856 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3858 LISTVIEW_INFO
*infoPtr
;
3859 SCROLLINFO scrollInfo
;
3865 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3870 /* Get the current cursor position and convert to client coordinates */
3871 GetCursorPos(&coords_orig
);
3872 ScreenToClient(hWnd
, &coords_orig
);
3874 /* Ensure coordinates are within client bounds */
3875 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3876 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3879 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3881 /* Offset coordinates by the appropriate amount */
3882 coords_offs
.x
-= offset
.x
;
3883 coords_offs
.y
-= offset
.y
;
3885 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3886 scrollInfo
.fMask
= SIF_ALL
;
3888 /* Work out in which directions we can scroll */
3889 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3891 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3892 scroll
|= SCROLL_UP
;
3894 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3895 scroll
|= SCROLL_DOWN
;
3898 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3900 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3901 scroll
|= SCROLL_LEFT
;
3903 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3904 scroll
|= SCROLL_RIGHT
;
3907 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3908 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3909 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3910 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3912 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3918 * Called whenever WM_MOUSEMOVE is received.
3921 * [I] infoPtr : valid pointer to the listview structure
3922 * [I] fwKeys : key indicator
3923 * [I] x,y : mouse position
3926 * 0 if the message is processed, non-zero if there was an error
3928 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3930 if (!(fwKeys
& MK_LBUTTON
))
3931 infoPtr
->bLButtonDown
= FALSE
;
3933 if (infoPtr
->bLButtonDown
)
3937 LVHITTESTINFO lvHitTestInfo
;
3938 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3939 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3941 if (infoPtr
->bMarqueeSelect
)
3951 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3953 /* Ensure coordinates are within client bounds */
3954 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
3955 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
3957 /* Offset coordinates by the appropriate amount */
3958 coords_offs
.x
-= offset
.x
;
3959 coords_offs
.y
-= offset
.y
;
3961 /* Enable the timer if we're going outside our bounds, in case the user doesn't
3962 move the mouse again */
3964 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
3965 (y
>= infoPtr
->rcList
.bottom
))
3967 if (!infoPtr
->bScrolling
)
3969 infoPtr
->bScrolling
= TRUE
;
3970 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
3975 infoPtr
->bScrolling
= FALSE
;
3976 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
3979 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
3983 rect
.left
= infoPtr
->ptClickPos
.x
- wDragWidth
;
3984 rect
.right
= infoPtr
->ptClickPos
.x
+ wDragWidth
;
3985 rect
.top
= infoPtr
->ptClickPos
.y
- wDragHeight
;
3986 rect
.bottom
= infoPtr
->ptClickPos
.y
+ wDragHeight
;
3991 lvHitTestInfo
.pt
= tmp
;
3992 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
3994 /* reset item marker */
3995 if (infoPtr
->nLButtonDownItem
!= lvHitTestInfo
.iItem
)
3996 infoPtr
->nLButtonDownItem
= -1;
3998 if (!PtInRect(&rect
, tmp
))
4000 /* this path covers the following:
4001 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4002 2. change focus with keys
4003 3. move mouse over item from step 1 selects it and moves focus on it */
4004 if (infoPtr
->nLButtonDownItem
!= -1 &&
4005 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4009 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4010 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4012 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4013 infoPtr
->nLButtonDownItem
= -1;
4016 if (!infoPtr
->bDragging
)
4018 lvHitTestInfo
.pt
= infoPtr
->ptClickPos
;
4019 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
4021 /* If the click is outside the range of an item, begin a
4022 highlight. If not, begin an item drag. */
4023 if (lvHitTestInfo
.iItem
== -1)
4027 /* If we're allowing multiple selections, send notification.
4028 If return value is non-zero, cancel. */
4029 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4031 /* Store the absolute coordinates of the click */
4033 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4035 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4036 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4038 /* Begin selection and capture mouse */
4039 infoPtr
->bMarqueeSelect
= TRUE
;
4040 SetCapture(infoPtr
->hwndSelf
);
4047 ZeroMemory(&nmlv
, sizeof(nmlv
));
4048 nmlv
.iItem
= lvHitTestInfo
.iItem
;
4049 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4051 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4052 infoPtr
->bDragging
= TRUE
;
4060 /* see if we are supposed to be tracking mouse hovering */
4061 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4062 TRACKMOUSEEVENT trackinfo
;
4064 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4065 trackinfo
.dwFlags
= TME_QUERY
;
4067 /* see if we are already tracking this hwnd */
4068 _TrackMouseEvent(&trackinfo
);
4070 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4071 trackinfo
.dwFlags
= TME_HOVER
;
4072 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4073 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4075 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4076 _TrackMouseEvent(&trackinfo
);
4085 * Tests whether the item is assignable to a list with style lStyle
4087 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4089 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4090 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4091 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4099 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
4102 * [I] infoPtr : valid pointer to the listview structure
4103 * [I] lpLVItem : valid pointer to new item attributes
4104 * [I] isNew : the item being set is being inserted
4105 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4106 * [O] bChanged : will be set to TRUE if the item really changed
4112 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4118 /* stateMask is ignored for LVM_INSERTITEM */
4119 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4123 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4125 if (lpLVItem
->mask
== 0) return TRUE
;
4127 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4129 /* a virtual listview only stores selection and focus */
4130 if (lpLVItem
->mask
& ~LVIF_STATE
)
4136 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4137 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4141 /* we need to get the lParam and state of the item */
4142 item
.iItem
= lpLVItem
->iItem
;
4143 item
.iSubItem
= lpLVItem
->iSubItem
;
4144 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4145 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4149 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4151 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4152 /* determine what fields will change */
4153 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4154 uChanged
|= LVIF_STATE
;
4156 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4157 uChanged
|= LVIF_IMAGE
;
4159 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4160 uChanged
|= LVIF_PARAM
;
4162 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4163 uChanged
|= LVIF_INDENT
;
4165 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4166 uChanged
|= LVIF_TEXT
;
4168 TRACE("uChanged=0x%x\n", uChanged
);
4169 if (!uChanged
) return TRUE
;
4172 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
4173 nmlv
.iItem
= lpLVItem
->iItem
;
4174 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4175 nmlv
.uOldState
= item
.state
;
4176 nmlv
.uChanged
= uChanged
;
4177 nmlv
.lParam
= item
.lParam
;
4179 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
4180 /* and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications */
4182 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4184 HWND hwndSelf
= infoPtr
->hwndSelf
;
4186 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4188 if (!IsWindow(hwndSelf
))
4192 /* copy information */
4193 if (lpLVItem
->mask
& LVIF_TEXT
)
4194 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4196 if (lpLVItem
->mask
& LVIF_IMAGE
)
4197 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4199 if (lpLVItem
->mask
& LVIF_PARAM
)
4200 lpItem
->lParam
= lpLVItem
->lParam
;
4202 if (lpLVItem
->mask
& LVIF_INDENT
)
4203 lpItem
->iIndent
= lpLVItem
->iIndent
;
4205 if (uChanged
& LVIF_STATE
)
4207 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4209 lpItem
->state
&= ~stateMask
;
4210 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4212 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4214 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4215 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4217 else if (stateMask
& LVIS_SELECTED
)
4219 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4221 /* if we are asked to change focus, and we manage it, do it */
4222 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4224 if (lpLVItem
->state
& LVIS_FOCUSED
)
4226 if (infoPtr
->nFocusedItem
!= -1)
4228 /* remove current focus */
4229 item
.mask
= LVIF_STATE
;
4231 item
.stateMask
= LVIS_FOCUSED
;
4233 /* recurse with redrawing an item */
4234 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4237 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4238 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4240 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4242 infoPtr
->nFocusedItem
= -1;
4247 /* if we're inserting the item, we're done */
4248 if (isNew
) return TRUE
;
4250 /* send LVN_ITEMCHANGED notification */
4251 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4252 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4259 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4262 * [I] infoPtr : valid pointer to the listview structure
4263 * [I] lpLVItem : valid pointer to new subitem attributes
4264 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4265 * [O] bChanged : will be set to TRUE if the item really changed
4271 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4274 SUBITEM_INFO
*lpSubItem
;
4276 /* we do not support subitems for virtual listviews */
4277 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4279 /* set subitem only if column is present */
4280 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4282 /* First do some sanity checks */
4283 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4284 particularly useful. We currently do not actually do anything with
4285 the flag on subitems.
4287 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
)) return FALSE
;
4288 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4290 /* get the subitem structure, and create it if not there */
4291 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4292 assert (hdpaSubItems
);
4294 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4297 SUBITEM_INFO
*tmpSubItem
;
4300 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4301 if (!lpSubItem
) return FALSE
;
4302 /* we could binary search here, if need be...*/
4303 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4305 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4306 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4308 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4313 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4314 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4318 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4320 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4324 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4326 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4335 * Sets item attributes.
4338 * [I] infoPtr : valid pointer to the listview structure
4339 * [I] lpLVItem : new item attributes
4340 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4346 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4348 HWND hwndSelf
= infoPtr
->hwndSelf
;
4349 LPWSTR pszText
= NULL
;
4350 BOOL bResult
, bChanged
= FALSE
;
4352 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4354 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4357 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4358 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4360 pszText
= lpLVItem
->pszText
;
4361 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4364 /* actually set the fields */
4365 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4367 if (lpLVItem
->iSubItem
)
4368 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4370 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4371 if (!IsWindow(hwndSelf
))
4374 /* redraw item, if necessary */
4375 if (bChanged
&& !infoPtr
->bIsDrawing
)
4377 /* this little optimization eliminates some nasty flicker */
4378 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4379 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4380 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4381 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4383 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4388 textfreeT(lpLVItem
->pszText
, isW
);
4389 lpLVItem
->pszText
= pszText
;
4397 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4400 * [I] infoPtr : valid pointer to the listview structure
4405 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4408 SCROLLINFO scrollInfo
;
4410 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4411 scrollInfo
.fMask
= SIF_POS
;
4413 if (infoPtr
->uView
== LV_VIEW_LIST
)
4415 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4416 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4418 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4420 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4421 nItem
= scrollInfo
.nPos
;
4425 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4426 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4429 TRACE("nItem=%d\n", nItem
);
4437 * Erases the background of the given rectangle
4440 * [I] infoPtr : valid pointer to the listview structure
4441 * [I] hdc : device context handle
4442 * [I] lprcBox : clipping rectangle
4448 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4450 if (!infoPtr
->hBkBrush
) return FALSE
;
4452 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4454 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4462 * [I] infoPtr : valid pointer to the listview structure
4463 * [I] hdc : device context handle
4464 * [I] nItem : item index
4465 * [I] nSubItem : subitem index
4466 * [I] pos : item position in client coordinates
4467 * [I] cdmode : custom draw mode
4473 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
4476 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4477 static WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4478 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4480 RECT rcSelect
, rcBox
, rcIcon
, rcLabel
, rcStateIcon
;
4481 NMLVCUSTOMDRAW nmlvcd
;
4486 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, wine_dbgstr_point(&pos
));
4488 /* get information needed for drawing the item */
4489 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
4490 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
;
4491 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4492 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
;
4493 lvItem
.iItem
= nItem
;
4494 lvItem
.iSubItem
= nSubItem
;
4497 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4498 lvItem
.pszText
= szDispText
;
4499 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4500 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4501 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4502 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
4503 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4505 /* now check if we need to update the focus rectangle */
4506 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4508 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4509 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4510 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4511 OffsetRect(&rcSelect
, pos
.x
, pos
.y
);
4512 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
4513 OffsetRect(&rcStateIcon
, pos
.x
, pos
.y
);
4514 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
4515 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4516 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4517 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4519 /* fill in the custom draw structure */
4520 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4522 hOldFont
= GetCurrentObject(hdc
, OBJ_FONT
);
4523 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
4524 if (cdmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4525 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4526 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4527 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
4528 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4529 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
4530 if (nSubItem
== 0 && cdsubitemmode
== CDRF_NOTIFYITEMDRAW
)
4532 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4533 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4535 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4536 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4537 else if ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) == FALSE
)
4538 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4540 /* in full row select, subitems, will just use main item's colors */
4541 if (nSubItem
&& infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4542 nmlvcd
.clrTextBk
= CLR_NONE
;
4544 /* FIXME: temporary hack */
4545 rcSelect
.left
= rcLabel
.left
;
4547 /* draw the selection background, if we're drawing the main item */
4550 /* in icon mode, the label rect is really what we want to draw the
4552 if (infoPtr
->uView
== LV_VIEW_ICON
)
4555 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4557 /* we have to update left focus bound too if item isn't in leftmost column
4558 and reduce right box bound */
4559 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4563 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4565 INT Originx
= pos
.x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4566 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4567 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4569 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4570 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4574 rcSelect
.right
= rcBox
.right
;
4577 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
4578 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4579 /* store new focus rectangle */
4580 if (infoPtr
->nFocusedItem
== nItem
) infoPtr
->rcFocus
= rcSelect
;
4584 if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && (nSubItem
== 0))
4586 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
4589 TRACE("uStateImage=%d\n", uStateImage
);
4590 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
,
4591 rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4596 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4597 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4601 TRACE("iImage=%d\n", lvItem
.iImage
);
4603 if (lvItem
.state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4604 style
= ILD_SELECTED
;
4608 ImageList_DrawEx(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
4609 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4610 lvItem
.state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4614 /* Don't bother painting item being edited */
4615 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
4617 /* figure out the text drawing flags */
4618 uFormat
= (infoPtr
->uView
== LV_VIEW_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4619 if (infoPtr
->uView
== LV_VIEW_ICON
)
4620 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4623 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4625 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
4626 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
4627 default: uFormat
|= DT_LEFT
;
4630 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
4632 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4633 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4635 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4637 /* for GRIDLINES reduce the bottom so the text formats correctly */
4638 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4641 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
4644 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4645 notify_postpaint(infoPtr
, &nmlvcd
);
4646 if (cdsubitemmode
& CDRF_NEWFONT
)
4647 SelectObject(hdc
, hOldFont
);
4653 * Draws listview items when in owner draw mode.
4656 * [I] infoPtr : valid pointer to the listview structure
4657 * [I] hdc : device context handle
4662 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4664 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4665 DWORD cditemmode
= CDRF_DODEFAULT
;
4666 NMLVCUSTOMDRAW nmlvcd
;
4667 POINT Origin
, Position
;
4673 ZeroMemory(&dis
, sizeof(dis
));
4675 /* Get scroll info once before loop */
4676 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4678 /* iterate through the invalidated rows */
4679 while(iterator_next(i
))
4681 item
.iItem
= i
->nItem
;
4683 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4684 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4685 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4687 dis
.CtlType
= ODT_LISTVIEW
;
4689 dis
.itemID
= item
.iItem
;
4690 dis
.itemAction
= ODA_DRAWENTIRE
;
4692 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4693 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4694 dis
.hwndItem
= infoPtr
->hwndSelf
;
4696 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4697 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4698 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4699 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4700 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4701 dis
.itemData
= item
.lParam
;
4703 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4706 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4707 * structure for the rest. of the paint cycle
4709 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4710 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4711 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4713 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4715 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4716 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4719 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4720 notify_postpaint(infoPtr
, &nmlvcd
);
4726 * Draws listview items when in report display mode.
4729 * [I] infoPtr : valid pointer to the listview structure
4730 * [I] hdc : device context handle
4731 * [I] cdmode : custom draw mode
4736 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4739 RECT rcClip
, rcItem
;
4740 POINT Origin
, Position
;
4747 /* figure out what to draw */
4748 rgntype
= GetClipBox(hdc
, &rcClip
);
4749 if (rgntype
== NULLREGION
) return;
4751 /* Get scroll info once before loop */
4752 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4754 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4756 /* narrow down the columns we need to paint */
4757 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4759 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4761 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4762 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4763 ranges_additem(colRanges
, index
);
4765 iterator_rangesitems(&j
, colRanges
);
4767 /* in full row select, we _have_ to draw the main item */
4768 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4771 /* iterate through the invalidated rows */
4772 while(iterator_next(i
))
4774 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4775 Position
.y
+= Origin
.y
;
4777 /* iterate through the invalidated columns */
4778 while(iterator_next(&j
))
4780 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4781 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4783 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4786 rcItem
.bottom
= infoPtr
->nItemHeight
;
4787 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4788 if (!RectVisible(hdc
, &rcItem
)) continue;
4791 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
4794 iterator_destroy(&j
);
4799 * Draws the gridlines if necessary when in report display mode.
4802 * [I] infoPtr : valid pointer to the listview structure
4803 * [I] hdc : device context handle
4808 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4814 RECT rcClip
, rcItem
= {0};
4822 /* figure out what to draw */
4823 rgntype
= GetClipBox(hdc
, &rcClip
);
4824 if (rgntype
== NULLREGION
) return;
4826 /* Get scroll info once before loop */
4827 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4829 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4831 /* narrow down the columns we need to paint */
4832 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4834 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4836 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4837 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4838 ranges_additem(colRanges
, index
);
4841 /* is right most vertical line visible? */
4842 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4844 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4845 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4846 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
4849 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
4851 hOldPen
= SelectObject ( hdc
, hPen
);
4853 /* draw the vertical lines for the columns */
4854 iterator_rangesitems(&j
, colRanges
);
4855 while(iterator_next(&j
))
4857 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4858 if (rcItem
.left
== 0) continue; /* skip leftmost column */
4859 rcItem
.left
+= Origin
.x
;
4860 rcItem
.right
+= Origin
.x
;
4861 rcItem
.top
= infoPtr
->rcList
.top
;
4862 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
4863 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
4864 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4865 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
4867 iterator_destroy(&j
);
4868 /* draw rightmost grid line if visible */
4871 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4872 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4873 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4875 rcItem
.right
+= Origin
.x
;
4877 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
4878 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
4881 /* draw the horizontial lines for the rows */
4882 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
4883 rcItem
.left
= infoPtr
->rcList
.left
;
4884 rcItem
.right
= infoPtr
->rcList
.right
;
4885 rcItem
.bottom
= rcItem
.top
= Origin
.y
- 1;
4886 MoveToEx(hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4887 LineTo(hdc
, rcItem
.right
, rcItem
.top
);
4888 for(y
=itemheight
-1+Origin
.y
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
4890 rcItem
.bottom
= rcItem
.top
= y
;
4891 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
4892 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4893 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
4896 SelectObject( hdc
, hOldPen
);
4897 DeleteObject( hPen
);
4903 * Draws listview items when in list display mode.
4906 * [I] infoPtr : valid pointer to the listview structure
4907 * [I] hdc : device context handle
4908 * [I] cdmode : custom draw mode
4913 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4915 POINT Origin
, Position
;
4917 /* Get scroll info once before loop */
4918 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4920 while(iterator_prev(i
))
4922 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4923 Position
.x
+= Origin
.x
;
4924 Position
.y
+= Origin
.y
;
4926 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
4933 * Draws listview items.
4936 * [I] infoPtr : valid pointer to the listview structure
4937 * [I] hdc : device context handle
4938 * [I] prcErase : rect to be erased before refresh (may be NULL)
4943 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
4945 COLORREF oldTextColor
= 0, oldBkColor
= 0, oldClrTextBk
, oldClrText
;
4946 NMLVCUSTOMDRAW nmlvcd
;
4953 HBITMAP hbmp
= NULL
;
4956 LISTVIEW_DUMP(infoPtr
);
4958 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4959 TRACE("double buffering\n");
4961 hdc
= CreateCompatibleDC(hdcOrig
);
4963 ERR("Failed to create DC for backbuffer\n");
4966 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
4967 infoPtr
->rcList
.bottom
);
4969 ERR("Failed to create bitmap for backbuffer\n");
4974 SelectObject(hdc
, hbmp
);
4975 SelectObject(hdc
, infoPtr
->hFont
);
4977 /* Save dc values we're gonna trash while drawing
4978 * FIXME: Should be done in LISTVIEW_DrawItem() */
4979 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4980 oldBkMode
= GetBkMode(hdc
);
4981 oldBkColor
= GetBkColor(hdc
);
4982 oldTextColor
= GetTextColor(hdc
);
4985 infoPtr
->bIsDrawing
= TRUE
;
4988 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
4989 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4990 /* If no erasing was done (usually because RedrawWindow was called
4991 * with RDW_INVALIDATE only) we need to copy the old contents into
4992 * the backbuffer before continuing. */
4993 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
4994 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
4995 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
4996 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
4999 /* FIXME: Shouldn't need to do this */
5000 oldClrTextBk
= infoPtr
->clrTextBk
;
5001 oldClrText
= infoPtr
->clrText
;
5003 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
5005 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5006 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5007 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5008 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5009 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
5011 /* Use these colors to draw the items */
5012 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
5013 infoPtr
->clrText
= nmlvcd
.clrText
;
5015 /* nothing to draw */
5016 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5018 /* figure out what we need to draw */
5019 iterator_visibleitems(&i
, infoPtr
, hdc
);
5020 range
= iterator_range(&i
);
5022 /* send cache hint notification */
5023 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5027 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5028 nmlv
.iFrom
= range
.lower
;
5029 nmlv
.iTo
= range
.upper
- 1;
5030 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5033 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5034 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5037 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5038 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5039 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5040 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5042 /* if we have a focus rect and it's visible, draw it */
5043 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5044 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5045 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5047 iterator_destroy(&i
);
5050 /* For LVS_EX_GRIDLINES go and draw lines */
5051 /* This includes the case where there were *no* items */
5052 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5053 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5055 /* Draw marquee rectangle if appropriate */
5056 if (infoPtr
->bMarqueeSelect
)
5058 SetBkColor(hdc
, RGB(255, 255, 255));
5059 SetTextColor(hdc
, RGB(0, 0, 0));
5060 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5063 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5064 notify_postpaint(infoPtr
, &nmlvcd
);
5066 infoPtr
->clrTextBk
= oldClrTextBk
;
5067 infoPtr
->clrText
= oldClrText
;
5070 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5071 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5072 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5073 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5078 SelectObject(hdc
, hOldFont
);
5079 SetBkMode(hdc
, oldBkMode
);
5080 SetBkColor(hdc
, oldBkColor
);
5081 SetTextColor(hdc
, oldTextColor
);
5084 infoPtr
->bIsDrawing
= FALSE
;
5090 * Calculates the approximate width and height of a given number of items.
5093 * [I] infoPtr : valid pointer to the listview structure
5094 * [I] nItemCount : number of items
5095 * [I] wWidth : width
5096 * [I] wHeight : height
5099 * Returns a DWORD. The width in the low word and the height in high word.
5101 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5102 WORD wWidth
, WORD wHeight
)
5104 DWORD dwViewRect
= 0;
5106 if (nItemCount
== -1)
5107 nItemCount
= infoPtr
->nItemCount
;
5109 if (infoPtr
->uView
== LV_VIEW_LIST
)
5111 INT nItemCountPerColumn
= 1;
5112 INT nColumnCount
= 0;
5114 if (wHeight
== 0xFFFF)
5116 /* use current height */
5117 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5120 if (wHeight
< infoPtr
->nItemHeight
)
5121 wHeight
= infoPtr
->nItemHeight
;
5125 if (infoPtr
->nItemHeight
> 0)
5127 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5128 if (nItemCountPerColumn
== 0)
5129 nItemCountPerColumn
= 1;
5131 if (nItemCount
% nItemCountPerColumn
!= 0)
5132 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5134 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5138 /* Microsoft padding magic */
5139 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5140 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5142 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5144 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5148 if (infoPtr
->nItemCount
> 0)
5150 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5151 wWidth
= rcBox
.right
- rcBox
.left
;
5152 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5156 /* use current height and width */
5157 if (wHeight
== 0xffff)
5158 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5159 if (wWidth
== 0xffff)
5160 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5163 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5165 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5171 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5172 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5174 if (wWidth
== 0xffff)
5175 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5177 if (wWidth
< nItemWidth
)
5178 wWidth
= nItemWidth
;
5180 cols
= wWidth
/ nItemWidth
;
5181 if (cols
> nItemCount
)
5188 rows
= nItemCount
/ cols
;
5189 if (nItemCount
% cols
)
5195 wHeight
= (nItemHeight
* rows
)+2;
5196 wWidth
= (nItemWidth
* cols
)+2;
5198 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5200 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5201 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5208 * Cancel edit label with saving item text.
5211 * [I] infoPtr : valid pointer to the listview structure
5214 * Always returns TRUE.
5216 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5218 if (infoPtr
->hwndEdit
)
5220 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5221 HWND edit
= infoPtr
->hwndEdit
;
5223 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5224 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5232 * Create a drag image list for the specified item.
5235 * [I] infoPtr : valid pointer to the listview structure
5236 * [I] iItem : index of item
5237 * [O] lppt : Upper-left corner of the image
5240 * Returns a handle to the image list if successful, NULL otherwise.
5242 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5248 HBITMAP hbmp
, hOldbmp
;
5249 HIMAGELIST dragList
= 0;
5250 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5252 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5255 rcItem
.left
= LVIR_BOUNDS
;
5256 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5259 lppt
->x
= rcItem
.left
;
5260 lppt
->y
= rcItem
.top
;
5262 size
.cx
= rcItem
.right
- rcItem
.left
;
5263 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5265 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5266 hdc
= CreateCompatibleDC(hdcOrig
);
5267 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5268 hOldbmp
= SelectObject(hdc
, hbmp
);
5270 rcItem
.left
= rcItem
.top
= 0;
5271 rcItem
.right
= size
.cx
;
5272 rcItem
.bottom
= size
.cy
;
5273 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5276 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
5278 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5279 SelectObject(hdc
, hOldbmp
);
5280 ImageList_Add(dragList
, hbmp
, 0);
5283 SelectObject(hdc
, hOldbmp
);
5287 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5289 TRACE("ret=%p\n", dragList
);
5297 * Removes all listview items and subitems.
5300 * [I] infoPtr : valid pointer to the listview structure
5306 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5309 HDPA hdpaSubItems
= NULL
;
5318 /* we do it directly, to avoid notifications */
5319 ranges_clear(infoPtr
->selectionRanges
);
5320 infoPtr
->nSelectionMark
= -1;
5321 infoPtr
->nFocusedItem
= -1;
5322 SetRectEmpty(&infoPtr
->rcFocus
);
5323 /* But we are supposed to leave nHotItem as is! */
5326 /* send LVN_DELETEALLITEMS notification */
5327 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
5329 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5331 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5333 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5335 /* send LVN_DELETEITEM notification, if not suppressed
5336 and if it is not a virtual listview */
5337 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
5338 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5339 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5340 /* free id struct */
5341 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5342 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5343 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5345 /* both item and subitem start with ITEMHDR header */
5346 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5348 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5349 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5352 DPA_Destroy(hdpaSubItems
);
5353 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5355 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5356 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5357 infoPtr
->nItemCount
--;
5362 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5363 LISTVIEW_UpdateScroll(infoPtr
);
5365 LISTVIEW_InvalidateList(infoPtr
);
5372 * Scrolls, and updates the columns, when a column is changing width.
5375 * [I] infoPtr : valid pointer to the listview structure
5376 * [I] nColumn : column to scroll
5377 * [I] dx : amount of scroll, in pixels
5382 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5384 COLUMN_INFO
*lpColumnInfo
;
5390 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5391 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5392 rcCol
= lpColumnInfo
->rcHeader
;
5393 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5394 rcCol
.left
= rcCol
.right
;
5396 /* adjust the other columns */
5397 hdi
.mask
= HDI_ORDER
;
5398 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5400 INT nOrder
= hdi
.iOrder
;
5401 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5403 hdi
.mask
= HDI_ORDER
;
5404 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5405 if (hdi
.iOrder
>= nOrder
) {
5406 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5407 lpColumnInfo
->rcHeader
.left
+= dx
;
5408 lpColumnInfo
->rcHeader
.right
+= dx
;
5413 /* do not update screen if not in report mode */
5414 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5416 /* Need to reset the item width when inserting a new column */
5417 infoPtr
->nItemWidth
+= dx
;
5419 LISTVIEW_UpdateScroll(infoPtr
);
5420 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5422 /* scroll to cover the deleted column, and invalidate for redraw */
5423 rcOld
= infoPtr
->rcList
;
5424 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5425 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5430 * Removes a column from the listview control.
5433 * [I] infoPtr : valid pointer to the listview structure
5434 * [I] nColumn : column index
5440 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5444 TRACE("nColumn=%d\n", nColumn
);
5446 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5447 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5449 /* While the MSDN specifically says that column zero should not be deleted,
5450 what actually happens is that the column itself is deleted but no items or subitems
5454 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5456 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5459 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5460 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5462 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5464 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5466 INT nItem
, nSubItem
, i
;
5468 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5470 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5473 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5475 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5476 if (lpSubItem
->iSubItem
== nColumn
)
5479 lpDelItem
= lpSubItem
;
5481 else if (lpSubItem
->iSubItem
> nColumn
)
5483 lpSubItem
->iSubItem
--;
5487 /* if we found our subitem, zapp it */
5491 if (is_text(lpDelItem
->hdr
.pszText
))
5492 Free(lpDelItem
->hdr
.pszText
);
5497 /* free dpa memory */
5498 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5503 /* update the other column info */
5504 LISTVIEW_UpdateItemSize(infoPtr
);
5505 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5506 LISTVIEW_InvalidateList(infoPtr
);
5508 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5515 * Invalidates the listview after an item's insertion or deletion.
5518 * [I] infoPtr : valid pointer to the listview structure
5519 * [I] nItem : item index
5520 * [I] dir : -1 if deleting, 1 if inserting
5525 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5527 INT nPerCol
, nItemCol
, nItemRow
;
5531 /* if we don't refresh, what's the point of scrolling? */
5532 if (!is_redrawing(infoPtr
)) return;
5534 assert (abs(dir
) == 1);
5536 /* arrange icons if autoarrange is on */
5537 if (is_autoarrange(infoPtr
))
5539 BOOL arrange
= TRUE
;
5540 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5541 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5542 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5545 /* scrollbars need updating */
5546 LISTVIEW_UpdateScroll(infoPtr
);
5548 /* figure out the item's position */
5549 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5550 nPerCol
= infoPtr
->nItemCount
+ 1;
5551 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5552 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5553 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5556 nItemCol
= nItem
/ nPerCol
;
5557 nItemRow
= nItem
% nPerCol
;
5558 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5560 /* move the items below up a slot */
5561 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5562 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5563 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5564 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5565 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5566 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5567 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5569 TRACE("Scrolling rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5570 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5571 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5574 /* report has only that column, so we're done */
5575 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5577 /* now for LISTs, we have to deal with the columns to the right */
5578 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5580 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5581 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5582 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5583 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5584 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5585 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5590 * Removes an item from the listview control.
5593 * [I] infoPtr : valid pointer to the listview structure
5594 * [I] nItem : item index
5600 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5603 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5605 TRACE("(nItem=%d)\n", nItem
);
5607 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5609 /* remove selection, and focus */
5611 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5612 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5614 /* send LVN_DELETEITEM notification. */
5615 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5617 /* we need to do this here, because we'll be deleting stuff */
5619 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5621 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5629 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5630 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5632 /* free id struct */
5633 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5634 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5635 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5637 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5639 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5640 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5643 DPA_Destroy(hdpaSubItems
);
5648 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5649 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5652 infoPtr
->nItemCount
--;
5653 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5655 /* now is the invalidation fun */
5657 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5664 * Callback implementation for editlabel control
5667 * [I] infoPtr : valid pointer to the listview structure
5668 * [I] storeText : store edit box text as item text
5669 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5675 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5677 HWND hwndSelf
= infoPtr
->hwndSelf
;
5678 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5679 NMLVDISPINFOW dispInfo
;
5680 INT editedItem
= infoPtr
->nEditLabelItem
;
5682 WCHAR
*pszText
= NULL
;
5687 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5691 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5693 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5694 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5699 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5701 infoPtr
->nEditLabelItem
= -1;
5702 infoPtr
->hwndEdit
= 0;
5704 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5705 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5706 dispInfo
.item
.iItem
= editedItem
;
5707 dispInfo
.item
.iSubItem
= 0;
5708 dispInfo
.item
.stateMask
= ~0;
5709 dispInfo
.item
.pszText
= szDispText
;
5710 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5711 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5718 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5721 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5722 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5723 textfreeT(tmp
, FALSE
);
5726 /* add the text from the edit in */
5727 dispInfo
.item
.mask
|= LVIF_TEXT
;
5728 dispInfo
.item
.pszText
= bSame
? NULL
: pszText
;
5729 dispInfo
.item
.cchTextMax
= bSame
? 0 : textlenT(pszText
, isW
);
5731 /* Do we need to update the Item Text */
5732 if (!notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
))
5737 if (!IsWindow(hwndSelf
))
5742 if (!pszText
) return TRUE
;
5749 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5751 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5752 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5753 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5755 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5761 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5762 dispInfo
.item
.mask
= LVIF_TEXT
;
5763 dispInfo
.item
.iItem
= editedItem
;
5764 dispInfo
.item
.iSubItem
= 0;
5765 dispInfo
.item
.pszText
= pszText
;
5766 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5767 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5777 * Subclassed edit control windproc function
5780 * [I] hwnd : the edit window handle
5781 * [I] uMsg : the message that is to be processed
5782 * [I] wParam : first message parameter
5783 * [I] lParam : second message parameter
5784 * [I] isW : TRUE if input is Unicode
5789 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5791 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5794 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5795 hwnd
, uMsg
, wParam
, lParam
, isW
);
5800 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5804 WNDPROC editProc
= infoPtr
->EditWndProc
;
5805 infoPtr
->EditWndProc
= 0;
5806 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5807 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5811 if (VK_ESCAPE
== (INT
)wParam
)
5816 else if (VK_RETURN
== (INT
)wParam
)
5820 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5824 if (infoPtr
->hwndEdit
)
5825 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5827 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
5833 * Subclassed edit control Unicode windproc function
5836 * [I] hwnd : the edit window handle
5837 * [I] uMsg : the message that is to be processed
5838 * [I] wParam : first message parameter
5839 * [I] lParam : second message parameter
5843 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5845 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
5850 * Subclassed edit control ANSI windproc function
5853 * [I] hwnd : the edit window handle
5854 * [I] uMsg : the message that is to be processed
5855 * [I] wParam : first message parameter
5856 * [I] lParam : second message parameter
5860 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5862 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
5867 * Creates a subclassed edit control
5870 * [I] infoPtr : valid pointer to the listview structure
5871 * [I] text : initial text for the edit
5872 * [I] style : the window style
5873 * [I] isW : TRUE if input is Unicode
5877 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
5879 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
5880 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
5883 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
5885 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
5887 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5889 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5891 if (!hedit
) return 0;
5893 infoPtr
->EditWndProc
= (WNDPROC
)
5894 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
5895 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
5897 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
5898 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
5905 * Begin in place editing of specified list view item
5908 * [I] infoPtr : valid pointer to the listview structure
5909 * [I] nItem : item index
5910 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
5916 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
5918 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
5919 HWND hwndSelf
= infoPtr
->hwndSelf
;
5920 NMLVDISPINFOW dispInfo
;
5921 HFONT hOldFont
= NULL
;
5927 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
5929 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
5931 /* remove existing edit box */
5932 if (infoPtr
->hwndEdit
)
5934 SetFocus(infoPtr
->hwndSelf
);
5935 infoPtr
->hwndEdit
= 0;
5938 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5940 infoPtr
->nEditLabelItem
= nItem
;
5942 LISTVIEW_SetSelection(infoPtr
, nItem
);
5943 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
5944 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5946 rect
.left
= LVIR_LABEL
;
5947 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
5949 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5950 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5951 dispInfo
.item
.iItem
= nItem
;
5952 dispInfo
.item
.iSubItem
= 0;
5953 dispInfo
.item
.stateMask
= ~0;
5954 dispInfo
.item
.pszText
= disptextW
;
5955 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5956 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
5958 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
5959 if (!infoPtr
->hwndEdit
) return 0;
5961 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
5963 if (!IsWindow(hwndSelf
))
5965 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
5966 infoPtr
->hwndEdit
= 0;
5970 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
5972 /* position and display edit box */
5973 hdc
= GetDC(infoPtr
->hwndSelf
);
5975 /* select the font to get appropriate metric dimensions */
5977 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5979 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
5980 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
5981 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
5983 /* get string length in pixels */
5984 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
5986 /* add extra spacing for the next character */
5987 GetTextMetricsW(hdc
, &tm
);
5988 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
5991 SelectObject(hdc
, hOldFont
);
5993 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
5995 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
5998 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
5999 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6000 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6001 SetFocus(infoPtr
->hwndEdit
);
6002 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6003 return infoPtr
->hwndEdit
;
6009 * Ensures the specified item is visible, scrolling into view if necessary.
6012 * [I] infoPtr : valid pointer to the listview structure
6013 * [I] nItem : item index
6014 * [I] bPartial : partially or entirely visible
6020 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6022 INT nScrollPosHeight
= 0;
6023 INT nScrollPosWidth
= 0;
6024 INT nHorzAdjust
= 0;
6025 INT nVertAdjust
= 0;
6028 RECT rcItem
, rcTemp
;
6030 rcItem
.left
= LVIR_BOUNDS
;
6031 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6033 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6035 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6037 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6038 if (infoPtr
->uView
== LV_VIEW_LIST
)
6039 nScrollPosWidth
= infoPtr
->nItemWidth
;
6040 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6041 nScrollPosWidth
= 1;
6043 if (rcItem
.left
< infoPtr
->rcList
.left
)
6046 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6051 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6055 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6057 /* scroll up/down, but not in LVS_LIST mode */
6058 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6059 nScrollPosHeight
= infoPtr
->nItemHeight
;
6060 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6061 nScrollPosHeight
= 1;
6063 if (rcItem
.top
< infoPtr
->rcList
.top
)
6066 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6071 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6075 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6077 if (nScrollPosWidth
)
6079 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6080 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6081 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6084 if (nScrollPosHeight
)
6086 INT diff
= nVertDiff
/ nScrollPosHeight
;
6087 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6088 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6096 * Searches for an item with specific characteristics.
6099 * [I] hwnd : window handle
6100 * [I] nStart : base item index
6101 * [I] lpFindInfo : item information to look for
6104 * SUCCESS : index of item
6107 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6108 const LVFINDINFOW
*lpFindInfo
)
6110 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6111 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6112 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6113 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6114 POINT Position
, Destination
;
6117 /* Search in virtual listviews should be done by application, not by
6118 listview control, so we just send LVN_ODFINDITEMW and return the result */
6119 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6123 nmlv
.iStart
= nStart
;
6124 nmlv
.lvfi
= *lpFindInfo
;
6125 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6128 if (!lpFindInfo
|| nItem
< 0) return -1;
6131 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6132 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6134 lvItem
.mask
|= LVIF_TEXT
;
6135 lvItem
.pszText
= szDispText
;
6136 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6139 if (lpFindInfo
->flags
& LVFI_WRAP
)
6142 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6143 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6148 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6149 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6150 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6151 switch(lpFindInfo
->vkDirection
)
6153 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6154 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6155 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6156 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6157 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6158 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6159 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6161 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6162 Destination
.x
= rcArea
.right
;
6163 Destination
.y
= rcArea
.bottom
;
6165 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6169 else Destination
.x
= Destination
.y
= 0;
6171 /* if LVFI_PARAM is specified, all other flags are ignored */
6172 if (lpFindInfo
->flags
& LVFI_PARAM
)
6174 lvItem
.mask
|= LVIF_PARAM
;
6176 lvItem
.mask
&= ~LVIF_TEXT
;
6180 for (; nItem
< nLast
; nItem
++)
6182 lvItem
.iItem
= nItem
;
6183 lvItem
.iSubItem
= 0;
6184 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6186 if (lvItem
.mask
& LVIF_PARAM
)
6188 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6194 if (lvItem
.mask
& LVIF_TEXT
)
6196 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6198 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6199 if (!p
|| p
!= lvItem
.pszText
) continue;
6203 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6207 if (!bNearest
) return nItem
;
6209 /* This is very inefficient. To do a good job here,
6210 * we need a sorted array of (x,y) item positions */
6211 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6213 /* compute the distance^2 to the destination */
6214 xdist
= Destination
.x
- Position
.x
;
6215 ydist
= Destination
.y
- Position
.y
;
6216 dist
= xdist
* xdist
+ ydist
* ydist
;
6218 /* remember the distance, and item if it's closer */
6222 nNearestItem
= nItem
;
6229 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6234 return nNearestItem
;
6239 * Searches for an item with specific characteristics.
6242 * [I] hwnd : window handle
6243 * [I] nStart : base item index
6244 * [I] lpFindInfo : item information to look for
6247 * SUCCESS : index of item
6250 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6251 const LVFINDINFOA
*lpFindInfo
)
6253 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6254 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6259 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6260 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6261 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6262 textfreeT(strW
, FALSE
);
6268 * Retrieves column attributes.
6271 * [I] infoPtr : valid pointer to the listview structure
6272 * [I] nColumn : column index
6273 * [IO] lpColumn : column information
6274 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6275 * otherwise it is in fact a LPLVCOLUMNA
6281 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6283 COLUMN_INFO
*lpColumnInfo
;
6286 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6287 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6289 /* initialize memory */
6290 ZeroMemory(&hdi
, sizeof(hdi
));
6292 if (lpColumn
->mask
& LVCF_TEXT
)
6294 hdi
.mask
|= HDI_TEXT
;
6295 hdi
.pszText
= lpColumn
->pszText
;
6296 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6299 if (lpColumn
->mask
& LVCF_IMAGE
)
6300 hdi
.mask
|= HDI_IMAGE
;
6302 if (lpColumn
->mask
& LVCF_ORDER
)
6303 hdi
.mask
|= HDI_ORDER
;
6305 if (lpColumn
->mask
& LVCF_SUBITEM
)
6306 hdi
.mask
|= HDI_LPARAM
;
6308 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6310 if (lpColumn
->mask
& LVCF_FMT
)
6311 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6313 if (lpColumn
->mask
& LVCF_WIDTH
)
6314 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6316 if (lpColumn
->mask
& LVCF_IMAGE
)
6317 lpColumn
->iImage
= hdi
.iImage
;
6319 if (lpColumn
->mask
& LVCF_ORDER
)
6320 lpColumn
->iOrder
= hdi
.iOrder
;
6322 if (lpColumn
->mask
& LVCF_SUBITEM
)
6323 lpColumn
->iSubItem
= hdi
.lParam
;
6325 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6326 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6332 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6334 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
6339 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6344 * Retrieves the column width.
6347 * [I] infoPtr : valid pointer to the listview structure
6348 * [I] int : column index
6351 * SUCCESS : column width
6354 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6356 INT nColumnWidth
= 0;
6359 TRACE("nColumn=%d\n", nColumn
);
6361 /* we have a 'column' in LIST and REPORT mode only */
6362 switch(infoPtr
->uView
)
6365 nColumnWidth
= infoPtr
->nItemWidth
;
6367 case LV_VIEW_DETAILS
:
6368 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6369 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6370 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6372 * TODO: should we do the same in LVM_GETCOLUMN?
6374 hdItem
.mask
= HDI_WIDTH
;
6375 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6377 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6380 nColumnWidth
= hdItem
.cxy
;
6384 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6385 return nColumnWidth
;
6390 * In list or report display mode, retrieves the number of items that can fit
6391 * vertically in the visible area. In icon or small icon display mode,
6392 * retrieves the total number of visible items.
6395 * [I] infoPtr : valid pointer to the listview structure
6398 * Number of fully visible items.
6400 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6402 switch (infoPtr
->uView
)
6405 case LV_VIEW_SMALLICON
:
6406 return infoPtr
->nItemCount
;
6407 case LV_VIEW_DETAILS
:
6408 return LISTVIEW_GetCountPerColumn(infoPtr
);
6410 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6418 * Retrieves an image list handle.
6421 * [I] infoPtr : valid pointer to the listview structure
6422 * [I] nImageList : image list identifier
6425 * SUCCESS : image list handle
6428 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6432 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6433 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6434 case LVSIL_STATE
: return infoPtr
->himlState
;
6435 case LVSIL_GROUPHEADER
:
6436 FIXME("LVSIL_GROUPHEADER not supported\n");
6439 WARN("got unknown imagelist index - %d\n", nImageList
);
6444 /* LISTVIEW_GetISearchString */
6448 * Retrieves item attributes.
6451 * [I] hwnd : window handle
6452 * [IO] lpLVItem : item info
6453 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6454 * if FALSE, then lpLVItem is a LPLVITEMA.
6457 * This is the internal 'GetItem' interface -- it tries to
6458 * be smart and avoid text copies, if possible, by modifying
6459 * lpLVItem->pszText to point to the text string. Please note
6460 * that this is not always possible (e.g. OWNERDATA), so on
6461 * entry you *must* supply valid values for pszText, and cchTextMax.
6462 * The only difference to the documented interface is that upon
6463 * return, you should use *only* the lpLVItem->pszText, rather than
6464 * the buffer pointer you provided on input. Most code already does
6465 * that, so it's not a problem.
6466 * For the two cases when the text must be copied (that is,
6467 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6473 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6475 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6476 NMLVDISPINFOW dispInfo
;
6482 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6484 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6487 if (lpLVItem
->mask
== 0) return TRUE
;
6488 TRACE("mask=%x\n", lpLVItem
->mask
);
6490 /* make a local copy */
6491 isubitem
= lpLVItem
->iSubItem
;
6493 /* a quick optimization if all we're asked is the focus state
6494 * these queries are worth optimising since they are common,
6495 * and can be answered in constant time, without the heavy accesses */
6496 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6497 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6499 lpLVItem
->state
= 0;
6500 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6501 lpLVItem
->state
|= LVIS_FOCUSED
;
6505 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6507 /* if the app stores all the data, handle it separately */
6508 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6510 dispInfo
.item
.state
= 0;
6512 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6513 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6514 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6516 UINT mask
= lpLVItem
->mask
;
6518 /* NOTE: copy only fields which we _know_ are initialized, some apps
6519 * depend on the uninitialized fields being 0 */
6520 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6521 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6522 dispInfo
.item
.iSubItem
= isubitem
;
6523 if (lpLVItem
->mask
& LVIF_TEXT
)
6525 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6527 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6530 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6531 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6534 if (lpLVItem
->mask
& LVIF_STATE
)
6535 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6536 /* could be zeroed on LVIF_NORECOMPUTE case */
6537 if (dispInfo
.item
.mask
)
6539 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6540 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6541 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6543 /* full size structure expected - _WIN32IE >= 0x560 */
6544 *lpLVItem
= dispInfo
.item
;
6546 else if (lpLVItem
->mask
& LVIF_INDENT
)
6548 /* indent member expected - _WIN32IE >= 0x300 */
6549 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6553 /* minimal structure expected */
6554 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6556 lpLVItem
->mask
= mask
;
6557 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6561 /* make sure lParam is zeroed out */
6562 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6564 /* callback marked pointer required here */
6565 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6566 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6568 /* we store only a little state, so if we're not asked, we're done */
6569 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6571 /* if focus is handled by us, report it */
6572 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6574 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6575 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6576 lpLVItem
->state
|= LVIS_FOCUSED
;
6579 /* and do the same for selection, if we handle it */
6580 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6582 lpLVItem
->state
&= ~LVIS_SELECTED
;
6583 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6584 lpLVItem
->state
|= LVIS_SELECTED
;
6590 /* find the item and subitem structures before we proceed */
6591 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6592 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6597 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6598 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6601 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6606 pItemHdr
= &lpItem
->hdr
;
6608 /* Do we need to query the state from the app? */
6609 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6611 dispInfo
.item
.mask
|= LVIF_STATE
;
6612 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6615 /* Do we need to enquire about the image? */
6616 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6617 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6619 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6620 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6623 /* Only items support indentation */
6624 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6627 dispInfo
.item
.mask
|= LVIF_INDENT
;
6628 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6631 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6632 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6633 !is_text(pItemHdr
->pszText
))
6635 dispInfo
.item
.mask
|= LVIF_TEXT
;
6636 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6637 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6638 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6639 *dispInfo
.item
.pszText
= '\0';
6642 /* If we don't have all the requested info, query the application */
6643 if (dispInfo
.item
.mask
)
6645 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6646 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6647 dispInfo
.item
.lParam
= lpItem
->lParam
;
6648 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6649 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6652 /* we should not store values for subitems */
6653 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6655 /* Now, handle the iImage field */
6656 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6658 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6659 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6660 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6662 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6664 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6665 lpLVItem
->iImage
= pItemHdr
->iImage
;
6667 lpLVItem
->iImage
= 0;
6670 /* The pszText field */
6671 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6673 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6674 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6676 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6678 else if (lpLVItem
->mask
& LVIF_TEXT
)
6680 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6681 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6682 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6685 /* Next is the lParam field */
6686 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6688 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6689 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6690 lpItem
->lParam
= dispInfo
.item
.lParam
;
6692 else if (lpLVItem
->mask
& LVIF_PARAM
)
6693 lpLVItem
->lParam
= lpItem
->lParam
;
6695 /* if this is a subitem, we're done */
6696 if (isubitem
) return TRUE
;
6698 /* ... the state field (this one is different due to uCallbackmask) */
6699 if (lpLVItem
->mask
& LVIF_STATE
)
6701 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6702 if (dispInfo
.item
.mask
& LVIF_STATE
)
6704 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6705 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6707 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6709 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6710 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6711 lpLVItem
->state
|= LVIS_FOCUSED
;
6713 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6715 lpLVItem
->state
&= ~LVIS_SELECTED
;
6716 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6717 lpLVItem
->state
|= LVIS_SELECTED
;
6721 /* and last, but not least, the indent field */
6722 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6724 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6725 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6726 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6728 else if (lpLVItem
->mask
& LVIF_INDENT
)
6730 lpLVItem
->iIndent
= lpItem
->iIndent
;
6738 * Retrieves item attributes.
6741 * [I] hwnd : window handle
6742 * [IO] lpLVItem : item info
6743 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6744 * if FALSE, then lpLVItem is a LPLVITEMA.
6747 * This is the external 'GetItem' interface -- it properly copies
6748 * the text in the provided buffer.
6754 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6759 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6762 pszText
= lpLVItem
->pszText
;
6763 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6764 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6766 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6767 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6769 pszText
= LPSTR_TEXTCALLBACKW
;
6771 lpLVItem
->pszText
= pszText
;
6779 * Retrieves the position (upper-left) of the listview control item.
6780 * Note that for LVS_ICON style, the upper-left is that of the icon
6781 * and not the bounding box.
6784 * [I] infoPtr : valid pointer to the listview structure
6785 * [I] nItem : item index
6786 * [O] lpptPosition : coordinate information
6792 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6796 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6798 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6800 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6801 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6803 if (infoPtr
->uView
== LV_VIEW_ICON
)
6805 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6806 lpptPosition
->y
+= ICON_TOP_PADDING
;
6808 lpptPosition
->x
+= Origin
.x
;
6809 lpptPosition
->y
+= Origin
.y
;
6811 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6818 * Retrieves the bounding rectangle for a listview control item.
6821 * [I] infoPtr : valid pointer to the listview structure
6822 * [I] nItem : item index
6823 * [IO] lprc : bounding rectangle coordinates
6824 * lprc->left specifies the portion of the item for which the bounding
6825 * rectangle will be retrieved.
6827 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6828 * including the icon and label.
6831 * * Experiment shows that native control returns:
6832 * * width = min (48, length of text line)
6833 * * .left = position.x - (width - iconsize.cx)/2
6834 * * .right = .left + width
6835 * * height = #lines of text * ntmHeight + icon height + 8
6836 * * .top = position.y - 2
6837 * * .bottom = .top + height
6838 * * separation between items .y = itemSpacing.cy - height
6839 * * .x = itemSpacing.cx - width
6840 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6843 * * Experiment shows that native control returns:
6844 * * width = iconSize.cx + 16
6845 * * .left = position.x - (width - iconsize.cx)/2
6846 * * .right = .left + width
6847 * * height = iconSize.cy + 4
6848 * * .top = position.y - 2
6849 * * .bottom = .top + height
6850 * * separation between items .y = itemSpacing.cy - height
6851 * * .x = itemSpacing.cx - width
6852 * LVIR_LABEL Returns the bounding rectangle of the item text.
6855 * * Experiment shows that native control returns:
6856 * * width = text length
6857 * * .left = position.x - width/2
6858 * * .right = .left + width
6859 * * height = ntmH * linecount + 2
6860 * * .top = position.y + iconSize.cy + 6
6861 * * .bottom = .top + height
6862 * * separation between items .y = itemSpacing.cy - height
6863 * * .x = itemSpacing.cx - width
6864 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6865 * rectangles, but excludes columns in report view.
6872 * Note that the bounding rectangle of the label in the LVS_ICON view depends
6873 * upon whether the window has the focus currently and on whether the item
6874 * is the one with the focus. Ensure that the control's record of which
6875 * item has the focus agrees with the items' records.
6877 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6879 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6880 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
6881 POINT Position
, Origin
;
6885 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
6887 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6889 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6890 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6892 /* Be smart and try to figure out the minimum we have to do */
6893 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
6894 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
6895 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
6896 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
6897 oversizedBox
= TRUE
;
6899 /* get what we need from the item before hand, so we make
6900 * only one request. This can speed up things, if data
6901 * is stored on the app side */
6903 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6904 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
6905 lvItem
.iItem
= nItem
;
6906 lvItem
.iSubItem
= 0;
6907 lvItem
.pszText
= szDispText
;
6908 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6909 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6910 /* we got the state already up, simulate it here, to avoid a reget */
6911 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
6913 lvItem
.mask
|= LVIF_STATE
;
6914 lvItem
.stateMask
= LVIS_FOCUSED
;
6915 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
6918 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
6919 lprc
->left
= LVIR_BOUNDS
;
6925 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
6929 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
6933 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
6936 case LVIR_SELECTBOUNDS
:
6937 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
6941 WARN("Unknown value: %d\n", lprc
->left
);
6945 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6947 if (mode
!= LVIR_BOUNDS
)
6948 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
6949 Position
.y
+ Origin
.y
);
6951 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
6954 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
6956 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
6963 * Retrieves the spacing between listview control items.
6966 * [I] infoPtr : valid pointer to the listview structure
6967 * [IO] lprc : rectangle to receive the output
6968 * on input, lprc->top = nSubItem
6969 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
6971 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
6972 * not only those of the first column.
6973 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
6979 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6981 POINT Position
, Origin
;
6985 if (!lprc
) return FALSE
;
6987 nColumn
= lprc
->top
;
6989 TRACE("(nItem=%d, nSubItem=%d, type=%d)\n", nItem
, lprc
->top
, lprc
->left
);
6990 /* On WinNT, a subitem of '0' calls LISTVIEW_GetItemRect */
6992 return LISTVIEW_GetItemRect(infoPtr
, nItem
, lprc
);
6994 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
6996 /* special case for header items */
6999 if (lprc
->left
!= LVIR_BOUNDS
)
7001 FIXME("Only LVIR_BOUNDS is implemented for header, got %d\n", lprc
->left
);
7005 if (infoPtr
->hwndHeader
)
7006 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)lprc
);
7009 memset(lprc
, 0, sizeof(RECT
));
7014 if (!LISTVIEW_GetItemPosition(infoPtr
, nItem
, &Position
)) return FALSE
;
7015 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7017 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
7020 lvItem
.iItem
= nItem
;
7021 lvItem
.iSubItem
= nColumn
;
7026 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7031 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7035 ERR("Unknown bounds=%d\n", lprc
->left
);
7039 OffsetRect(lprc
, Origin
.x
, Position
.y
);
7040 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7047 * Retrieves the spacing between listview control items.
7050 * [I] infoPtr : valid pointer to the listview structure
7051 * [I] bSmall : flag for small or large icon
7054 * Horizontal + vertical spacing
7056 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7062 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7066 if (infoPtr
->uView
== LV_VIEW_ICON
)
7067 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7069 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7076 * Retrieves the state of a listview control item.
7079 * [I] infoPtr : valid pointer to the listview structure
7080 * [I] nItem : item index
7081 * [I] uMask : state mask
7084 * State specified by the mask.
7086 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7090 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7092 lvItem
.iItem
= nItem
;
7093 lvItem
.iSubItem
= 0;
7094 lvItem
.mask
= LVIF_STATE
;
7095 lvItem
.stateMask
= uMask
;
7096 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7098 return lvItem
.state
& uMask
;
7103 * Retrieves the text of a listview control item or subitem.
7106 * [I] hwnd : window handle
7107 * [I] nItem : item index
7108 * [IO] lpLVItem : item information
7109 * [I] isW : TRUE if lpLVItem is Unicode
7112 * SUCCESS : string length
7115 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7117 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7119 lpLVItem
->mask
= LVIF_TEXT
;
7120 lpLVItem
->iItem
= nItem
;
7121 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7123 return textlenT(lpLVItem
->pszText
, isW
);
7128 * Searches for an item based on properties + relationships.
7131 * [I] infoPtr : valid pointer to the listview structure
7132 * [I] nItem : item index
7133 * [I] uFlags : relationship flag
7136 * SUCCESS : item index
7139 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7142 LVFINDINFOW lvFindInfo
;
7143 INT nCountPerColumn
;
7147 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7148 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7150 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7152 if (uFlags
& LVNI_CUT
)
7155 if (uFlags
& LVNI_DROPHILITED
)
7156 uMask
|= LVIS_DROPHILITED
;
7158 if (uFlags
& LVNI_FOCUSED
)
7159 uMask
|= LVIS_FOCUSED
;
7161 if (uFlags
& LVNI_SELECTED
)
7162 uMask
|= LVIS_SELECTED
;
7164 /* if we're asked for the focused item, that's only one,
7165 * so it's worth optimizing */
7166 if (uFlags
& LVNI_FOCUSED
)
7168 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7169 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7172 if (uFlags
& LVNI_ABOVE
)
7174 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7179 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7185 /* Special case for autoarrange - move 'til the top of a list */
7186 if (is_autoarrange(infoPtr
))
7188 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7189 while (nItem
- nCountPerRow
>= 0)
7191 nItem
-= nCountPerRow
;
7192 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7197 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7198 lvFindInfo
.vkDirection
= VK_UP
;
7199 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7200 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7202 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7207 else if (uFlags
& LVNI_BELOW
)
7209 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7211 while (nItem
< infoPtr
->nItemCount
)
7214 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7220 /* Special case for autoarrange - move 'til the bottom of a list */
7221 if (is_autoarrange(infoPtr
))
7223 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7224 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7226 nItem
+= nCountPerRow
;
7227 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7232 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7233 lvFindInfo
.vkDirection
= VK_DOWN
;
7234 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7235 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7237 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7242 else if (uFlags
& LVNI_TOLEFT
)
7244 if (infoPtr
->uView
== LV_VIEW_LIST
)
7246 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7247 while (nItem
- nCountPerColumn
>= 0)
7249 nItem
-= nCountPerColumn
;
7250 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7254 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7256 /* Special case for autoarrange - move 'til the beginning of a row */
7257 if (is_autoarrange(infoPtr
))
7259 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7260 while (nItem
% nCountPerRow
> 0)
7263 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7268 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7269 lvFindInfo
.vkDirection
= VK_LEFT
;
7270 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7271 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7273 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7278 else if (uFlags
& LVNI_TORIGHT
)
7280 if (infoPtr
->uView
== LV_VIEW_LIST
)
7282 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7283 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7285 nItem
+= nCountPerColumn
;
7286 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7290 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7292 /* Special case for autoarrange - move 'til the end of a row */
7293 if (is_autoarrange(infoPtr
))
7295 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7296 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7299 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7304 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7305 lvFindInfo
.vkDirection
= VK_RIGHT
;
7306 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7307 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7309 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7318 /* search by index */
7319 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7321 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7329 /* LISTVIEW_GetNumberOfWorkAreas */
7333 * Retrieves the origin coordinates when in icon or small icon display mode.
7336 * [I] infoPtr : valid pointer to the listview structure
7337 * [O] lpptOrigin : coordinate information
7342 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7344 INT nHorzPos
= 0, nVertPos
= 0;
7345 SCROLLINFO scrollInfo
;
7347 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7348 scrollInfo
.fMask
= SIF_POS
;
7350 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7351 nHorzPos
= scrollInfo
.nPos
;
7352 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7353 nVertPos
= scrollInfo
.nPos
;
7355 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7357 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7358 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7359 if (infoPtr
->uView
== LV_VIEW_LIST
)
7360 nHorzPos
*= infoPtr
->nItemWidth
;
7361 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7362 nVertPos
*= infoPtr
->nItemHeight
;
7364 lpptOrigin
->x
-= nHorzPos
;
7365 lpptOrigin
->y
-= nVertPos
;
7367 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7372 * Retrieves the width of a string.
7375 * [I] hwnd : window handle
7376 * [I] lpszText : text string to process
7377 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7380 * SUCCESS : string width (in pixels)
7383 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7388 if (is_text(lpszText
))
7390 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7391 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7392 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7395 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7397 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7398 SelectObject(hdc
, hOldFont
);
7399 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7401 return stringSize
.cx
;
7406 * Determines which listview item is located at the specified position.
7409 * [I] infoPtr : valid pointer to the listview structure
7410 * [IO] lpht : hit test information
7411 * [I] subitem : fill out iSubItem.
7412 * [I] select : return the index only if the hit selects the item
7415 * (mm 20001022): We must not allow iSubItem to be touched, for
7416 * an app might pass only a structure with space up to iItem!
7417 * (MS Office 97 does that for instance in the file open dialog)
7420 * SUCCESS : item index
7423 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7425 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7426 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7427 POINT Origin
, Position
, opt
;
7432 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7436 if (subitem
) lpht
->iSubItem
= 0;
7438 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7440 /* set whole list relation flags */
7441 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7443 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7444 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7445 lpht
->flags
|= LVHT_TOLEFT
;
7447 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7448 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7452 if (infoPtr
->rcList
.bottom
< opt
.y
)
7453 lpht
->flags
|= LVHT_BELOW
;
7457 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7458 lpht
->flags
|= LVHT_TOLEFT
;
7459 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7460 lpht
->flags
|= LVHT_TORIGHT
;
7462 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7463 lpht
->flags
|= LVHT_ABOVE
;
7464 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7465 lpht
->flags
|= LVHT_BELOW
;
7468 /* even if item is invalid try to find subitem */
7469 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7474 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7476 lpht
->iSubItem
= -1;
7477 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7479 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7481 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7487 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7489 /* if we're outside horizontal columns bounds there's nothing to test further */
7490 if (lpht
->iSubItem
== -1)
7493 lpht
->flags
= LVHT_NOWHERE
;
7498 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7499 if (lpht
->flags
) return -1;
7501 lpht
->flags
|= LVHT_NOWHERE
;
7503 /* first deal with the large items */
7504 rcSearch
.left
= lpht
->pt
.x
;
7505 rcSearch
.top
= lpht
->pt
.y
;
7506 rcSearch
.right
= rcSearch
.left
+ 1;
7507 rcSearch
.bottom
= rcSearch
.top
+ 1;
7509 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7510 iterator_next(&i
); /* go to first item in the sequence */
7512 iterator_destroy(&i
);
7514 TRACE("lpht->iItem=%d\n", iItem
);
7515 if (iItem
== -1) return -1;
7517 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7518 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7519 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7520 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7521 lvItem
.iItem
= iItem
;
7522 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7523 lvItem
.pszText
= szDispText
;
7524 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7525 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7526 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7528 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7529 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7530 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7532 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7533 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7535 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7537 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7540 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7541 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7545 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7546 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7548 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7549 if (!PtInRect(&rcBounds
, opt
)) return -1;
7551 if (PtInRect(&rcIcon
, opt
))
7552 lpht
->flags
|= LVHT_ONITEMICON
;
7553 else if (PtInRect(&rcLabel
, opt
))
7554 lpht
->flags
|= LVHT_ONITEMLABEL
;
7555 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7556 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7557 /* special case for LVS_EX_FULLROWSELECT */
7558 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
7559 !(lpht
->flags
& LVHT_ONITEM
))
7561 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7563 if (lpht
->flags
& LVHT_ONITEM
)
7564 lpht
->flags
&= ~LVHT_NOWHERE
;
7565 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7567 if (select
&& !(infoPtr
->uView
== LV_VIEW_DETAILS
&&
7568 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
7569 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
7571 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7573 /* get main item bounds */
7574 lvItem
.iSubItem
= 0;
7575 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7576 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7577 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7579 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7581 return lpht
->iItem
= iItem
;
7586 * Inserts a new item in the listview control.
7589 * [I] infoPtr : valid pointer to the listview structure
7590 * [I] lpLVItem : item information
7591 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7594 * SUCCESS : new item index
7597 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7604 BOOL is_sorted
, has_changed
;
7606 HWND hwndSelf
= infoPtr
->hwndSelf
;
7608 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7610 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7612 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7613 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7615 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7617 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7619 /* insert item in listview control data structure */
7620 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7621 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7623 /* link with id struct */
7624 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7626 lpID
->item
= hdpaSubItems
;
7627 lpID
->id
= get_next_itemid(infoPtr
);
7628 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7630 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7631 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7633 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7635 /* calculate new item index */
7642 while (i
< infoPtr
->nItemCount
)
7644 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7645 item_s
= DPA_GetPtr(hItem
, 0);
7647 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7648 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7650 if (cmpv
>= 0) break;
7656 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7658 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7659 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7660 if (nItem
== -1) goto fail
;
7661 infoPtr
->nItemCount
++;
7663 /* shift indices first so they don't get tangled */
7664 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7666 /* set the item attributes */
7667 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7669 /* full size structure expected - _WIN32IE >= 0x560 */
7672 else if (lpLVItem
->mask
& LVIF_INDENT
)
7674 /* indent member expected - _WIN32IE >= 0x300 */
7675 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7679 /* minimal structure expected */
7680 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7683 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7685 item
.mask
|= LVIF_STATE
;
7686 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7687 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7688 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7690 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7692 /* make room for the position, if we are in the right mode */
7693 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7695 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7697 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7699 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7704 /* send LVN_INSERTITEM notification */
7705 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
7707 nmlv
.lParam
= lpItem
->lParam
;
7708 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7709 if (!IsWindow(hwndSelf
))
7712 /* align items (set position of each item) */
7713 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7717 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7718 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7720 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7722 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7725 /* now is the invalidation fun */
7726 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7730 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7731 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7732 infoPtr
->nItemCount
--;
7734 DPA_DeletePtr(hdpaSubItems
, 0);
7735 DPA_Destroy (hdpaSubItems
);
7742 * Checks item visibility.
7745 * [I] infoPtr : valid pointer to the listview structure
7746 * [I] nFirst : item index to check for
7749 * Item visible : TRUE
7750 * Item invisible or failure : FALSE
7752 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7754 POINT Origin
, Position
;
7759 TRACE("nItem=%d\n", nItem
);
7761 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7763 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7764 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7765 rcItem
.left
= Position
.x
+ Origin
.x
;
7766 rcItem
.top
= Position
.y
+ Origin
.y
;
7767 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7768 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7770 hdc
= GetDC(infoPtr
->hwndSelf
);
7771 if (!hdc
) return FALSE
;
7772 ret
= RectVisible(hdc
, &rcItem
);
7773 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7780 * Redraws a range of items.
7783 * [I] infoPtr : valid pointer to the listview structure
7784 * [I] nFirst : first item
7785 * [I] nLast : last item
7791 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7795 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7796 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7799 for (i
= nFirst
; i
<= nLast
; i
++)
7800 LISTVIEW_InvalidateItem(infoPtr
, i
);
7807 * Scroll the content of a listview.
7810 * [I] infoPtr : valid pointer to the listview structure
7811 * [I] dx : horizontal scroll amount in pixels
7812 * [I] dy : vertical scroll amount in pixels
7819 * If the control is in report view (LV_VIEW_DETAILS) the control can
7820 * be scrolled only in line increments. "dy" will be rounded to the
7821 * nearest number of pixels that are a whole line. Ex: if line height
7822 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7823 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7825 * For: (per experimentation with native control and CSpy ListView)
7826 * LV_VIEW_ICON dy=1 = 1 pixel (vertical only)
7828 * LV_VIEW_SMALLICON dy=1 = 1 pixel (vertical only)
7830 * LV_VIEW_LIST dx=1 = 1 column (horizontal only)
7831 * but will only scroll 1 column per message
7832 * no matter what the value.
7833 * dy must be 0 or FALSE returned.
7834 * LV_VIEW_DETAILS dx=1 = 1 pixel
7838 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7840 switch(infoPtr
->uView
) {
7841 case LV_VIEW_DETAILS
:
7842 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7843 dy
/= infoPtr
->nItemHeight
;
7846 if (dy
!= 0) return FALSE
;
7853 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
7854 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
7861 * Sets the background color.
7864 * [I] infoPtr : valid pointer to the listview structure
7865 * [I] clrBk : background color
7871 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrBk
)
7873 TRACE("(clrBk=%x)\n", clrBk
);
7875 infoPtr
->bDefaultBkColor
= FALSE
;
7876 if(infoPtr
->clrBk
!= clrBk
) {
7877 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7878 infoPtr
->clrBk
= clrBk
;
7879 if (clrBk
== CLR_NONE
)
7880 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
7883 infoPtr
->hBkBrush
= CreateSolidBrush(clrBk
);
7884 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
7886 LISTVIEW_InvalidateList(infoPtr
);
7892 /* LISTVIEW_SetBkImage */
7894 /*** Helper for {Insert,Set}ColumnT *only* */
7895 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
7896 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7898 if (lpColumn
->mask
& LVCF_FMT
)
7900 /* format member is valid */
7901 lphdi
->mask
|= HDI_FORMAT
;
7903 /* set text alignment (leftmost column must be left-aligned) */
7904 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7905 lphdi
->fmt
|= HDF_LEFT
;
7906 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
7907 lphdi
->fmt
|= HDF_RIGHT
;
7908 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
7909 lphdi
->fmt
|= HDF_CENTER
;
7911 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
7912 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
7914 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
7916 lphdi
->fmt
|= HDF_IMAGE
;
7917 lphdi
->iImage
= I_IMAGECALLBACK
;
7920 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
7921 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
7924 if (lpColumn
->mask
& LVCF_WIDTH
)
7926 lphdi
->mask
|= HDI_WIDTH
;
7927 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
7929 /* make it fill the remainder of the controls width */
7933 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
7935 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
7936 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
7939 /* retrieve the layout of the header */
7940 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
7941 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
7943 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
7946 lphdi
->cxy
= lpColumn
->cx
;
7949 if (lpColumn
->mask
& LVCF_TEXT
)
7951 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
7952 lphdi
->fmt
|= HDF_STRING
;
7953 lphdi
->pszText
= lpColumn
->pszText
;
7954 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
7957 if (lpColumn
->mask
& LVCF_IMAGE
)
7959 lphdi
->mask
|= HDI_IMAGE
;
7960 lphdi
->iImage
= lpColumn
->iImage
;
7963 if (lpColumn
->mask
& LVCF_ORDER
)
7965 lphdi
->mask
|= HDI_ORDER
;
7966 lphdi
->iOrder
= lpColumn
->iOrder
;
7973 * Inserts a new column.
7976 * [I] infoPtr : valid pointer to the listview structure
7977 * [I] nColumn : column index
7978 * [I] lpColumn : column information
7979 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
7982 * SUCCESS : new column index
7985 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
7986 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7988 COLUMN_INFO
*lpColumnInfo
;
7992 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
7994 if (!lpColumn
|| nColumn
< 0) return -1;
7995 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
7997 ZeroMemory(&hdi
, sizeof(HDITEMW
));
7998 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8001 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8002 * (can be seen in SPY) otherwise column never gets added.
8004 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8005 hdi
.mask
|= HDI_WIDTH
;
8010 * when the iSubItem is available Windows copies it to the header lParam. It seems
8011 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8013 if (lpColumn
->mask
& LVCF_SUBITEM
)
8015 hdi
.mask
|= HDI_LPARAM
;
8016 hdi
.lParam
= lpColumn
->iSubItem
;
8019 /* create header if not present */
8020 LISTVIEW_CreateHeader(infoPtr
);
8021 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8022 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8024 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8027 /* insert item in header control */
8028 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8029 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8030 nColumn
, (LPARAM
)&hdi
);
8031 if (nNewColumn
== -1) return -1;
8032 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8034 /* create our own column info */
8035 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8036 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8038 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8039 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8040 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8043 /* now we have to actually adjust the data */
8044 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8046 SUBITEM_INFO
*lpSubItem
;
8052 item
.iSubItem
= nNewColumn
;
8053 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8054 item
.iImage
= I_IMAGECALLBACK
;
8055 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8057 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8059 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8060 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8062 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8063 if (lpSubItem
->iSubItem
>= nNewColumn
)
8064 lpSubItem
->iSubItem
++;
8067 /* add new subitem for each item */
8069 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8073 /* make space for the new column */
8074 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8075 LISTVIEW_UpdateItemSize(infoPtr
);
8080 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8083 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8091 * Sets the attributes of a header item.
8094 * [I] infoPtr : valid pointer to the listview structure
8095 * [I] nColumn : column index
8096 * [I] lpColumn : column attributes
8097 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8103 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8104 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8106 HDITEMW hdi
, hdiget
;
8109 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8111 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8113 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8114 if (lpColumn
->mask
& LVCF_FMT
)
8116 hdi
.mask
|= HDI_FORMAT
;
8117 hdiget
.mask
= HDI_FORMAT
;
8118 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8119 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8121 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8123 /* set header item attributes */
8124 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8125 if (!bResult
) return FALSE
;
8127 if (lpColumn
->mask
& LVCF_FMT
)
8129 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8130 INT oldFmt
= lpColumnInfo
->fmt
;
8132 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8133 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8135 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8139 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8140 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8147 * Sets the column order array
8150 * [I] infoPtr : valid pointer to the listview structure
8151 * [I] iCount : number of elements in column order array
8152 * [I] lpiArray : pointer to column order array
8158 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8160 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
8162 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
8164 infoPtr
->colRectsDirty
= TRUE
;
8166 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8171 * Sets the width of a column
8174 * [I] infoPtr : valid pointer to the listview structure
8175 * [I] nColumn : column index
8176 * [I] cx : column width
8182 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8184 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8188 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
8190 /* set column width only if in report or list mode */
8191 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8193 /* take care of invalid cx values */
8194 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
8195 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
8197 /* resize all columns if in LV_VIEW_LIST mode */
8198 if(infoPtr
->uView
== LV_VIEW_LIST
)
8200 infoPtr
->nItemWidth
= cx
;
8201 LISTVIEW_InvalidateList(infoPtr
);
8205 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8207 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8212 lvItem
.mask
= LVIF_TEXT
;
8214 lvItem
.iSubItem
= nColumn
;
8215 lvItem
.pszText
= szDispText
;
8216 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8217 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8219 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8220 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8221 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8223 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8224 max_cx
+= infoPtr
->iconSize
.cx
;
8225 max_cx
+= TRAILING_LABEL_PADDING
;
8228 /* autosize based on listview items width */
8229 if(cx
== LVSCW_AUTOSIZE
)
8231 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8233 /* if iCol is the last column make it fill the remainder of the controls width */
8234 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8239 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8240 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8242 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8246 /* Despite what the MS docs say, if this is not the last
8247 column, then MS resizes the column to the width of the
8248 largest text string in the column, including headers
8249 and items. This is different from LVSCW_AUTOSIZE in that
8250 LVSCW_AUTOSIZE ignores the header string length. */
8253 /* retrieve header text */
8254 hdi
.mask
= HDI_TEXT
;
8255 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8256 hdi
.pszText
= szDispText
;
8257 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8259 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8260 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8263 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8264 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8265 /* FIXME: Take into account the header image, if one is present */
8266 SelectObject(hdc
, old_font
);
8267 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8269 cx
= max (cx
, max_cx
);
8273 if (cx
< 0) return FALSE
;
8275 /* call header to update the column change */
8276 hdi
.mask
= HDI_WIDTH
;
8277 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8278 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8279 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8283 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8286 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8289 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8291 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8292 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8295 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8296 ILC_COLOR
| ILC_MASK
, 2, 2);
8297 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8298 hdc
= CreateCompatibleDC(hdc_wnd
);
8299 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8300 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8301 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8303 rc
.left
= rc
.top
= 0;
8304 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8305 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8307 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8308 FillRect(hdc
, &rc
, hbr_white
);
8309 InflateRect(&rc
, -2, -2);
8310 FillRect(hdc
, &rc
, hbr_black
);
8312 SelectObject(hdc
, hbm_im
);
8313 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8314 SelectObject(hdc
, hbm_orig
);
8315 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8317 SelectObject(hdc
, hbm_im
);
8318 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8319 SelectObject(hdc
, hbm_orig
);
8320 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8322 DeleteObject(hbm_mask
);
8323 DeleteObject(hbm_im
);
8331 * Sets the extended listview style.
8334 * [I] infoPtr : valid pointer to the listview structure
8336 * [I] dwStyle : style
8339 * SUCCESS : previous style
8342 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD dwMask
, DWORD dwExStyle
)
8344 DWORD dwOldExStyle
= infoPtr
->dwLvExStyle
;
8348 infoPtr
->dwLvExStyle
= (dwOldExStyle
& ~dwMask
) | (dwExStyle
& dwMask
);
8350 infoPtr
->dwLvExStyle
= dwExStyle
;
8352 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_CHECKBOXES
)
8354 HIMAGELIST himl
= 0;
8355 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8358 item
.mask
= LVIF_STATE
;
8359 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8360 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8361 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8363 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8364 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8365 ImageList_Destroy(infoPtr
->himlState
);
8367 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8368 /* checkbox list replaces prevous custom list or... */
8369 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8370 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8371 /* ...previous was checkbox list */
8372 (dwOldExStyle
& LVS_EX_CHECKBOXES
))
8373 ImageList_Destroy(himl
);
8376 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_HEADERDRAGDROP
)
8380 /* if not already created */
8381 LISTVIEW_CreateHeader(infoPtr
);
8383 dwStyle
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8384 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8385 dwStyle
|= HDS_DRAGDROP
;
8387 dwStyle
&= ~HDS_DRAGDROP
;
8388 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, dwStyle
);
8391 /* GRIDLINES adds decoration at top so changes sizes */
8392 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_GRIDLINES
)
8394 LISTVIEW_UpdateSize(infoPtr
);
8397 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_TRANSPARENTBKGND
)
8399 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8400 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8403 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_HEADERINALLVIEWS
)
8405 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8406 LISTVIEW_CreateHeader(infoPtr
);
8408 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8409 LISTVIEW_UpdateSize(infoPtr
);
8410 LISTVIEW_UpdateScroll(infoPtr
);
8413 LISTVIEW_InvalidateList(infoPtr
);
8414 return dwOldExStyle
;
8419 * Sets the new hot cursor used during hot tracking and hover selection.
8422 * [I] infoPtr : valid pointer to the listview structure
8423 * [I] hCursor : the new hot cursor handle
8426 * Returns the previous hot cursor
8428 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8430 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8432 infoPtr
->hHotCursor
= hCursor
;
8440 * Sets the hot item index.
8443 * [I] infoPtr : valid pointer to the listview structure
8444 * [I] iIndex : index
8447 * SUCCESS : previous hot item index
8448 * FAILURE : -1 (no hot item)
8450 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8452 INT iOldIndex
= infoPtr
->nHotItem
;
8454 infoPtr
->nHotItem
= iIndex
;
8462 * Sets the amount of time the cursor must hover over an item before it is selected.
8465 * [I] infoPtr : valid pointer to the listview structure
8466 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8469 * Returns the previous hover time
8471 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8473 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8475 infoPtr
->dwHoverTime
= dwHoverTime
;
8477 return oldHoverTime
;
8482 * Sets spacing for icons of LVS_ICON style.
8485 * [I] infoPtr : valid pointer to the listview structure
8486 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8487 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8490 * MAKELONG(oldcx, oldcy)
8492 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8494 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8496 TRACE("requested=(%d,%d)\n", cx
, cy
);
8498 /* this is supported only for LVS_ICON style */
8499 if (infoPtr
->uView
!= LV_VIEW_ICON
) return oldspacing
;
8501 /* set to defaults, if instructed to */
8502 if (cx
== -1) cx
= GetSystemMetrics(SM_CXICONSPACING
);
8503 if (cy
== -1) cy
= GetSystemMetrics(SM_CYICONSPACING
);
8505 /* if 0 then compute width
8506 * FIXME: Should scan each item and determine max width of
8507 * icon or label, then make that the width */
8509 cx
= infoPtr
->iconSpacing
.cx
;
8511 /* if 0 then compute height */
8513 cy
= infoPtr
->iconSize
.cy
+ 2 * infoPtr
->ntmHeight
+
8514 ICON_BOTTOM_PADDING
+ ICON_TOP_PADDING
+ LABEL_VERT_PADDING
;
8517 infoPtr
->iconSpacing
.cx
= cx
;
8518 infoPtr
->iconSpacing
.cy
= cy
;
8520 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8521 LOWORD(oldspacing
), HIWORD(oldspacing
), cx
, cy
,
8522 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8523 infoPtr
->ntmHeight
);
8525 /* these depend on the iconSpacing */
8526 LISTVIEW_UpdateItemSize(infoPtr
);
8531 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8535 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8542 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8543 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8552 * [I] infoPtr : valid pointer to the listview structure
8553 * [I] nType : image list type
8554 * [I] himl : image list handle
8557 * SUCCESS : old image list
8560 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8562 INT oldHeight
= infoPtr
->nItemHeight
;
8563 HIMAGELIST himlOld
= 0;
8565 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
8570 himlOld
= infoPtr
->himlNormal
;
8571 infoPtr
->himlNormal
= himl
;
8572 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8573 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
8577 himlOld
= infoPtr
->himlSmall
;
8578 infoPtr
->himlSmall
= himl
;
8579 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8583 himlOld
= infoPtr
->himlState
;
8584 infoPtr
->himlState
= himl
;
8585 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8586 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8590 ERR("Unknown icon type=%d\n", nType
);
8594 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8595 if (infoPtr
->nItemHeight
!= oldHeight
)
8596 LISTVIEW_UpdateScroll(infoPtr
);
8603 * Preallocates memory (does *not* set the actual count of items !)
8606 * [I] infoPtr : valid pointer to the listview structure
8607 * [I] nItems : item count (projected number of items to allocate)
8608 * [I] dwFlags : update flags
8614 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8616 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8618 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8620 INT nOldCount
= infoPtr
->nItemCount
;
8622 if (nItems
< nOldCount
)
8624 RANGE range
= { nItems
, nOldCount
};
8625 ranges_del(infoPtr
->selectionRanges
, range
);
8626 if (infoPtr
->nFocusedItem
>= nItems
)
8628 LISTVIEW_SetItemFocus(infoPtr
, -1);
8629 SetRectEmpty(&infoPtr
->rcFocus
);
8633 infoPtr
->nItemCount
= nItems
;
8634 LISTVIEW_UpdateScroll(infoPtr
);
8636 /* the flags are valid only in ownerdata report and list modes */
8637 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8639 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8640 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8642 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8643 LISTVIEW_InvalidateList(infoPtr
);
8650 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8651 nFrom
= min(nOldCount
, nItems
);
8652 nTo
= max(nOldCount
, nItems
);
8654 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8657 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8658 rcErase
.right
= infoPtr
->nItemWidth
;
8659 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8660 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8661 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8662 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8664 else /* LV_VIEW_LIST */
8666 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8668 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8669 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8670 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8671 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8672 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8673 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8674 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8676 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8678 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8679 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8680 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8681 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8682 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8688 /* According to MSDN for non-LVS_OWNERDATA this is just
8689 * a performance issue. The control allocates its internal
8690 * data structures for the number of items specified. It
8691 * cuts down on the number of memory allocations. Therefore
8692 * we will just issue a WARN here
8694 WARN("for non-ownerdata performance option not implemented.\n");
8702 * Sets the position of an item.
8705 * [I] infoPtr : valid pointer to the listview structure
8706 * [I] nItem : item index
8707 * [I] pt : coordinate
8713 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8717 TRACE("(nItem=%d, pt=%s\n", nItem
, wine_dbgstr_point(pt
));
8719 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8720 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8723 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8725 /* This point value seems to be an undocumented feature.
8726 * The best guess is that it means either at the origin,
8727 * or at true beginning of the list. I will assume the origin. */
8728 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8731 if (infoPtr
->uView
== LV_VIEW_ICON
)
8733 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8734 Pt
.y
-= ICON_TOP_PADDING
;
8739 infoPtr
->bAutoarrange
= FALSE
;
8741 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8746 * Sets the state of one or many items.
8749 * [I] infoPtr : valid pointer to the listview structure
8750 * [I] nItem : item index
8751 * [I] lpLVItem : item or subitem info
8757 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
)
8759 BOOL bResult
= TRUE
;
8762 lvItem
.iItem
= nItem
;
8763 lvItem
.iSubItem
= 0;
8764 lvItem
.mask
= LVIF_STATE
;
8765 lvItem
.state
= lpLVItem
->state
;
8766 lvItem
.stateMask
= lpLVItem
->stateMask
;
8767 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8771 /* select all isn't allowed in LVS_SINGLESEL */
8772 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8775 /* focus all isn't allowed */
8776 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8778 /* apply to all items */
8779 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8780 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) bResult
= FALSE
;
8783 bResult
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8790 * Sets the text of an item or subitem.
8793 * [I] hwnd : window handle
8794 * [I] nItem : item index
8795 * [I] lpLVItem : item or subitem info
8796 * [I] isW : TRUE if input is Unicode
8802 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8806 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
8808 lvItem
.iItem
= nItem
;
8809 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
8810 lvItem
.mask
= LVIF_TEXT
;
8811 lvItem
.pszText
= lpLVItem
->pszText
;
8812 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
8814 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
8816 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
8821 * Set item index that marks the start of a multiple selection.
8824 * [I] infoPtr : valid pointer to the listview structure
8825 * [I] nIndex : index
8828 * Index number or -1 if there is no selection mark.
8830 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
8832 INT nOldIndex
= infoPtr
->nSelectionMark
;
8834 TRACE("(nIndex=%d)\n", nIndex
);
8836 infoPtr
->nSelectionMark
= nIndex
;
8843 * Sets the text background color.
8846 * [I] infoPtr : valid pointer to the listview structure
8847 * [I] clrTextBk : text background color
8853 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrTextBk
)
8855 TRACE("(clrTextBk=%x)\n", clrTextBk
);
8857 if (infoPtr
->clrTextBk
!= clrTextBk
)
8859 infoPtr
->clrTextBk
= clrTextBk
;
8860 LISTVIEW_InvalidateList(infoPtr
);
8868 * Sets the text foreground color.
8871 * [I] infoPtr : valid pointer to the listview structure
8872 * [I] clrText : text color
8878 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF clrText
)
8880 TRACE("(clrText=%x)\n", clrText
);
8882 if (infoPtr
->clrText
!= clrText
)
8884 infoPtr
->clrText
= clrText
;
8885 LISTVIEW_InvalidateList(infoPtr
);
8893 * Sets new ToolTip window to ListView control.
8896 * [I] infoPtr : valid pointer to the listview structure
8897 * [I] hwndNewToolTip : handle to new ToolTip
8902 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
8904 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
8905 infoPtr
->hwndToolTip
= hwndNewToolTip
;
8906 return hwndOldToolTip
;
8911 * sets the Unicode character format flag for the control
8913 * [I] infoPtr :valid pointer to the listview structure
8914 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
8917 * Old Unicode Format
8919 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
8921 SHORT rc
= infoPtr
->notifyFormat
;
8922 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
8923 return rc
== NFR_UNICODE
;
8928 * sets the control view mode
8930 * [I] infoPtr :valid pointer to the listview structure
8931 * [I] nView :new view mode value
8937 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
8939 SIZE oldIconSize
= infoPtr
->iconSize
;
8942 if (infoPtr
->uView
== nView
) return 1;
8944 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
8945 if (nView
== LV_VIEW_TILE
)
8947 FIXME("View LV_VIEW_TILE unimplemented\n");
8951 infoPtr
->uView
= nView
;
8953 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8954 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8956 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
8957 SetRectEmpty(&infoPtr
->rcFocus
);
8959 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
8960 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
8965 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
8967 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
8968 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
8969 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
8971 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8973 case LV_VIEW_SMALLICON
:
8974 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8976 case LV_VIEW_DETAILS
:
8981 LISTVIEW_CreateHeader( infoPtr
);
8983 hl
.prc
= &infoPtr
->rcList
;
8985 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
8986 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
8987 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
8994 LISTVIEW_UpdateItemSize(infoPtr
);
8995 LISTVIEW_UpdateSize(infoPtr
);
8996 LISTVIEW_UpdateScroll(infoPtr
);
8997 LISTVIEW_InvalidateList(infoPtr
);
8999 TRACE("nView=%d\n", nView
);
9004 /* LISTVIEW_SetWorkAreas */
9008 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9011 * [I] first : pointer to first ITEM_INFO to compare
9012 * [I] second : pointer to second ITEM_INFO to compare
9013 * [I] lParam : HWND of control
9016 * if first comes before second : negative
9017 * if first comes after second : positive
9018 * if first and second are equivalent : zero
9020 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9022 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9023 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9024 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9026 /* Forward the call to the client defined callback */
9027 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9032 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9035 * [I] first : pointer to first ITEM_INFO to compare
9036 * [I] second : pointer to second ITEM_INFO to compare
9037 * [I] lParam : HWND of control
9040 * if first comes before second : negative
9041 * if first comes after second : positive
9042 * if first and second are equivalent : zero
9044 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9046 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9047 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9048 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9050 /* Forward the call to the client defined callback */
9051 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9056 * Sorts the listview items.
9059 * [I] infoPtr : valid pointer to the listview structure
9060 * [I] pfnCompare : application-defined value
9061 * [I] lParamSort : pointer to comparison callback
9062 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9068 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9069 LPARAM lParamSort
, BOOL IsEx
)
9073 LPVOID selectionMarkItem
= NULL
;
9074 LPVOID focusedItem
= NULL
;
9077 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9079 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9081 if (!pfnCompare
) return FALSE
;
9082 if (!infoPtr
->hdpaItems
) return FALSE
;
9084 /* if there are 0 or 1 items, there is no need to sort */
9085 if (infoPtr
->nItemCount
< 2) return TRUE
;
9087 /* clear selection */
9088 ranges_clear(infoPtr
->selectionRanges
);
9090 /* save selection mark and focused item */
9091 if (infoPtr
->nSelectionMark
>= 0)
9092 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9093 if (infoPtr
->nFocusedItem
>= 0)
9094 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9096 infoPtr
->pfnCompare
= pfnCompare
;
9097 infoPtr
->lParamSort
= lParamSort
;
9099 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9101 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9103 /* restore selection ranges */
9104 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9106 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9107 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9109 if (lpItem
->state
& LVIS_SELECTED
)
9110 ranges_additem(infoPtr
->selectionRanges
, i
);
9112 /* restore selection mark and focused item */
9113 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9114 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9116 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9118 /* refresh the display */
9119 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
)
9120 LISTVIEW_InvalidateList(infoPtr
);
9127 * Update theme handle after a theme change.
9130 * [I] infoPtr : valid pointer to the listview structure
9134 * FAILURE : something else
9136 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9138 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9139 CloseThemeData(theme
);
9140 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9146 * Updates an items or rearranges the listview control.
9149 * [I] infoPtr : valid pointer to the listview structure
9150 * [I] nItem : item index
9156 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9158 TRACE("(nItem=%d)\n", nItem
);
9160 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9162 /* rearrange with default alignment style */
9163 if (is_autoarrange(infoPtr
))
9164 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9166 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9173 * Draw the track line at the place defined in the infoPtr structure.
9174 * The line is drawn with a XOR pen so drawing the line for the second time
9175 * in the same place erases the line.
9178 * [I] infoPtr : valid pointer to the listview structure
9184 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9190 if (infoPtr
->xTrackLine
== -1)
9193 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9195 hOldPen
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
9196 oldROP
= SetROP2(hdc
, R2_XORPEN
);
9197 MoveToEx(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
, NULL
);
9198 LineTo(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.bottom
);
9199 SetROP2(hdc
, oldROP
);
9200 SelectObject(hdc
, hOldPen
);
9201 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9207 * Called when an edit control should be displayed. This function is called after
9208 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9211 * [I] hwnd : Handle to the listview
9212 * [I] uMsg : WM_TIMER (ignored)
9213 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9214 * [I] dwTimer : The elapsed time (ignored)
9219 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9221 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9222 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9224 KillTimer(hwnd
, idEvent
);
9225 editItem
->fEnabled
= FALSE
;
9226 /* check if the item is still selected */
9227 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9228 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9233 * Creates the listview control - the WM_NCCREATE phase.
9236 * [I] hwnd : window handle
9237 * [I] lpcs : the create parameters
9243 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9245 LISTVIEW_INFO
*infoPtr
;
9248 TRACE("(lpcs=%p)\n", lpcs
);
9250 /* initialize info pointer */
9251 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9252 if (!infoPtr
) return FALSE
;
9254 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9256 infoPtr
->hwndSelf
= hwnd
;
9257 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9258 map_style_view(infoPtr
);
9259 /* determine the type of structures to use */
9260 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9261 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9263 /* initialize color information */
9264 infoPtr
->clrBk
= CLR_NONE
;
9265 infoPtr
->clrText
= CLR_DEFAULT
;
9266 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9267 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9268 infoPtr
->bDefaultBkColor
= TRUE
;
9270 /* set default values */
9271 infoPtr
->nFocusedItem
= -1;
9272 infoPtr
->nSelectionMark
= -1;
9273 infoPtr
->nHotItem
= -1;
9274 infoPtr
->bRedraw
= TRUE
;
9275 infoPtr
->bNoItemMetrics
= TRUE
;
9276 infoPtr
->bDoChangeNotify
= TRUE
;
9277 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
);
9278 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
);
9279 infoPtr
->nEditLabelItem
= -1;
9280 infoPtr
->nLButtonDownItem
= -1;
9281 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9282 infoPtr
->nMeasureItemHeight
= 0;
9283 infoPtr
->xTrackLine
= -1; /* no track line */
9284 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9285 infoPtr
->iVersion
= COMCTL32_VERSION
;
9286 infoPtr
->colRectsDirty
= FALSE
;
9288 /* get default font (icon title) */
9289 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9290 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9291 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9292 LISTVIEW_SaveTextMetrics(infoPtr
);
9294 /* allocate memory for the data structure */
9295 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9296 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9297 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9298 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9299 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9300 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9304 DestroyWindow(infoPtr
->hwndHeader
);
9305 ranges_destroy(infoPtr
->selectionRanges
);
9306 DPA_Destroy(infoPtr
->hdpaItems
);
9307 DPA_Destroy(infoPtr
->hdpaItemIds
);
9308 DPA_Destroy(infoPtr
->hdpaPosX
);
9309 DPA_Destroy(infoPtr
->hdpaPosY
);
9310 DPA_Destroy(infoPtr
->hdpaColumns
);
9317 * Creates the listview control - the WM_CREATE phase. Most of the data is
9318 * already set up in LISTVIEW_NCCreate
9321 * [I] hwnd : window handle
9322 * [I] lpcs : the create parameters
9328 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9330 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9332 TRACE("(lpcs=%p)\n", lpcs
);
9334 infoPtr
->dwStyle
= lpcs
->style
;
9335 map_style_view(infoPtr
);
9337 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9338 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9339 /* on error defaulting to ANSI notifications */
9340 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9341 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9343 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9345 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9348 infoPtr
->hwndHeader
= 0;
9350 /* init item size to avoid division by 0 */
9351 LISTVIEW_UpdateItemSize (infoPtr
);
9353 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9355 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9357 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9359 LISTVIEW_UpdateScroll(infoPtr
);
9360 /* send WM_MEASUREITEM notification */
9361 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9364 OpenThemeData(hwnd
, themeClass
);
9366 /* initialize the icon sizes */
9367 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9368 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9374 * Destroys the listview control.
9377 * [I] infoPtr : valid pointer to the listview structure
9383 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9385 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9386 CloseThemeData(theme
);
9388 /* delete all items */
9389 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9396 * Enables the listview control.
9399 * [I] infoPtr : valid pointer to the listview structure
9400 * [I] bEnable : specifies whether to enable or disable the window
9406 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9408 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9409 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9415 * Erases the background of the listview control.
9418 * [I] infoPtr : valid pointer to the listview structure
9419 * [I] hdc : device context handle
9425 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9429 TRACE("(hdc=%p)\n", hdc
);
9431 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9433 if (infoPtr
->clrBk
== CLR_NONE
)
9435 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9436 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9437 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9439 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9442 /* for double buffered controls we need to do this during refresh */
9443 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9445 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9451 * Helper function for LISTVIEW_[HV]Scroll *only*.
9452 * Performs vertical/horizontal scrolling by a give amount.
9455 * [I] infoPtr : valid pointer to the listview structure
9456 * [I] dx : amount of horizontal scroll
9457 * [I] dy : amount of vertical scroll
9459 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9461 /* now we can scroll the list */
9462 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9463 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9464 /* if we have focus, adjust rect */
9465 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9466 UpdateWindow(infoPtr
->hwndSelf
);
9471 * Performs vertical scrolling.
9474 * [I] infoPtr : valid pointer to the listview structure
9475 * [I] nScrollCode : scroll code
9476 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9477 * [I] hScrollWnd : scrollbar control window handle
9483 * SB_LINEUP/SB_LINEDOWN:
9484 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9485 * for LVS_REPORT is 1 line
9486 * for LVS_LIST cannot occur
9489 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9492 INT nOldScrollPos
, nNewScrollPos
;
9493 SCROLLINFO scrollInfo
;
9496 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9497 debugscrollcode(nScrollCode
), nScrollDiff
);
9499 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9501 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9502 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9504 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9506 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9508 nOldScrollPos
= scrollInfo
.nPos
;
9509 switch (nScrollCode
)
9515 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9519 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9523 nScrollDiff
= -scrollInfo
.nPage
;
9527 nScrollDiff
= scrollInfo
.nPage
;
9530 case SB_THUMBPOSITION
:
9532 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9539 /* quit right away if pos isn't changing */
9540 if (nScrollDiff
== 0) return 0;
9542 /* calculate new position, and handle overflows */
9543 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9544 if (nScrollDiff
> 0) {
9545 if (nNewScrollPos
< nOldScrollPos
||
9546 nNewScrollPos
> scrollInfo
.nMax
)
9547 nNewScrollPos
= scrollInfo
.nMax
;
9549 if (nNewScrollPos
> nOldScrollPos
||
9550 nNewScrollPos
< scrollInfo
.nMin
)
9551 nNewScrollPos
= scrollInfo
.nMin
;
9554 /* set the new position, and reread in case it changed */
9555 scrollInfo
.fMask
= SIF_POS
;
9556 scrollInfo
.nPos
= nNewScrollPos
;
9557 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9559 /* carry on only if it really changed */
9560 if (nNewScrollPos
== nOldScrollPos
) return 0;
9562 /* now adjust to client coordinates */
9563 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9564 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9566 /* and scroll the window */
9567 scroll_list(infoPtr
, 0, nScrollDiff
);
9574 * Performs horizontal scrolling.
9577 * [I] infoPtr : valid pointer to the listview structure
9578 * [I] nScrollCode : scroll code
9579 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9580 * [I] hScrollWnd : scrollbar control window handle
9586 * SB_LINELEFT/SB_LINERIGHT:
9587 * for LVS_ICON, LVS_SMALLICON 1 pixel
9588 * for LVS_REPORT is 1 pixel
9589 * for LVS_LIST is 1 column --> which is a 1 because the
9590 * scroll is based on columns not pixels
9593 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9596 INT nOldScrollPos
, nNewScrollPos
;
9597 SCROLLINFO scrollInfo
;
9599 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9600 debugscrollcode(nScrollCode
), nScrollDiff
);
9602 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9604 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9605 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9607 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9609 nOldScrollPos
= scrollInfo
.nPos
;
9611 switch (nScrollCode
)
9625 nScrollDiff
= -scrollInfo
.nPage
;
9629 nScrollDiff
= scrollInfo
.nPage
;
9632 case SB_THUMBPOSITION
:
9634 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9641 /* quit right away if pos isn't changing */
9642 if (nScrollDiff
== 0) return 0;
9644 /* calculate new position, and handle overflows */
9645 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9646 if (nScrollDiff
> 0) {
9647 if (nNewScrollPos
< nOldScrollPos
||
9648 nNewScrollPos
> scrollInfo
.nMax
)
9649 nNewScrollPos
= scrollInfo
.nMax
;
9651 if (nNewScrollPos
> nOldScrollPos
||
9652 nNewScrollPos
< scrollInfo
.nMin
)
9653 nNewScrollPos
= scrollInfo
.nMin
;
9656 /* set the new position, and reread in case it changed */
9657 scrollInfo
.fMask
= SIF_POS
;
9658 scrollInfo
.nPos
= nNewScrollPos
;
9659 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9661 /* carry on only if it really changed */
9662 if (nNewScrollPos
== nOldScrollPos
) return 0;
9664 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9666 /* now adjust to client coordinates */
9667 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9668 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9670 /* and scroll the window */
9671 scroll_list(infoPtr
, nScrollDiff
, 0);
9676 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9678 INT gcWheelDelta
= 0;
9679 INT pulScrollLines
= 3;
9681 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9683 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9684 gcWheelDelta
-= wheelDelta
;
9686 switch(infoPtr
->uView
)
9689 case LV_VIEW_SMALLICON
:
9691 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9692 * should be fixed in the future.
9694 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (gcWheelDelta
< 0) ?
9695 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9698 case LV_VIEW_DETAILS
:
9699 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
9701 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9702 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
9703 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, cLineScroll
);
9708 LISTVIEW_HScroll(infoPtr
, (gcWheelDelta
< 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9719 * [I] infoPtr : valid pointer to the listview structure
9720 * [I] nVirtualKey : virtual key
9721 * [I] lKeyData : key data
9726 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9728 HWND hwndSelf
= infoPtr
->hwndSelf
;
9730 NMLVKEYDOWN nmKeyDown
;
9732 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9734 /* send LVN_KEYDOWN notification */
9735 nmKeyDown
.wVKey
= nVirtualKey
;
9736 nmKeyDown
.flags
= 0;
9737 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9738 if (!IsWindow(hwndSelf
))
9741 switch (nVirtualKey
)
9744 nItem
= infoPtr
->nFocusedItem
;
9745 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9746 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9750 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9752 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9753 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9758 if (infoPtr
->nItemCount
> 0)
9763 if (infoPtr
->nItemCount
> 0)
9764 nItem
= infoPtr
->nItemCount
- 1;
9768 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9772 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9776 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9780 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9784 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9786 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9787 if (infoPtr
->nFocusedItem
== topidx
)
9788 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9793 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9794 * LISTVIEW_GetCountPerRow(infoPtr
);
9795 if(nItem
< 0) nItem
= 0;
9799 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9801 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9802 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9803 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9804 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9806 nItem
= topidx
+ cnt
- 1;
9809 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9810 * LISTVIEW_GetCountPerRow(infoPtr
);
9811 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9815 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9816 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
9826 * [I] infoPtr : valid pointer to the listview structure
9831 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
9835 /* if we did not have the focus, there's nothing to do */
9836 if (!infoPtr
->bFocus
) return 0;
9838 /* send NM_KILLFOCUS notification */
9839 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
9841 /* if we have a focus rectangle, get rid of it */
9842 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
9844 /* if have a marquee selection, stop it */
9845 if (infoPtr
->bMarqueeSelect
)
9847 /* Remove the marquee rectangle and release our mouse capture */
9848 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
9851 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
9853 infoPtr
->bMarqueeSelect
= FALSE
;
9854 infoPtr
->bScrolling
= FALSE
;
9855 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
9858 /* set window focus flag */
9859 infoPtr
->bFocus
= FALSE
;
9861 /* invalidate the selected items before resetting focus flag */
9862 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9869 * Processes double click messages (left mouse button).
9872 * [I] infoPtr : valid pointer to the listview structure
9873 * [I] wKey : key flag
9874 * [I] x,y : mouse coordinate
9879 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9881 LVHITTESTINFO htInfo
;
9883 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
9885 /* Cancel the item edition if any */
9886 if (infoPtr
->itemEdit
.fEnabled
)
9888 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
9889 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9892 /* send NM_RELEASEDCAPTURE notification */
9893 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9898 /* send NM_DBLCLK notification */
9899 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
9900 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
9902 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
9903 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
9910 * Processes mouse down messages (left mouse button).
9913 * infoPtr [I ] valid pointer to the listview structure
9914 * wKey [I ] key flag
9915 * x,y [I ] mouse coordinate
9920 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9922 LVHITTESTINFO lvHitTestInfo
;
9923 static BOOL bGroupSelect
= TRUE
;
9924 POINT pt
= { x
, y
};
9927 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
9929 /* send NM_RELEASEDCAPTURE notification */
9930 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9932 /* set left button down flag and record the click position */
9933 infoPtr
->bLButtonDown
= TRUE
;
9934 infoPtr
->ptClickPos
= pt
;
9935 infoPtr
->bDragging
= FALSE
;
9936 infoPtr
->bMarqueeSelect
= FALSE
;
9937 infoPtr
->bScrolling
= FALSE
;
9939 lvHitTestInfo
.pt
.x
= x
;
9940 lvHitTestInfo
.pt
.y
= y
;
9942 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
9943 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
9944 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
9946 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
9948 toggle_checkbox_state(infoPtr
, nItem
);
9952 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
9954 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9955 infoPtr
->nEditLabelItem
= nItem
;
9957 LISTVIEW_SetSelection(infoPtr
, nItem
);
9961 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
9965 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
9966 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9967 infoPtr
->nSelectionMark
= nItem
;
9973 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
9974 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9976 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
9977 infoPtr
->nSelectionMark
= nItem
;
9980 else if (wKey
& MK_CONTROL
)
9984 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
9986 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
9987 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9988 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
9989 infoPtr
->nSelectionMark
= nItem
;
9991 else if (wKey
& MK_SHIFT
)
9993 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
9997 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9999 infoPtr
->nEditLabelItem
= nItem
;
10000 infoPtr
->nLButtonDownItem
= nItem
;
10002 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10005 /* set selection (clears other pre-existing selections) */
10006 LISTVIEW_SetSelection(infoPtr
, nItem
);
10010 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10011 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10015 if (!infoPtr
->bFocus
)
10016 SetFocus(infoPtr
->hwndSelf
);
10018 /* remove all selections */
10019 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10020 LISTVIEW_DeselectAll(infoPtr
);
10029 * Processes mouse up messages (left mouse button).
10032 * infoPtr [I ] valid pointer to the listview structure
10033 * wKey [I ] key flag
10034 * x,y [I ] mouse coordinate
10039 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10041 LVHITTESTINFO lvHitTestInfo
;
10043 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10045 if (!infoPtr
->bLButtonDown
) return 0;
10047 lvHitTestInfo
.pt
.x
= x
;
10048 lvHitTestInfo
.pt
.y
= y
;
10050 /* send NM_CLICK notification */
10051 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10052 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10054 /* set left button flag */
10055 infoPtr
->bLButtonDown
= FALSE
;
10057 /* set a single selection, reset others */
10058 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10059 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10060 infoPtr
->nLButtonDownItem
= -1;
10062 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10064 /* Remove the marquee rectangle and release our mouse capture */
10065 if (infoPtr
->bMarqueeSelect
)
10067 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10071 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10072 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10074 infoPtr
->bDragging
= FALSE
;
10075 infoPtr
->bMarqueeSelect
= FALSE
;
10076 infoPtr
->bScrolling
= FALSE
;
10078 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10082 /* if we clicked on a selected item, edit the label */
10083 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10085 /* we want to make sure the user doesn't want to do a double click. So we will
10086 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10088 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10089 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10090 SetTimer(infoPtr
->hwndSelf
,
10091 (UINT_PTR
)&infoPtr
->itemEdit
,
10092 GetDoubleClickTime(),
10093 LISTVIEW_DelayedEditItem
);
10096 if (!infoPtr
->bFocus
)
10097 SetFocus(infoPtr
->hwndSelf
);
10104 * Destroys the listview control (called after WM_DESTROY).
10107 * [I] infoPtr : valid pointer to the listview structure
10112 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10118 /* destroy data structure */
10119 DPA_Destroy(infoPtr
->hdpaItems
);
10120 DPA_Destroy(infoPtr
->hdpaItemIds
);
10121 DPA_Destroy(infoPtr
->hdpaPosX
);
10122 DPA_Destroy(infoPtr
->hdpaPosY
);
10124 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10125 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10126 DPA_Destroy(infoPtr
->hdpaColumns
);
10127 ranges_destroy(infoPtr
->selectionRanges
);
10129 /* destroy image lists */
10130 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10132 ImageList_Destroy(infoPtr
->himlNormal
);
10133 ImageList_Destroy(infoPtr
->himlSmall
);
10134 ImageList_Destroy(infoPtr
->himlState
);
10137 /* destroy font, bkgnd brush */
10138 infoPtr
->hFont
= 0;
10139 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10140 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10142 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10144 /* free listview info pointer*/
10152 * Handles notifications.
10155 * [I] infoPtr : valid pointer to the listview structure
10156 * [I] lpnmhdr : notification information
10161 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, const NMHDR
*lpnmhdr
)
10163 HWND hwndSelf
= infoPtr
->hwndSelf
;
10164 const NMHEADERW
*lpnmh
;
10166 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10168 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10170 /* remember: HDN_LAST < HDN_FIRST */
10171 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10172 lpnmh
= (const NMHEADERW
*)lpnmhdr
;
10174 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10176 switch (lpnmhdr
->code
)
10181 COLUMN_INFO
*lpColumnInfo
;
10185 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10188 /* remove the old line (if any) */
10189 LISTVIEW_DrawTrackLine(infoPtr
);
10191 /* compute & draw the new line */
10192 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10193 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10194 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10195 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10196 LISTVIEW_DrawTrackLine(infoPtr
);
10200 case HDN_ENDTRACKA
:
10201 case HDN_ENDTRACKW
:
10202 /* remove the track line (if any) */
10203 LISTVIEW_DrawTrackLine(infoPtr
);
10204 infoPtr
->xTrackLine
= -1;
10207 case HDN_BEGINDRAG
:
10208 notify_forward_header(infoPtr
, lpnmh
);
10209 return (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0;
10212 infoPtr
->colRectsDirty
= TRUE
;
10213 LISTVIEW_InvalidateList(infoPtr
);
10214 notify_forward_header(infoPtr
, lpnmh
);
10217 case HDN_ITEMCHANGINGW
:
10218 case HDN_ITEMCHANGINGA
:
10219 return notify_forward_header(infoPtr
, lpnmh
);
10221 case HDN_ITEMCHANGEDW
:
10222 case HDN_ITEMCHANGEDA
:
10224 COLUMN_INFO
*lpColumnInfo
;
10228 notify_forward_header(infoPtr
, lpnmh
);
10229 if (!IsWindow(hwndSelf
))
10232 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10234 hdi
.mask
= HDI_WIDTH
;
10235 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10239 cxy
= lpnmh
->pitem
->cxy
;
10241 /* determine how much we change since the last know position */
10242 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10243 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10246 lpColumnInfo
->rcHeader
.right
+= dx
;
10248 hdi
.mask
= HDI_ORDER
;
10249 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10251 /* not the rightmost one */
10252 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10254 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10255 hdi
.iOrder
+ 1, 0);
10256 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10260 /* only needs to update the scrolls */
10261 infoPtr
->nItemWidth
+= dx
;
10262 LISTVIEW_UpdateScroll(infoPtr
);
10264 LISTVIEW_UpdateItemSize(infoPtr
);
10265 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10268 RECT rcCol
= lpColumnInfo
->rcHeader
;
10270 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10271 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10273 rcCol
.top
= infoPtr
->rcList
.top
;
10274 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10276 /* resizing left-aligned columns leaves most of the left side untouched */
10277 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10279 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10282 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10285 /* when shrinking the last column clear the now unused field */
10286 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10292 /* deal with right from rightmost column area */
10293 right
.left
= rcCol
.right
;
10294 right
.top
= rcCol
.top
;
10295 right
.bottom
= rcCol
.bottom
;
10296 right
.right
= infoPtr
->rcList
.right
;
10298 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10301 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10307 case HDN_ITEMCLICKW
:
10308 case HDN_ITEMCLICKA
:
10310 /* Handle sorting by Header Column */
10313 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10315 nmlv
.iSubItem
= lpnmh
->iItem
;
10316 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10317 notify_forward_header(infoPtr
, lpnmh
);
10321 case HDN_DIVIDERDBLCLICKW
:
10322 case HDN_DIVIDERDBLCLICKA
:
10323 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10324 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10325 split needed for that */
10326 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10327 notify_forward_header(infoPtr
, lpnmh
);
10336 * Paint non-client area of control.
10339 * [I] infoPtr : valid pointer to the listview structureof the sender
10340 * [I] region : update region
10343 * TRUE - frame was painted
10344 * FALSE - call default window proc
10346 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10348 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10352 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10353 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10356 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10358 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10360 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10361 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10362 if (region
!= (HRGN
)1)
10363 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10364 OffsetRect(&r
, -r
.left
, -r
.top
);
10366 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10367 OffsetRect(&r
, -r
.left
, -r
.top
);
10369 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10370 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10371 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10372 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10374 /* Call default proc to get the scrollbars etc. painted */
10375 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10382 * Determines the type of structure to use.
10385 * [I] infoPtr : valid pointer to the listview structureof the sender
10386 * [I] hwndFrom : listview window handle
10387 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10392 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10394 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10396 if (nCommand
== NF_REQUERY
)
10397 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10399 return infoPtr
->notifyFormat
;
10404 * Paints/Repaints the listview control. Internal use.
10407 * [I] infoPtr : valid pointer to the listview structure
10408 * [I] hdc : device context handle
10413 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10415 TRACE("(hdc=%p)\n", hdc
);
10417 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10419 infoPtr
->bNoItemMetrics
= FALSE
;
10420 LISTVIEW_UpdateItemSize(infoPtr
);
10421 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10422 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10423 LISTVIEW_UpdateScroll(infoPtr
);
10426 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10429 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10434 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10435 if (!hdc
) return 1;
10436 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10437 EndPaint(infoPtr
->hwndSelf
, &ps
);
10445 * Paints/Repaints the listview control, WM_PAINT handler.
10448 * [I] infoPtr : valid pointer to the listview structure
10449 * [I] hdc : device context handle
10454 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10456 TRACE("(hdc=%p)\n", hdc
);
10458 if (!is_redrawing(infoPtr
))
10459 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10461 return LISTVIEW_Paint(infoPtr
, hdc
);
10466 * Paints/Repaints the listview control.
10469 * [I] infoPtr : valid pointer to the listview structure
10470 * [I] hdc : device context handle
10471 * [I] options : drawing options
10476 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10478 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10480 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10483 if (options
& PRF_ERASEBKGND
)
10484 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10486 if (options
& PRF_CLIENT
)
10487 LISTVIEW_Paint(infoPtr
, hdc
);
10495 * Processes double click messages (right mouse button).
10498 * [I] infoPtr : valid pointer to the listview structure
10499 * [I] wKey : key flag
10500 * [I] x,y : mouse coordinate
10505 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10507 LVHITTESTINFO lvHitTestInfo
;
10509 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10511 /* send NM_RELEASEDCAPTURE notification */
10512 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10514 /* send NM_RDBLCLK notification */
10515 lvHitTestInfo
.pt
.x
= x
;
10516 lvHitTestInfo
.pt
.y
= y
;
10517 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10518 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10525 * Processes mouse down messages (right mouse button).
10528 * [I] infoPtr : valid pointer to the listview structure
10529 * [I] wKey : key flag
10530 * [I] x,y : mouse coordinate
10535 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10537 LVHITTESTINFO lvHitTestInfo
;
10540 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10542 /* send NM_RELEASEDCAPTURE notification */
10543 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10545 /* make sure the listview control window has the focus */
10546 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10548 /* set right button down flag */
10549 infoPtr
->bRButtonDown
= TRUE
;
10551 /* determine the index of the selected item */
10552 lvHitTestInfo
.pt
.x
= x
;
10553 lvHitTestInfo
.pt
.y
= y
;
10554 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10556 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10558 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10559 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10560 !LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10561 LISTVIEW_SetSelection(infoPtr
, nItem
);
10565 LISTVIEW_DeselectAll(infoPtr
);
10573 * Processes mouse up messages (right mouse button).
10576 * [I] infoPtr : valid pointer to the listview structure
10577 * [I] wKey : key flag
10578 * [I] x,y : mouse coordinate
10583 static LRESULT
LISTVIEW_RButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10585 LVHITTESTINFO lvHitTestInfo
;
10588 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10590 if (!infoPtr
->bRButtonDown
) return 0;
10592 /* set button flag */
10593 infoPtr
->bRButtonDown
= FALSE
;
10595 /* Send NM_RCLICK notification */
10596 lvHitTestInfo
.pt
.x
= x
;
10597 lvHitTestInfo
.pt
.y
= y
;
10598 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10599 if (!notify_click(infoPtr
, NM_RCLICK
, &lvHitTestInfo
)) return 0;
10601 /* Change to screen coordinate for WM_CONTEXTMENU */
10602 pt
= lvHitTestInfo
.pt
;
10603 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
10605 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
10606 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10607 (WPARAM
)infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
10618 * [I] infoPtr : valid pointer to the listview structure
10619 * [I] hwnd : window handle of window containing the cursor
10620 * [I] nHittest : hit-test code
10621 * [I] wMouseMsg : ideintifier of the mouse message
10624 * TRUE if cursor is set
10627 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10629 LVHITTESTINFO lvHitTestInfo
;
10631 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10633 if (!infoPtr
->hHotCursor
) goto forward
;
10635 GetCursorPos(&lvHitTestInfo
.pt
);
10636 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10638 SetCursor(infoPtr
->hHotCursor
);
10644 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10652 * [I] infoPtr : valid pointer to the listview structure
10653 * [I] hwndLoseFocus : handle of previously focused window
10658 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10660 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10662 /* if we have the focus already, there's nothing to do */
10663 if (infoPtr
->bFocus
) return 0;
10665 /* send NM_SETFOCUS notification */
10666 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10668 /* set window focus flag */
10669 infoPtr
->bFocus
= TRUE
;
10671 /* put the focus rect back on */
10672 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10674 /* redraw all visible selected items */
10675 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10685 * [I] infoPtr : valid pointer to the listview structure
10686 * [I] fRedraw : font handle
10687 * [I] fRedraw : redraw flag
10692 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10694 HFONT oldFont
= infoPtr
->hFont
;
10696 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10698 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10699 if (infoPtr
->hFont
== oldFont
) return 0;
10701 LISTVIEW_SaveTextMetrics(infoPtr
);
10703 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10705 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10706 LISTVIEW_UpdateSize(infoPtr
);
10707 LISTVIEW_UpdateScroll(infoPtr
);
10710 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10717 * Message handling for WM_SETREDRAW.
10718 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10721 * [I] infoPtr : valid pointer to the listview structure
10722 * [I] bRedraw: state of redraw flag
10725 * DefWinProc return value
10727 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10729 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10731 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10732 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10734 infoPtr
->bRedraw
= bRedraw
;
10736 if(!bRedraw
) return 0;
10738 if (is_autoarrange(infoPtr
))
10739 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10740 LISTVIEW_UpdateScroll(infoPtr
);
10742 /* despite what the WM_SETREDRAW docs says, apps expect us
10743 * to invalidate the listview here... stupid! */
10744 LISTVIEW_InvalidateList(infoPtr
);
10751 * Resizes the listview control. This function processes WM_SIZE
10752 * messages. At this time, the width and height are not used.
10755 * [I] infoPtr : valid pointer to the listview structure
10756 * [I] Width : new width
10757 * [I] Height : new height
10762 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10764 RECT rcOld
= infoPtr
->rcList
;
10766 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10768 LISTVIEW_UpdateSize(infoPtr
);
10769 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10771 /* do not bother with display related stuff if we're not redrawing */
10772 if (!is_redrawing(infoPtr
)) return 0;
10774 if (is_autoarrange(infoPtr
))
10775 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10777 LISTVIEW_UpdateScroll(infoPtr
);
10779 /* refresh all only for lists whose height changed significantly */
10780 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10781 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10782 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10783 LISTVIEW_InvalidateList(infoPtr
);
10790 * Sets the size information.
10793 * [I] infoPtr : valid pointer to the listview structure
10798 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10800 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
10802 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
10804 if (infoPtr
->uView
== LV_VIEW_LIST
)
10806 /* Apparently the "LIST" style is supposed to have the same
10807 * number of items in a column even if there is no scroll bar.
10808 * Since if a scroll bar already exists then the bottom is already
10809 * reduced, only reduce if the scroll bar does not currently exist.
10810 * The "2" is there to mimic the native control. I think it may be
10811 * related to either padding or edges. (GLA 7/2002)
10813 if (!(infoPtr
->dwStyle
& WS_HSCROLL
))
10814 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
10815 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
10818 /* if control created invisible header isn't created */
10819 if (infoPtr
->hwndHeader
)
10824 hl
.prc
= &infoPtr
->rcList
;
10826 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10827 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10829 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
10830 wp
.flags
|= SWP_SHOWWINDOW
;
10833 wp
.flags
|= SWP_HIDEWINDOW
;
10837 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
10838 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10840 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
10842 /* extra padding for grid */
10843 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
10844 infoPtr
->rcList
.top
+= 2;
10846 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
10851 * Processes WM_STYLECHANGED messages.
10854 * [I] infoPtr : valid pointer to the listview structure
10855 * [I] wStyleType : window style type (normal or extended)
10856 * [I] lpss : window style information
10861 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10862 const STYLESTRUCT
*lpss
)
10864 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
10865 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
10868 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10869 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10871 if (wStyleType
!= GWL_STYLE
) return 0;
10873 infoPtr
->dwStyle
= lpss
->styleNew
;
10874 map_style_view(infoPtr
);
10876 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
10877 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
10878 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
10880 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
10881 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
10882 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
10884 if (uNewView
!= uOldView
)
10886 SIZE oldIconSize
= infoPtr
->iconSize
;
10889 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
10890 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
10892 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
10893 SetRectEmpty(&infoPtr
->rcFocus
);
10895 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
10896 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
10898 if (uNewView
== LVS_ICON
)
10900 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
10902 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
10903 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
10904 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
10907 else if (uNewView
== LVS_REPORT
)
10912 LISTVIEW_CreateHeader( infoPtr
);
10914 hl
.prc
= &infoPtr
->rcList
;
10916 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10917 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
10918 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
10919 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
10922 LISTVIEW_UpdateItemSize(infoPtr
);
10925 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
10927 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
10929 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
10931 /* Turn off the header control */
10932 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
10933 TRACE("Hide header control, was 0x%08x\n", style
);
10934 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
10936 /* Turn on the header control */
10937 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
10939 TRACE("Show header control, was 0x%08x\n", style
);
10940 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
10946 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
10947 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
10948 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10950 /* update the size of the client area */
10951 LISTVIEW_UpdateSize(infoPtr
);
10953 /* add scrollbars if needed */
10954 LISTVIEW_UpdateScroll(infoPtr
);
10956 /* invalidate client area + erase background */
10957 LISTVIEW_InvalidateList(infoPtr
);
10964 * Processes WM_STYLECHANGING messages.
10967 * [I] wStyleType : window style type (normal or extended)
10968 * [I0] lpss : window style information
10973 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
10976 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10977 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10979 /* don't forward LVS_OWNERDATA only if not already set to */
10980 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
10982 if (lpss
->styleOld
& LVS_OWNERDATA
)
10983 lpss
->styleNew
|= LVS_OWNERDATA
;
10985 lpss
->styleNew
&= ~LVS_OWNERDATA
;
10993 * Processes WM_SHOWWINDOW messages.
10996 * [I] infoPtr : valid pointer to the listview structure
10997 * [I] bShown : window is being shown (FALSE when hidden)
10998 * [I] iStatus : window show status
11003 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11005 /* header delayed creation */
11006 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11008 LISTVIEW_CreateHeader(infoPtr
);
11010 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11011 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11014 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11019 * Processes CCM_GETVERSION messages.
11022 * [I] infoPtr : valid pointer to the listview structure
11027 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11029 return infoPtr
->iVersion
;
11034 * Processes CCM_SETVERSION messages.
11037 * [I] infoPtr : valid pointer to the listview structure
11038 * [I] iVersion : version to be set
11041 * -1 when requested version is greater than DLL version;
11042 * previous version otherwise
11044 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11046 INT iOldVersion
= infoPtr
->iVersion
;
11048 if (iVersion
> COMCTL32_VERSION
)
11051 infoPtr
->iVersion
= iVersion
;
11053 TRACE("new version %d\n", iVersion
);
11055 return iOldVersion
;
11060 * Window procedure of the listview control.
11063 static LRESULT WINAPI
11064 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11066 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11068 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11070 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11071 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11075 case LVM_APPROXIMATEVIEWRECT
:
11076 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11077 LOWORD(lParam
), HIWORD(lParam
));
11079 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11081 case LVM_CANCELEDITLABEL
:
11082 return LISTVIEW_CancelEditLabel(infoPtr
);
11084 case LVM_CREATEDRAGIMAGE
:
11085 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11087 case LVM_DELETEALLITEMS
:
11088 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11090 case LVM_DELETECOLUMN
:
11091 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11093 case LVM_DELETEITEM
:
11094 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11096 case LVM_EDITLABELA
:
11097 case LVM_EDITLABELW
:
11098 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11099 uMsg
== LVM_EDITLABELW
);
11100 /* case LVM_ENABLEGROUPVIEW: */
11102 case LVM_ENSUREVISIBLE
:
11103 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11105 case LVM_FINDITEMW
:
11106 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11108 case LVM_FINDITEMA
:
11109 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11111 case LVM_GETBKCOLOR
:
11112 return infoPtr
->clrBk
;
11114 /* case LVM_GETBKIMAGE: */
11116 case LVM_GETCALLBACKMASK
:
11117 return infoPtr
->uCallbackMask
;
11119 case LVM_GETCOLUMNA
:
11120 case LVM_GETCOLUMNW
:
11121 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11122 uMsg
== LVM_GETCOLUMNW
);
11124 case LVM_GETCOLUMNORDERARRAY
:
11125 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11127 case LVM_GETCOLUMNWIDTH
:
11128 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11130 case LVM_GETCOUNTPERPAGE
:
11131 return LISTVIEW_GetCountPerPage(infoPtr
);
11133 case LVM_GETEDITCONTROL
:
11134 return (LRESULT
)infoPtr
->hwndEdit
;
11136 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11137 return infoPtr
->dwLvExStyle
;
11139 /* case LVM_GETGROUPINFO: */
11141 /* case LVM_GETGROUPMETRICS: */
11143 case LVM_GETHEADER
:
11144 return (LRESULT
)infoPtr
->hwndHeader
;
11146 case LVM_GETHOTCURSOR
:
11147 return (LRESULT
)infoPtr
->hHotCursor
;
11149 case LVM_GETHOTITEM
:
11150 return infoPtr
->nHotItem
;
11152 case LVM_GETHOVERTIME
:
11153 return infoPtr
->dwHoverTime
;
11155 case LVM_GETIMAGELIST
:
11156 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11158 /* case LVM_GETINSERTMARK: */
11160 /* case LVM_GETINSERTMARKCOLOR: */
11162 /* case LVM_GETINSERTMARKRECT: */
11164 case LVM_GETISEARCHSTRINGA
:
11165 case LVM_GETISEARCHSTRINGW
:
11166 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11171 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11173 case LVM_GETITEMCOUNT
:
11174 return infoPtr
->nItemCount
;
11176 case LVM_GETITEMPOSITION
:
11177 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11179 case LVM_GETITEMRECT
:
11180 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11182 case LVM_GETITEMSPACING
:
11183 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11185 case LVM_GETITEMSTATE
:
11186 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11188 case LVM_GETITEMTEXTA
:
11189 case LVM_GETITEMTEXTW
:
11190 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11191 uMsg
== LVM_GETITEMTEXTW
);
11193 case LVM_GETNEXTITEM
:
11194 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11196 case LVM_GETNUMBEROFWORKAREAS
:
11197 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11200 case LVM_GETORIGIN
:
11201 if (!lParam
) return FALSE
;
11202 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11203 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11204 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11207 /* case LVM_GETOUTLINECOLOR: */
11209 /* case LVM_GETSELECTEDCOLUMN: */
11211 case LVM_GETSELECTEDCOUNT
:
11212 return LISTVIEW_GetSelectedCount(infoPtr
);
11214 case LVM_GETSELECTIONMARK
:
11215 return infoPtr
->nSelectionMark
;
11217 case LVM_GETSTRINGWIDTHA
:
11218 case LVM_GETSTRINGWIDTHW
:
11219 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11220 uMsg
== LVM_GETSTRINGWIDTHW
);
11222 case LVM_GETSUBITEMRECT
:
11223 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11225 case LVM_GETTEXTBKCOLOR
:
11226 return infoPtr
->clrTextBk
;
11228 case LVM_GETTEXTCOLOR
:
11229 return infoPtr
->clrText
;
11231 /* case LVM_GETTILEINFO: */
11233 /* case LVM_GETTILEVIEWINFO: */
11235 case LVM_GETTOOLTIPS
:
11236 if( !infoPtr
->hwndToolTip
)
11237 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11238 return (LRESULT
)infoPtr
->hwndToolTip
;
11240 case LVM_GETTOPINDEX
:
11241 return LISTVIEW_GetTopIndex(infoPtr
);
11243 case LVM_GETUNICODEFORMAT
:
11244 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11247 return infoPtr
->uView
;
11249 case LVM_GETVIEWRECT
:
11250 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11252 case LVM_GETWORKAREAS
:
11253 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11256 /* case LVM_HASGROUP: */
11259 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11261 case LVM_INSERTCOLUMNA
:
11262 case LVM_INSERTCOLUMNW
:
11263 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11264 uMsg
== LVM_INSERTCOLUMNW
);
11266 /* case LVM_INSERTGROUP: */
11268 /* case LVM_INSERTGROUPSORTED: */
11270 case LVM_INSERTITEMA
:
11271 case LVM_INSERTITEMW
:
11272 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11274 /* case LVM_INSERTMARKHITTEST: */
11276 /* case LVM_ISGROUPVIEWENABLED: */
11278 case LVM_ISITEMVISIBLE
:
11279 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11281 case LVM_MAPIDTOINDEX
:
11282 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11284 case LVM_MAPINDEXTOID
:
11285 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11287 /* case LVM_MOVEGROUP: */
11289 /* case LVM_MOVEITEMTOGROUP: */
11291 case LVM_REDRAWITEMS
:
11292 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11294 /* case LVM_REMOVEALLGROUPS: */
11296 /* case LVM_REMOVEGROUP: */
11299 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11301 case LVM_SETBKCOLOR
:
11302 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11304 /* case LVM_SETBKIMAGE: */
11306 case LVM_SETCALLBACKMASK
:
11307 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11310 case LVM_SETCOLUMNA
:
11311 case LVM_SETCOLUMNW
:
11312 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11313 uMsg
== LVM_SETCOLUMNW
);
11315 case LVM_SETCOLUMNORDERARRAY
:
11316 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11318 case LVM_SETCOLUMNWIDTH
:
11319 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11321 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11322 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11324 /* case LVM_SETGROUPINFO: */
11326 /* case LVM_SETGROUPMETRICS: */
11328 case LVM_SETHOTCURSOR
:
11329 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11331 case LVM_SETHOTITEM
:
11332 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11334 case LVM_SETHOVERTIME
:
11335 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11337 case LVM_SETICONSPACING
:
11338 return LISTVIEW_SetIconSpacing(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
11340 case LVM_SETIMAGELIST
:
11341 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11343 /* case LVM_SETINFOTIP: */
11345 /* case LVM_SETINSERTMARK: */
11347 /* case LVM_SETINSERTMARKCOLOR: */
11352 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11353 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11356 case LVM_SETITEMCOUNT
:
11357 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11359 case LVM_SETITEMPOSITION
:
11362 pt
.x
= (short)LOWORD(lParam
);
11363 pt
.y
= (short)HIWORD(lParam
);
11364 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11367 case LVM_SETITEMPOSITION32
:
11368 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11370 case LVM_SETITEMSTATE
:
11371 if (lParam
== 0) return FALSE
;
11372 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11374 case LVM_SETITEMTEXTA
:
11375 case LVM_SETITEMTEXTW
:
11376 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11377 uMsg
== LVM_SETITEMTEXTW
);
11379 /* case LVM_SETOUTLINECOLOR: */
11381 /* case LVM_SETSELECTEDCOLUMN: */
11383 case LVM_SETSELECTIONMARK
:
11384 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11386 case LVM_SETTEXTBKCOLOR
:
11387 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11389 case LVM_SETTEXTCOLOR
:
11390 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11392 /* case LVM_SETTILEINFO: */
11394 /* case LVM_SETTILEVIEWINFO: */
11396 /* case LVM_SETTILEWIDTH: */
11398 case LVM_SETTOOLTIPS
:
11399 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11401 case LVM_SETUNICODEFORMAT
:
11402 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11405 return LISTVIEW_SetView(infoPtr
, wParam
);
11407 /* case LVM_SETWORKAREAS: */
11409 /* case LVM_SORTGROUPS: */
11411 case LVM_SORTITEMS
:
11412 case LVM_SORTITEMSEX
:
11413 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11414 uMsg
== LVM_SORTITEMSEX
);
11415 case LVM_SUBITEMHITTEST
:
11416 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11419 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11421 case CCM_GETVERSION
:
11422 return LISTVIEW_GetVersion(infoPtr
);
11424 case CCM_SETVERSION
:
11425 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11428 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11431 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11434 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11437 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11440 return LISTVIEW_Destroy(infoPtr
);
11443 return LISTVIEW_Enable(infoPtr
);
11445 case WM_ERASEBKGND
:
11446 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11448 case WM_GETDLGCODE
:
11449 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11452 return (LRESULT
)infoPtr
->hFont
;
11455 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11458 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11461 return LISTVIEW_KillFocus(infoPtr
);
11463 case WM_LBUTTONDBLCLK
:
11464 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11466 case WM_LBUTTONDOWN
:
11467 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11470 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11473 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11475 case WM_MOUSEHOVER
:
11476 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11479 return LISTVIEW_NCDestroy(infoPtr
);
11482 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11485 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11487 case WM_NOTIFYFORMAT
:
11488 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11490 case WM_PRINTCLIENT
:
11491 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11494 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11496 case WM_RBUTTONDBLCLK
:
11497 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11499 case WM_RBUTTONDOWN
:
11500 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11503 return LISTVIEW_RButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11506 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11509 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11512 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11515 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11517 case WM_SHOWWINDOW
:
11518 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11521 return LISTVIEW_Size(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
11523 case WM_STYLECHANGED
:
11524 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11526 case WM_STYLECHANGING
:
11527 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11529 case WM_SYSCOLORCHANGE
:
11530 COMCTL32_RefreshSysColors();
11531 if (infoPtr
->bDefaultBkColor
)
11533 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
11534 infoPtr
->bDefaultBkColor
= TRUE
;
11538 /* case WM_TIMER: */
11539 case WM_THEMECHANGED
:
11540 return LISTVIEW_ThemeChanged(infoPtr
);
11543 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11545 case WM_MOUSEWHEEL
:
11546 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11547 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11548 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11550 case WM_WINDOWPOSCHANGED
:
11551 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11553 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11554 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11556 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11558 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11561 LISTVIEW_UpdateSize(infoPtr
);
11562 LISTVIEW_UpdateScroll(infoPtr
);
11564 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11566 /* case WM_WININICHANGE: */
11569 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11570 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11572 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11579 * Registers the window class.
11587 void LISTVIEW_Register(void)
11589 WNDCLASSW wndClass
;
11591 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11592 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11593 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11594 wndClass
.cbClsExtra
= 0;
11595 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11596 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11597 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11598 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11599 RegisterClassW(&wndClass
);
11604 * Unregisters the window class.
11612 void LISTVIEW_Unregister(void)
11614 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11619 * Handle any WM_COMMAND messages
11622 * [I] infoPtr : valid pointer to the listview structure
11623 * [I] wParam : the first message parameter
11624 * [I] lParam : the second message parameter
11629 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11632 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11634 if (!infoPtr
->hwndEdit
) return 0;
11636 switch (HIWORD(wParam
))
11641 * Adjust the edit window size
11643 WCHAR buffer
[1024];
11644 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11645 HFONT hFont
, hOldFont
= 0;
11649 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11650 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11651 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11653 /* Select font to get the right dimension of the string */
11654 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11657 hOldFont
= SelectObject(hdc
, hFont
);
11660 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11662 TEXTMETRICW textMetric
;
11664 /* Add Extra spacing for the next character */
11665 GetTextMetricsW(hdc
, &textMetric
);
11666 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11668 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11669 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11672 SelectObject(hdc
, hOldFont
);
11674 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11680 LISTVIEW_CancelEditLabel(infoPtr
);
11685 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);