4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1999 Luc Tourangeau
6 * Copyright 2000 Jason Mawdsley
7 * Copyright 2001 CodeWeavers Inc.
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Nikolay Sivov
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 /* make sure you set this to 0 for production use! */
172 #define DEBUG_RANGES 1
174 typedef struct tagCOLUMN_INFO
176 RECT rcHeader
; /* tracks the header's rectangle */
177 INT fmt
; /* same as LVCOLUMN.fmt */
181 typedef struct tagITEMHDR
185 } ITEMHDR
, *LPITEMHDR
;
187 typedef struct tagSUBITEM_INFO
193 typedef struct tagITEM_ID ITEM_ID
;
195 typedef struct tagITEM_INFO
206 UINT id
; /* item id */
207 HDPA item
; /* link to item data */
210 typedef struct tagRANGE
216 typedef struct tagRANGES
221 typedef struct tagITERATOR
230 typedef struct tagDELAYED_ITEM_EDIT
236 typedef struct tagLISTVIEW_INFO
240 RECT rcList
; /* This rectangle is really the window
241 * client rectangle possibly reduced by the
242 * horizontal scroll bar and/or header - see
243 * LISTVIEW_UpdateSize. This rectangle offset
244 * by the LISTVIEW_GetOrigin value is in
245 * client coordinates */
247 /* notification window */
250 BOOL bDoChangeNotify
; /* send change notification messages? */
257 INT nItemCount
; /* the number of items in the list */
258 HDPA hdpaItems
; /* array ITEM_INFO pointers */
259 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
260 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
261 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
262 RANGES selectionRanges
;
263 INT nSelectionMark
; /* item to start next multiselection from */
265 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
268 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
269 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
272 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
277 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
281 DWORD dwStyle
; /* the cached window GWL_STYLE */
282 DWORD dwLvExStyle
; /* extended listview style */
283 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
289 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
292 HIMAGELIST himlNormal
;
293 HIMAGELIST himlSmall
;
294 HIMAGELIST himlState
;
298 POINT currIconPos
; /* this is the position next icon will be placed */
302 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
304 /* marquee selection */
305 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
307 RECT marqueeRect
; /* absolute coordinates of marquee selection */
308 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
309 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
312 BOOL bFocus
; /* control has focus */
314 RECT rcFocus
; /* focus bounds */
325 INT ntmHeight
; /* Some cached metrics of the font used */
326 INT ntmMaxCharWidth
; /* by the listview to draw items */
329 /* mouse operation */
333 POINT ptClickPos
; /* point where the user clicked */
334 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
338 /* keyboard operation */
339 DWORD lastKeyPressTimestamp
;
341 INT nSearchParamLength
;
342 WCHAR szSearchParam
[ MAX_PATH
];
345 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
346 BOOL bIsDrawing
; /* Drawing in progress */
347 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
348 BOOL bRedraw
; /* WM_SETREDRAW switch */
351 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
357 /* How many we debug buffer to allocate */
358 #define DEBUG_BUFFERS 20
359 /* The size of a single debug buffer */
360 #define DEBUG_BUFFER_SIZE 256
362 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
363 #define SB_INTERNAL -1
365 /* maximum size of a label */
366 #define DISP_TEXT_SIZE 512
368 /* padding for items in list and small icon display modes */
369 #define WIDTH_PADDING 12
371 /* padding for items in list, report and small icon display modes */
372 #define HEIGHT_PADDING 1
374 /* offset of items in report display mode */
375 #define REPORT_MARGINX 2
377 /* padding for icon in large icon display mode
378 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
379 * that HITTEST will see.
380 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
381 * ICON_TOP_PADDING - sum of the two above.
382 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
383 * LABEL_HOR_PADDING - between text and sides of box
384 * LABEL_VERT_PADDING - between bottom of text and end of box
386 * ICON_LR_PADDING - additional width above icon size.
387 * ICON_LR_HALF - half of the above value
389 #define ICON_TOP_PADDING_NOTHITABLE 2
390 #define ICON_TOP_PADDING_HITABLE 2
391 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
392 #define ICON_BOTTOM_PADDING 4
393 #define LABEL_HOR_PADDING 5
394 #define LABEL_VERT_PADDING 7
395 #define ICON_LR_PADDING 16
396 #define ICON_LR_HALF (ICON_LR_PADDING/2)
398 /* default label width for items in list and small icon display modes */
399 #define DEFAULT_LABEL_WIDTH 40
400 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
401 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
403 /* default column width for items in list display mode */
404 #define DEFAULT_COLUMN_WIDTH 128
406 /* Size of "line" scroll for V & H scrolls */
407 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
409 /* Padding between image and label */
410 #define IMAGE_PADDING 2
412 /* Padding behind the label */
413 #define TRAILING_LABEL_PADDING 12
414 #define TRAILING_HEADER_PADDING 11
416 /* Border for the icon caption */
417 #define CAPTION_BORDER 2
419 /* Standard DrawText flags */
420 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
421 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
422 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
424 /* Image index from state */
425 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
427 /* The time in milliseconds to reset the search in the list */
428 #define KEY_DELAY 450
430 /* Dump the LISTVIEW_INFO structure to the debug channel */
431 #define LISTVIEW_DUMP(iP) do { \
432 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
433 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
434 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
435 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
436 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
437 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
438 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
439 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
440 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
441 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
444 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
447 * forward declarations
449 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
450 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
451 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
452 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
453 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
454 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
455 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
456 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
457 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
458 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
459 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
460 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
461 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
462 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
463 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
464 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
465 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
466 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
467 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
468 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
470 /******** Text handling functions *************************************/
472 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
473 * text string. The string may be ANSI or Unicode, in which case
474 * the boolean isW tells us the type of the string.
476 * The name of the function tell what type of strings it expects:
477 * W: Unicode, T: ANSI/Unicode - function of isW
480 static inline BOOL
is_textW(LPCWSTR text
)
482 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
485 static inline BOOL
is_textT(LPCWSTR text
, BOOL isW
)
487 /* we can ignore isW since LPSTR_TEXTCALLBACKW == LPSTR_TEXTCALLBACKA */
488 return is_textW(text
);
491 static inline int textlenT(LPCWSTR text
, BOOL isW
)
493 return !is_textT(text
, isW
) ? 0 :
494 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
497 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
500 if (isSrcW
) lstrcpynW(dest
, src
, max
);
501 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
503 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
504 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
507 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
509 LPWSTR wstr
= (LPWSTR
)text
;
511 if (!isW
&& is_textT(text
, isW
))
513 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
514 wstr
= Alloc(len
* sizeof(WCHAR
));
515 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
517 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
521 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
523 if (!isW
&& is_textT(wstr
, isW
)) Free (wstr
);
527 * dest is a pointer to a Unicode string
528 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
530 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
534 if (src
== LPSTR_TEXTCALLBACKW
)
536 if (is_textW(*dest
)) Free(*dest
);
537 *dest
= LPSTR_TEXTCALLBACKW
;
541 LPWSTR pszText
= textdupTtoW(src
, isW
);
542 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
543 bResult
= Str_SetPtrW(dest
, pszText
);
544 textfreeT(pszText
, isW
);
550 * compares a Unicode to a Unicode/ANSI text string
552 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
554 if (!aw
) return bt
? -1 : 0;
555 if (!bt
) return aw
? 1 : 0;
556 if (aw
== LPSTR_TEXTCALLBACKW
)
557 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
558 if (bt
!= LPSTR_TEXTCALLBACKW
)
560 LPWSTR bw
= textdupTtoW(bt
, isW
);
561 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
569 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
573 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
574 res
= CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
);
575 return res
? res
- sizeof(WCHAR
) : res
;
578 /******** Debugging functions *****************************************/
580 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
582 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
583 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
586 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
588 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
589 n
= min(textlenT(text
, isW
), n
);
590 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
593 static char* debug_getbuf(void)
595 static int index
= 0;
596 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
597 return buffers
[index
++ % DEBUG_BUFFERS
];
600 static inline const char* debugrange(const RANGE
*lprng
)
602 if (!lprng
) return "(null)";
603 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
606 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
608 char* buf
= debug_getbuf(), *text
= buf
;
609 int len
, size
= DEBUG_BUFFER_SIZE
;
611 if (pScrollInfo
== NULL
) return "(null)";
612 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
613 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
614 if (pScrollInfo
->fMask
& SIF_RANGE
)
615 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
617 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
618 if (pScrollInfo
->fMask
& SIF_PAGE
)
619 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
621 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
622 if (pScrollInfo
->fMask
& SIF_POS
)
623 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
625 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
626 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
627 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
629 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
632 buf
= text
+ strlen(text
);
634 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
638 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
640 if (!plvnm
) return "(null)";
641 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
642 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
643 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
644 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
647 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
649 char* buf
= debug_getbuf(), *text
= buf
;
650 int len
, size
= DEBUG_BUFFER_SIZE
;
652 if (lpLVItem
== NULL
) return "(null)";
653 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
654 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
655 if (lpLVItem
->mask
& LVIF_STATE
)
656 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
658 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
659 if (lpLVItem
->mask
& LVIF_TEXT
)
660 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
662 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
663 if (lpLVItem
->mask
& LVIF_IMAGE
)
664 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
666 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
667 if (lpLVItem
->mask
& LVIF_PARAM
)
668 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
670 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
671 if (lpLVItem
->mask
& LVIF_INDENT
)
672 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
674 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
677 buf
= text
+ strlen(text
);
679 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
683 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
685 char* buf
= debug_getbuf(), *text
= buf
;
686 int len
, size
= DEBUG_BUFFER_SIZE
;
688 if (lpColumn
== NULL
) return "(null)";
689 len
= snprintf(buf
, size
, "{");
690 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
691 if (lpColumn
->mask
& LVCF_SUBITEM
)
692 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
694 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
695 if (lpColumn
->mask
& LVCF_FMT
)
696 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
698 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
699 if (lpColumn
->mask
& LVCF_WIDTH
)
700 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
702 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
703 if (lpColumn
->mask
& LVCF_TEXT
)
704 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
706 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
707 if (lpColumn
->mask
& LVCF_IMAGE
)
708 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
710 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
711 if (lpColumn
->mask
& LVCF_ORDER
)
712 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
714 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
717 buf
= text
+ strlen(text
);
719 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
723 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
725 if (!lpht
) return "(null)";
727 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
728 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
731 /* Return the corresponding text for a given scroll value */
732 static inline LPCSTR
debugscrollcode(int nScrollCode
)
736 case SB_LINELEFT
: return "SB_LINELEFT";
737 case SB_LINERIGHT
: return "SB_LINERIGHT";
738 case SB_PAGELEFT
: return "SB_PAGELEFT";
739 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
740 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
741 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
742 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
743 case SB_INTERNAL
: return "SB_INTERNAL";
744 default: return "unknown";
749 /******** Notification functions ************************************/
751 static int get_ansi_notification(UINT unicodeNotificationCode
)
753 switch (unicodeNotificationCode
)
755 case LVN_BEGINLABELEDITA
:
756 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
757 case LVN_ENDLABELEDITA
:
758 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
759 case LVN_GETDISPINFOA
:
760 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
761 case LVN_SETDISPINFOA
:
762 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
763 case LVN_ODFINDITEMA
:
764 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
765 case LVN_GETINFOTIPA
:
766 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
767 /* header forwards */
769 case HDN_TRACKW
: return HDN_TRACKA
;
771 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
772 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
773 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
774 case HDN_ITEMCHANGINGA
:
775 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
776 case HDN_ITEMCHANGEDA
:
777 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
779 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
780 case HDN_DIVIDERDBLCLICKA
:
781 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
784 FIXME("unknown notification %x\n", unicodeNotificationCode
);
785 return unicodeNotificationCode
;
788 /* forwards header notifications to listview parent */
789 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
793 HD_TEXTFILTERA textfilter
;
794 LPSTR text
= NULL
, filter
= NULL
;
797 /* on unicode format exit earlier */
798 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
799 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
802 /* header always supplies unicode notifications,
803 all we have to do is to convert strings to ANSI */
804 nmhA
= *(const NMHEADERA
*)lpnmh
;
807 hditema
= *(HDITEMA
*)lpnmh
->pitem
;
808 nmhA
.pitem
= &hditema
;
809 /* convert item text */
810 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
812 hditema
.pszText
= NULL
;
813 Str_SetPtrWtoA(&hditema
.pszText
, lpnmh
->pitem
->pszText
);
814 text
= hditema
.pszText
;
816 /* convert filter text */
817 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
818 lpnmh
->pitem
->pvFilter
)
820 hditema
.pvFilter
= &textfilter
;
821 textfilter
= *(HD_TEXTFILTERA
*)(lpnmh
->pitem
->pvFilter
);
822 textfilter
.pszText
= NULL
;
823 Str_SetPtrWtoA(&textfilter
.pszText
, ((HD_TEXTFILTERW
*)lpnmh
->pitem
->pvFilter
)->pszText
);
824 filter
= textfilter
.pszText
;
827 nmhA
.hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
829 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhA
.hdr
.idFrom
,
839 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
843 TRACE("(code=%d)\n", code
);
845 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
846 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
848 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
850 TRACE(" <= %ld\n", result
);
855 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
858 HWND hwnd
= infoPtr
->hwndSelf
;
859 notify_hdr(infoPtr
, code
, &nmh
);
860 return IsWindow(hwnd
);
863 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
874 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
875 item
.iItem
= htInfo
->iItem
;
877 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
878 nmia
.lParam
= item
.lParam
;
879 nmia
.uOldState
= item
.state
;
880 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
881 nmia
.uChanged
= LVIF_STATE
;
884 nmia
.iItem
= htInfo
->iItem
;
885 nmia
.iSubItem
= htInfo
->iSubItem
;
886 nmia
.ptAction
= htInfo
->pt
;
888 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
889 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
890 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
892 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
895 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
897 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
898 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
901 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
905 HWND hwnd
= infoPtr
->hwndSelf
;
907 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
908 ZeroMemory(&nmia
, sizeof(nmia
));
909 nmia
.iItem
= lvht
->iItem
;
910 nmia
.iSubItem
= lvht
->iSubItem
;
911 nmia
.ptAction
= lvht
->pt
;
912 item
.mask
= LVIF_PARAM
;
913 item
.iItem
= lvht
->iItem
;
915 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
916 notify_hdr(infoPtr
, code
, (LPNMHDR
)&nmia
);
917 return IsWindow(hwnd
);
920 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
924 HWND hwnd
= infoPtr
->hwndSelf
;
926 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
928 item
.mask
= LVIF_PARAM
;
931 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
932 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
933 return IsWindow(hwnd
);
937 Send notification. depends on dispinfoW having same
938 structure as dispinfoA.
939 infoPtr : listview struct
940 notificationCode : *Unicode* notification code
941 pdi : dispinfo structure (can be unicode or ansi)
942 isW : TRUE if dispinfo is Unicode
944 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT notificationCode
, LPNMLVDISPINFOW pdi
, BOOL isW
)
946 BOOL bResult
= FALSE
;
947 BOOL convertToAnsi
= FALSE
, convertToUnicode
= FALSE
;
948 INT cchTempBufMax
= 0, savCchTextMax
= 0;
950 LPWSTR pszTempBuf
= NULL
, savPszText
= NULL
;
952 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_textT(pdi
->item
.pszText
, isW
))
954 convertToAnsi
= (isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
955 convertToUnicode
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
958 if (convertToAnsi
|| convertToUnicode
)
960 if (notificationCode
!= LVN_GETDISPINFOW
)
962 cchTempBufMax
= convertToUnicode
?
963 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
964 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
968 cchTempBufMax
= pdi
->item
.cchTextMax
;
969 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
972 pszTempBuf
= Alloc( (convertToUnicode
? sizeof(WCHAR
) : sizeof(CHAR
)) * cchTempBufMax
);
973 if (!pszTempBuf
) return FALSE
;
975 if (convertToUnicode
)
976 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
977 pszTempBuf
, cchTempBufMax
);
979 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) pszTempBuf
,
980 cchTempBufMax
, NULL
, NULL
);
982 savCchTextMax
= pdi
->item
.cchTextMax
;
983 savPszText
= pdi
->item
.pszText
;
984 pdi
->item
.pszText
= pszTempBuf
;
985 pdi
->item
.cchTextMax
= cchTempBufMax
;
988 if (infoPtr
->notifyFormat
== NFR_ANSI
)
989 realNotifCode
= get_ansi_notification(notificationCode
);
991 realNotifCode
= notificationCode
;
992 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
993 bResult
= notify_hdr(infoPtr
, realNotifCode
, &pdi
->hdr
);
995 if (convertToUnicode
|| convertToAnsi
)
997 if (convertToUnicode
) /* note : pointer can be changed by app ! */
998 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) savPszText
,
999 savCchTextMax
, NULL
, NULL
);
1001 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
1002 savPszText
, savCchTextMax
);
1003 pdi
->item
.pszText
= savPszText
; /* restores our buffer */
1004 pdi
->item
.cchTextMax
= savCchTextMax
;
1010 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1011 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1013 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1014 lpnmlvcd
->nmcd
.hdc
= hdc
;
1015 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1016 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1017 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1018 if (!lplvItem
) return;
1019 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1020 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1021 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1022 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1023 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1024 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1027 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1029 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1032 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1033 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1034 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1035 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1036 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1037 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1041 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1043 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
1044 lpnmlvcd
->clrTextBk
= comctl32_color
.clrWindow
;
1045 if (lpnmlvcd
->clrText
== CLR_DEFAULT
)
1046 lpnmlvcd
->clrText
= comctl32_color
.clrWindowText
;
1048 /* apparently, for selected items, we have to override the returned values */
1051 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1053 if (infoPtr
->bFocus
)
1055 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1056 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1058 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1060 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1061 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1066 /* Set the text attributes */
1067 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
1069 SetBkMode(hdc
, OPAQUE
);
1070 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1073 SetBkMode(hdc
, TRANSPARENT
);
1074 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1077 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1079 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1082 /* returns TRUE when repaint needed, FALSE otherwise */
1083 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1085 MEASUREITEMSTRUCT mis
;
1086 mis
.CtlType
= ODT_LISTVIEW
;
1087 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1091 mis
.itemHeight
= infoPtr
->nItemHeight
;
1092 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1093 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1095 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1101 /******** Item iterator functions **********************************/
1103 static RANGES
ranges_create(int count
);
1104 static void ranges_destroy(RANGES ranges
);
1105 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1106 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1107 static void ranges_dump(RANGES ranges
);
1109 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1111 RANGE range
= { nItem
, nItem
+ 1 };
1113 return ranges_add(ranges
, range
);
1116 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1118 RANGE range
= { nItem
, nItem
+ 1 };
1120 return ranges_del(ranges
, range
);
1124 * ITERATOR DOCUMENTATION
1126 * The iterator functions allow for easy, and convenient iteration
1127 * over items of interest in the list. Typically, you create a
1128 * iterator, use it, and destroy it, as such:
1131 * iterator_xxxitems(&i, ...);
1132 * while (iterator_{prev,next}(&i)
1134 * //code which uses i.nItem
1136 * iterator_destroy(&i);
1138 * where xxx is either: framed, or visible.
1139 * Note that it is important that the code destroys the iterator
1140 * after it's done with it, as the creation of the iterator may
1141 * allocate memory, which thus needs to be freed.
1143 * You can iterate both forwards, and backwards through the list,
1144 * by using iterator_next or iterator_prev respectively.
1146 * Lower numbered items are draw on top of higher number items in
1147 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1148 * items may overlap). So, to test items, you should use
1150 * which lists the items top to bottom (in Z-order).
1151 * For drawing items, you should use
1153 * which lists the items bottom to top (in Z-order).
1154 * If you keep iterating over the items after the end-of-items
1155 * marker (-1) is returned, the iterator will start from the
1156 * beginning. Typically, you don't need to test for -1,
1157 * because iterator_{next,prev} will return TRUE if more items
1158 * are to be iterated over, or FALSE otherwise.
1160 * Note: the iterator is defined to be bidirectional. That is,
1161 * any number of prev followed by any number of next, or
1162 * five versa, should leave the iterator at the same item:
1163 * prev * n, next * n = next * n, prev * n
1165 * The iterator has a notion of an out-of-order, special item,
1166 * which sits at the start of the list. This is used in
1167 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1168 * which needs to be first, as it may overlap other items.
1170 * The code is a bit messy because we have:
1171 * - a special item to deal with
1172 * - simple range, or composite range
1174 * If you find bugs, or want to add features, please make sure you
1175 * always check/modify *both* iterator_prev, and iterator_next.
1179 * This function iterates through the items in increasing order,
1180 * but prefixed by the special item, then -1. That is:
1181 * special, 1, 2, 3, ..., n, -1.
1182 * Each item is listed only once.
1184 static inline BOOL
iterator_next(ITERATOR
* i
)
1188 i
->nItem
= i
->nSpecial
;
1189 if (i
->nItem
!= -1) return TRUE
;
1191 if (i
->nItem
== i
->nSpecial
)
1193 if (i
->ranges
) i
->index
= 0;
1199 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1200 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1205 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1206 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1209 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1211 i
->nItem
= i
->range
.lower
;
1212 if (i
->nItem
>= 0) goto testitem
;
1219 * This function iterates through the items in decreasing order,
1220 * followed by the special item, then -1. That is:
1221 * n, n-1, ..., 3, 2, 1, special, -1.
1222 * Each item is listed only once.
1224 static inline BOOL
iterator_prev(ITERATOR
* i
)
1231 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1234 if (i
->nItem
== i
->nSpecial
)
1242 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1243 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1249 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1252 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1254 i
->nItem
= i
->range
.upper
;
1255 if (i
->nItem
> 0) goto testitem
;
1257 return (i
->nItem
= i
->nSpecial
) != -1;
1260 static RANGE
iterator_range(const ITERATOR
*i
)
1264 if (!i
->ranges
) return i
->range
;
1266 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1268 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1269 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1271 else range
.lower
= range
.upper
= 0;
1277 * Releases resources associated with this ierator.
1279 static inline void iterator_destroy(const ITERATOR
*i
)
1281 ranges_destroy(i
->ranges
);
1285 * Create an empty iterator.
1287 static inline BOOL
iterator_empty(ITERATOR
* i
)
1289 ZeroMemory(i
, sizeof(*i
));
1290 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1295 * Create an iterator over a range.
1297 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1305 * Create an iterator over a bunch of ranges.
1306 * Please note that the iterator will take ownership of the ranges,
1307 * and will free them upon destruction.
1309 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1317 * Creates an iterator over the items which intersect frame.
1318 * Uses absolute coordinates rather than compensating for the current offset.
1320 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1322 RECT rcItem
, rcTemp
;
1324 /* in case we fail, we want to return an empty iterator */
1325 if (!iterator_empty(i
)) return FALSE
;
1327 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1329 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1333 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1335 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1336 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1337 i
->nSpecial
= infoPtr
->nFocusedItem
;
1339 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1340 /* to do better here, we need to have PosX, and PosY sorted */
1341 TRACE("building icon ranges:\n");
1342 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1344 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1345 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1346 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1347 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1348 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1349 ranges_additem(i
->ranges
, nItem
);
1353 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1357 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1358 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1360 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1361 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1362 if (range
.upper
<= range
.lower
) return TRUE
;
1363 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1364 TRACE(" report=%s\n", debugrange(&i
->range
));
1368 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1369 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1370 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1377 if (infoPtr
->nItemWidth
)
1379 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1380 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1384 nFirstCol
= max(frame
->left
, 0);
1385 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1388 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1390 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1391 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1393 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1395 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1396 TRACE("building list ranges:\n");
1397 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1399 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1400 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1401 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1402 TRACE(" list=%s\n", debugrange(&item_range
));
1403 ranges_add(i
->ranges
, item_range
);
1411 * Creates an iterator over the items which intersect lprc.
1413 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1418 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1420 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1421 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1423 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1427 * Creates an iterator over the items which intersect the visible region of hdc.
1429 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1431 POINT Origin
, Position
;
1432 RECT rcItem
, rcClip
;
1435 rgntype
= GetClipBox(hdc
, &rcClip
);
1436 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1437 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1438 if (rgntype
== SIMPLEREGION
) return TRUE
;
1440 /* first deal with the special item */
1441 if (i
->nSpecial
!= -1)
1443 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1444 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1447 /* if we can't deal with the region, we'll just go with the simple range */
1448 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1449 TRACE("building visible range:\n");
1450 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1452 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1453 if (!ranges_add(i
->ranges
, i
->range
))
1455 ranges_destroy(i
->ranges
);
1461 /* now delete the invisible items from the list */
1462 while(iterator_next(i
))
1464 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1465 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1466 rcItem
.top
= Position
.y
+ Origin
.y
;
1467 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1468 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1469 if (!RectVisible(hdc
, &rcItem
))
1470 ranges_delitem(i
->ranges
, i
->nItem
);
1472 /* the iterator should restart on the next iterator_next */
1478 /******** Misc helper functions ************************************/
1480 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1481 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1483 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1484 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1487 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1489 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1490 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1493 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1495 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1496 if(state
== 1 || state
== 2)
1500 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1501 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1502 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1506 /* this should be called after window style got updated,
1507 it used to reset view state to match current window style */
1508 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1510 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1513 infoPtr
->uView
= LV_VIEW_ICON
;
1516 infoPtr
->uView
= LV_VIEW_DETAILS
;
1519 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1522 infoPtr
->uView
= LV_VIEW_LIST
;
1526 /* computes next item id value */
1527 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1529 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1533 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1534 return lpID
->id
+ 1;
1539 /******** Internal API functions ************************************/
1541 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1543 static COLUMN_INFO mainItem
;
1545 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1546 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1548 /* update cached column rectangles */
1549 if (infoPtr
->colRectsDirty
)
1552 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1555 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1556 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1557 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1559 Ptr
->colRectsDirty
= FALSE
;
1562 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1565 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1567 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1570 if (infoPtr
->hwndHeader
) return 0;
1572 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1574 /* setup creation flags */
1575 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1576 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1578 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1581 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1582 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1583 if (!infoPtr
->hwndHeader
) return -1;
1585 /* set header unicode format */
1586 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1588 /* set header font */
1589 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1591 LISTVIEW_UpdateSize(infoPtr
);
1596 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1598 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1601 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1603 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1604 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1605 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1608 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1610 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1613 /* used to handle collapse main item column case */
1614 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1616 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1617 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1620 /* Listview invalidation functions: use _only_ these functions to invalidate */
1622 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1624 return infoPtr
->bRedraw
;
1627 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1629 if(!is_redrawing(infoPtr
)) return;
1630 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1631 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1634 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1638 if(!is_redrawing(infoPtr
)) return;
1639 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1640 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1643 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1645 POINT Origin
, Position
;
1648 if(!is_redrawing(infoPtr
)) return;
1649 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1650 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1651 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1652 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1654 rcBox
.bottom
= infoPtr
->nItemHeight
;
1655 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1656 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1659 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1661 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1664 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1668 if(!is_redrawing(infoPtr
)) return;
1669 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1670 rcCol
.top
= infoPtr
->rcList
.top
;
1671 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1672 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1677 * Retrieves the number of items that can fit vertically in the client area.
1680 * [I] infoPtr : valid pointer to the listview structure
1683 * Number of items per row.
1685 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1687 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1689 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1694 * Retrieves the number of items that can fit horizontally in the client
1698 * [I] infoPtr : valid pointer to the listview structure
1701 * Number of items per column.
1703 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1705 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1707 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1711 /*************************************************************************
1712 * LISTVIEW_ProcessLetterKeys
1714 * Processes keyboard messages generated by pressing the letter keys
1716 * What this does is perform a case insensitive search from the
1717 * current position with the following quirks:
1718 * - If two chars or more are pressed in quick succession we search
1719 * for the corresponding string (e.g. 'abc').
1720 * - If there is a delay we wipe away the current search string and
1721 * restart with just that char.
1722 * - If the user keeps pressing the same character, whether slowly or
1723 * fast, so that the search string is entirely composed of this
1724 * character ('aaaaa' for instance), then we search for first item
1725 * that starting with that character.
1726 * - If the user types the above character in quick succession, then
1727 * we must also search for the corresponding string ('aaaaa'), and
1728 * go to that string if there is a match.
1731 * [I] hwnd : handle to the window
1732 * [I] charCode : the character code, the actual character
1733 * [I] keyData : key data
1741 * - The current implementation has a list of characters it will
1742 * accept and it ignores everything else. In particular it will
1743 * ignore accentuated characters which seems to match what
1744 * Windows does. But I'm not sure it makes sense to follow
1746 * - We don't sound a beep when the search fails.
1750 * TREEVIEW_ProcessLetterKeys
1752 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1757 WCHAR buffer
[MAX_PATH
];
1758 DWORD lastKeyPressTimestamp
= infoPtr
->lastKeyPressTimestamp
;
1760 /* simple parameter checking */
1761 if (!charCode
|| !keyData
) return 0;
1763 /* only allow the valid WM_CHARs through */
1764 if (!isalnumW(charCode
) &&
1765 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1766 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1767 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1768 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1769 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1770 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1771 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1772 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1773 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1776 /* if there's one item or less, there is no where to go */
1777 if (infoPtr
->nItemCount
<= 1) return 0;
1779 /* update the search parameters */
1780 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1781 if (infoPtr
->lastKeyPressTimestamp
- lastKeyPressTimestamp
< KEY_DELAY
) {
1782 if (infoPtr
->nSearchParamLength
< MAX_PATH
-1)
1783 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
1784 if (infoPtr
->charCode
!= charCode
)
1785 infoPtr
->charCode
= charCode
= 0;
1787 infoPtr
->charCode
=charCode
;
1788 infoPtr
->szSearchParam
[0]=charCode
;
1789 infoPtr
->nSearchParamLength
=1;
1790 /* Redundant with the 1 char string */
1794 /* and search from the current position */
1796 if (infoPtr
->nFocusedItem
>= 0) {
1797 endidx
=infoPtr
->nFocusedItem
;
1799 /* if looking for single character match,
1800 * then we must always move forward
1802 if (infoPtr
->nSearchParamLength
== 1)
1805 endidx
=infoPtr
->nItemCount
;
1809 /* Let application handle this for virtual listview */
1810 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1815 ZeroMemory(&lvfi
, sizeof(lvfi
));
1816 lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1817 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = '\0';
1818 lvfi
.psz
= infoPtr
->szSearchParam
;
1822 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1825 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1831 if (idx
== infoPtr
->nItemCount
) {
1832 if (endidx
== infoPtr
->nItemCount
|| endidx
== 0)
1838 item
.mask
= LVIF_TEXT
;
1841 item
.pszText
= buffer
;
1842 item
.cchTextMax
= MAX_PATH
;
1843 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1845 /* check for a match */
1846 if (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
1849 } else if ( (charCode
!= 0) && (nItem
== -1) && (nItem
!= infoPtr
->nFocusedItem
) &&
1850 (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
1851 /* This would work but we must keep looking for a longer match */
1855 } while (idx
!= endidx
);
1858 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1863 /*************************************************************************
1864 * LISTVIEW_UpdateHeaderSize [Internal]
1866 * Function to resize the header control
1869 * [I] hwnd : handle to a window
1870 * [I] nNewScrollPos : scroll pos to set
1875 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1880 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1882 if (!infoPtr
->hwndHeader
) return;
1884 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1885 point
[0].x
= winRect
.left
;
1886 point
[0].y
= winRect
.top
;
1887 point
[1].x
= winRect
.right
;
1888 point
[1].y
= winRect
.bottom
;
1890 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1891 point
[0].x
= -nNewScrollPos
;
1892 point
[1].x
+= nNewScrollPos
;
1894 SetWindowPos(infoPtr
->hwndHeader
,0,
1895 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1896 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1897 SWP_NOZORDER
| SWP_NOACTIVATE
);
1902 * Update the scrollbars. This functions should be called whenever
1903 * the content, size or view changes.
1906 * [I] infoPtr : valid pointer to the listview structure
1911 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
1913 SCROLLINFO horzInfo
, vertInfo
;
1916 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
1918 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
1919 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
1920 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1922 /* for now, we'll set info.nMax to the _count_, and adjust it later */
1923 if (infoPtr
->uView
== LV_VIEW_LIST
)
1925 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
1926 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
1928 /* scroll by at least one column per page */
1929 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
1930 horzInfo
.nPage
= infoPtr
->nItemWidth
;
1932 if (infoPtr
->nItemWidth
)
1933 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
1935 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1937 horzInfo
.nMax
= infoPtr
->nItemWidth
;
1939 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
1943 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
1946 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
1948 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
1953 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
1954 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
1956 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
1957 horzInfo
.nMax
= rcHeader
.right
;
1958 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
1962 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1963 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
1964 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
1965 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
1966 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
1968 /* Setting the horizontal scroll can change the listview size
1969 * (and potentially everything else) so we need to recompute
1970 * everything again for the vertical scroll
1973 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
1974 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
1975 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1977 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1979 vertInfo
.nMax
= infoPtr
->nItemCount
;
1981 /* scroll by at least one page */
1982 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
1983 vertInfo
.nPage
= infoPtr
->nItemHeight
;
1985 if (infoPtr
->nItemHeight
> 0)
1986 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
1988 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
1992 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
1995 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1996 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
1997 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
1998 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
1999 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2001 /* Change of the range may have changed the scroll pos. If so move the content */
2002 if (dx
!= 0 || dy
!= 0)
2005 listRect
= infoPtr
->rcList
;
2006 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2007 SW_ERASE
| SW_INVALIDATE
);
2010 /* Update the Header Control */
2011 if (infoPtr
->hwndHeader
)
2013 horzInfo
.fMask
= SIF_POS
;
2014 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2015 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2022 * Shows/hides the focus rectangle.
2025 * [I] infoPtr : valid pointer to the listview structure
2026 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2031 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2035 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2037 if (infoPtr
->nFocusedItem
< 0) return;
2039 /* we need some gymnastics in ICON mode to handle large items */
2040 if (infoPtr
->uView
== LV_VIEW_ICON
)
2044 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2045 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2047 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2052 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2054 /* for some reason, owner draw should work only in report mode */
2055 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2060 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2061 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2063 item
.iItem
= infoPtr
->nFocusedItem
;
2065 item
.mask
= LVIF_PARAM
;
2066 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2068 ZeroMemory(&dis
, sizeof(dis
));
2069 dis
.CtlType
= ODT_LISTVIEW
;
2070 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2071 dis
.itemID
= item
.iItem
;
2072 dis
.itemAction
= ODA_FOCUS
;
2073 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2074 dis
.hwndItem
= infoPtr
->hwndSelf
;
2076 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2077 dis
.itemData
= item
.lParam
;
2079 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2081 SelectObject(hdc
, hOldFont
);
2085 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2088 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2092 * Invalidates all visible selected items.
2094 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2098 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2099 while(iterator_next(&i
))
2101 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2102 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2104 iterator_destroy(&i
);
2109 * DESCRIPTION: [INTERNAL]
2110 * Computes an item's (left,top) corner, relative to rcView.
2111 * That is, the position has NOT been made relative to the Origin.
2112 * This is deliberate, to avoid computing the Origin over, and
2113 * over again, when this function is called in a loop. Instead,
2114 * one can factor the computation of the Origin before the loop,
2115 * and offset the value returned by this function, on every iteration.
2118 * [I] infoPtr : valid pointer to the listview structure
2119 * [I] nItem : item number
2120 * [O] lpptOrig : item top, left corner
2125 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2127 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2129 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2131 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2132 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2134 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2136 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2137 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2138 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2140 else /* LV_VIEW_DETAILS */
2142 lpptPosition
->x
= REPORT_MARGINX
;
2143 /* item is always at zero indexed column */
2144 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2145 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2146 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2151 * DESCRIPTION: [INTERNAL]
2152 * Compute the rectangles of an item. This is to localize all
2153 * the computations in one place. If you are not interested in some
2154 * of these values, simply pass in a NULL -- the function is smart
2155 * enough to compute only what's necessary. The function computes
2156 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2157 * one, the BOX rectangle. This rectangle is very cheap to compute,
2158 * and is guaranteed to contain all the other rectangles. Computing
2159 * the ICON rect is also cheap, but all the others are potentially
2160 * expensive. This gives an easy and effective optimization when
2161 * searching (like point inclusion, or rectangle intersection):
2162 * first test against the BOX, and if TRUE, test against the desired
2164 * If the function does not have all the necessary information
2165 * to computed the requested rectangles, will crash with a
2166 * failed assertion. This is done so we catch all programming
2167 * errors, given that the function is called only from our code.
2169 * We have the following 'special' meanings for a few fields:
2170 * * If LVIS_FOCUSED is set, we assume the item has the focus
2171 * This is important in ICON mode, where it might get a larger
2172 * then usual rectangle
2174 * Please note that subitem support works only in REPORT mode.
2177 * [I] infoPtr : valid pointer to the listview structure
2178 * [I] lpLVItem : item to compute the measures for
2179 * [O] lprcBox : ptr to Box rectangle
2180 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2181 * [0] lprcSelectBox : ptr to select box rectangle
2182 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2183 * [O] lprcIcon : ptr to Icon rectangle
2184 * Same as LVM_GETITEMRECT with LVIR_ICON
2185 * [O] lprcStateIcon: ptr to State Icon rectangle
2186 * [O] lprcLabel : ptr to Label rectangle
2187 * Same as LVM_GETITEMRECT with LVIR_LABEL
2192 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2193 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2194 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2196 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2197 RECT Box
, SelectBox
, Icon
, Label
;
2198 COLUMN_INFO
*lpColumnInfo
= NULL
;
2199 SIZE labelSize
= { 0, 0 };
2201 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2203 /* Be smart and try to figure out the minimum we have to do */
2204 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2205 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2207 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2208 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2210 if (lprcSelectBox
) doSelectBox
= TRUE
;
2211 if (lprcLabel
) doLabel
= TRUE
;
2212 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2219 /************************************************************/
2220 /* compute the box rectangle (it should be cheap to do) */
2221 /************************************************************/
2222 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2223 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2225 if (lpLVItem
->iSubItem
)
2227 Box
= lpColumnInfo
->rcHeader
;
2232 Box
.right
= infoPtr
->nItemWidth
;
2235 Box
.bottom
= infoPtr
->nItemHeight
;
2237 /******************************************************************/
2238 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2239 /******************************************************************/
2242 LONG state_width
= 0;
2244 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2245 state_width
= infoPtr
->iconStateSize
.cx
;
2247 if (infoPtr
->uView
== LV_VIEW_ICON
)
2249 Icon
.left
= Box
.left
+ state_width
;
2250 if (infoPtr
->himlNormal
)
2251 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2252 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2253 Icon
.right
= Icon
.left
;
2254 Icon
.bottom
= Icon
.top
;
2255 if (infoPtr
->himlNormal
)
2257 Icon
.right
+= infoPtr
->iconSize
.cx
;
2258 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2261 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2263 Icon
.left
= Box
.left
+ state_width
;
2265 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2267 /* we need the indent in report mode */
2268 assert(lpLVItem
->mask
& LVIF_INDENT
);
2269 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2273 Icon
.right
= Icon
.left
;
2274 if (infoPtr
->himlSmall
&&
2275 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 || (lpColumnInfo
->fmt
& LVCFMT_IMAGE
) ||
2276 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2277 Icon
.right
+= infoPtr
->iconSize
.cx
;
2278 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2280 if(lprcIcon
) *lprcIcon
= Icon
;
2281 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2283 /* TODO: is this correct? */
2286 lprcStateIcon
->left
= Icon
.left
- state_width
;
2287 lprcStateIcon
->right
= Icon
.left
;
2288 lprcStateIcon
->top
= Icon
.top
;
2289 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2290 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2293 else Icon
.right
= 0;
2295 /************************************************************/
2296 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2297 /************************************************************/
2300 /* calculate how far to the right can the label stretch */
2301 Label
.right
= Box
.right
;
2302 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2304 if (lpLVItem
->iSubItem
== 0)
2306 /* we need a zero based rect here */
2307 Label
= lpColumnInfo
->rcHeader
;
2308 OffsetRect(&Label
, -Label
.left
, 0);
2312 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2314 labelSize
.cx
= infoPtr
->nItemWidth
;
2315 labelSize
.cy
= infoPtr
->nItemHeight
;
2319 /* we need the text in non owner draw mode */
2320 assert(lpLVItem
->mask
& LVIF_TEXT
);
2321 if (is_textT(lpLVItem
->pszText
, TRUE
))
2323 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2324 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2325 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2329 /* compute rough rectangle where the label will go */
2330 SetRectEmpty(&rcText
);
2331 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2332 rcText
.bottom
= infoPtr
->nItemHeight
;
2333 if (infoPtr
->uView
== LV_VIEW_ICON
)
2334 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2336 /* now figure out the flags */
2337 if (infoPtr
->uView
== LV_VIEW_ICON
)
2338 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2340 uFormat
= LV_SL_DT_FLAGS
;
2342 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2344 if (rcText
.right
!= rcText
.left
)
2345 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2347 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2349 SelectObject(hdc
, hOldFont
);
2350 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2354 if (infoPtr
->uView
== LV_VIEW_ICON
)
2356 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2357 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2358 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2359 Label
.right
= Label
.left
+ labelSize
.cx
;
2360 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2361 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2363 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2364 labelSize
.cy
/= infoPtr
->ntmHeight
;
2365 labelSize
.cy
= max(labelSize
.cy
, 1);
2366 labelSize
.cy
*= infoPtr
->ntmHeight
;
2368 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2370 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2372 Label
.left
= Icon
.right
;
2373 Label
.top
= Box
.top
;
2374 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2375 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2376 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2378 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2380 Label
.left
= Icon
.right
;
2381 Label
.top
= Box
.top
;
2382 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2383 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2386 if (lprcLabel
) *lprcLabel
= Label
;
2387 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2390 /************************************************************/
2391 /* compute SELECT bounding box */
2392 /************************************************************/
2395 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2397 SelectBox
.left
= Icon
.left
;
2398 SelectBox
.top
= Box
.top
;
2399 SelectBox
.bottom
= Box
.bottom
;
2402 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2404 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2408 UnionRect(&SelectBox
, &Icon
, &Label
);
2410 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2411 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2414 /* Fix the Box if necessary */
2417 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2418 else *lprcBox
= Box
;
2420 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2424 * DESCRIPTION: [INTERNAL]
2427 * [I] infoPtr : valid pointer to the listview structure
2428 * [I] nItem : item number
2429 * [O] lprcBox : ptr to Box rectangle
2434 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2436 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2437 POINT Position
, Origin
;
2440 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2441 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2443 /* Be smart and try to figure out the minimum we have to do */
2445 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2446 lvItem
.mask
|= LVIF_TEXT
;
2447 lvItem
.iItem
= nItem
;
2448 lvItem
.iSubItem
= 0;
2449 lvItem
.pszText
= szDispText
;
2450 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2451 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2452 if (infoPtr
->uView
== LV_VIEW_ICON
)
2454 lvItem
.mask
|= LVIF_STATE
;
2455 lvItem
.stateMask
= LVIS_FOCUSED
;
2456 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2458 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2460 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2461 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2463 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2466 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2469 /* LISTVIEW_MapIdToIndex helper */
2470 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2472 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2473 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2475 if (id1
->id
== id2
->id
) return 0;
2477 return (id1
->id
< id2
->id
) ? -1 : 1;
2482 * Returns the item index for id specified.
2485 * [I] infoPtr : valid pointer to the listview structure
2486 * [I] iID : item id to get index for
2489 * Item index, or -1 on failure.
2491 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2496 TRACE("iID=%d\n", iID
);
2498 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2499 if (infoPtr
->nItemCount
== 0) return -1;
2502 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, &MapIdSearchCompare
, 0, DPAS_SORTED
);
2506 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2507 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2515 * Returns the item id for index given.
2518 * [I] infoPtr : valid pointer to the listview structure
2519 * [I] iItem : item index to get id for
2524 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2529 TRACE("iItem=%d\n", iItem
);
2531 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2532 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2534 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2535 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2537 return lpItem
->id
->id
;
2542 * Returns the current icon position, and advances it along the top.
2543 * The returned position is not offset by Origin.
2546 * [I] infoPtr : valid pointer to the listview structure
2547 * [O] lpPos : will get the current icon position
2552 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2554 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2556 *lpPos
= infoPtr
->currIconPos
;
2558 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2559 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2561 infoPtr
->currIconPos
.x
= 0;
2562 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2568 * Returns the current icon position, and advances it down the left edge.
2569 * The returned position is not offset by Origin.
2572 * [I] infoPtr : valid pointer to the listview structure
2573 * [O] lpPos : will get the current icon position
2578 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2580 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2582 *lpPos
= infoPtr
->currIconPos
;
2584 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2585 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2587 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2588 infoPtr
->currIconPos
.y
= 0;
2594 * Moves an icon to the specified position.
2595 * It takes care of invalidating the item, etc.
2598 * [I] infoPtr : valid pointer to the listview structure
2599 * [I] nItem : the item to move
2600 * [I] lpPos : the new icon position
2601 * [I] isNew : flags the item as being new
2607 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2613 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2614 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2616 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2617 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2620 /* Allocating a POINTER for every item is too resource intensive,
2621 * so we'll keep the (x,y) in different arrays */
2622 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2623 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2625 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2632 * Arranges listview items in icon display mode.
2635 * [I] infoPtr : valid pointer to the listview structure
2636 * [I] nAlignCode : alignment code
2642 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2644 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2648 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2650 TRACE("nAlignCode=%d\n", nAlignCode
);
2652 if (nAlignCode
== LVA_DEFAULT
)
2654 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2655 else nAlignCode
= LVA_ALIGNTOP
;
2660 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2661 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2662 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2663 default: return FALSE
;
2666 infoPtr
->bAutoarrange
= TRUE
;
2667 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2668 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2670 next_pos(infoPtr
, &pos
);
2671 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2679 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2680 * For LVS_REPORT always returns empty rectangle.
2683 * [I] infoPtr : valid pointer to the listview structure
2684 * [O] lprcView : bounding rectangle
2690 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2694 SetRectEmpty(lprcView
);
2696 switch (infoPtr
->uView
)
2699 case LV_VIEW_SMALLICON
:
2700 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2702 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2703 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2704 lprcView
->right
= max(lprcView
->right
, x
);
2705 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2707 if (infoPtr
->nItemCount
> 0)
2709 lprcView
->right
+= infoPtr
->nItemWidth
;
2710 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2715 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2716 x
= infoPtr
->nItemCount
/ y
;
2717 if (infoPtr
->nItemCount
% y
) x
++;
2718 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2719 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2726 * Retrieves the bounding rectangle of all the items.
2729 * [I] infoPtr : valid pointer to the listview structure
2730 * [O] lprcView : bounding rectangle
2736 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2740 TRACE("(lprcView=%p)\n", lprcView
);
2742 if (!lprcView
) return FALSE
;
2744 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2746 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2748 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2749 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2752 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2759 * Retrieves the subitem pointer associated with the subitem index.
2762 * [I] hdpaSubItems : DPA handle for a specific item
2763 * [I] nSubItem : index of subitem
2766 * SUCCESS : subitem pointer
2769 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2771 SUBITEM_INFO
*lpSubItem
;
2774 /* we should binary search here if need be */
2775 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2777 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2778 if (lpSubItem
->iSubItem
== nSubItem
)
2788 * Calculates the desired item width.
2791 * [I] infoPtr : valid pointer to the listview structure
2794 * The desired item width.
2796 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2800 TRACE("uView=%d\n", infoPtr
->uView
);
2802 if (infoPtr
->uView
== LV_VIEW_ICON
)
2803 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2804 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2806 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2811 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2812 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2814 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2815 nItemWidth
= rcHeader
.right
;
2818 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2820 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2824 lvItem
.mask
= LVIF_TEXT
;
2825 lvItem
.iSubItem
= 0;
2827 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2830 lvItem
.pszText
= szDispText
;
2831 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2832 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2833 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2837 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2838 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2840 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2848 * Calculates the desired item height.
2851 * [I] infoPtr : valid pointer to the listview structure
2854 * The desired item height.
2856 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2860 TRACE("uView=%d\n", infoPtr
->uView
);
2862 if (infoPtr
->uView
== LV_VIEW_ICON
)
2863 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2866 nItemHeight
= infoPtr
->ntmHeight
;
2867 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
2869 if (infoPtr
->himlState
)
2870 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2871 if (infoPtr
->himlSmall
)
2872 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2873 if (infoPtr
->himlState
|| infoPtr
->himlSmall
)
2874 nItemHeight
+= HEIGHT_PADDING
;
2875 if (infoPtr
->nMeasureItemHeight
> 0)
2876 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2879 return max(nItemHeight
, 1);
2884 * Updates the width, and height of an item.
2887 * [I] infoPtr : valid pointer to the listview structure
2892 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2894 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2895 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2901 * Retrieves and saves important text metrics info for the current
2905 * [I] infoPtr : valid pointer to the listview structure
2908 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2910 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2911 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2912 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2916 if (GetTextMetricsW(hdc
, &tm
))
2918 infoPtr
->ntmHeight
= tm
.tmHeight
;
2919 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
2922 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
2923 infoPtr
->nEllipsisWidth
= sz
.cx
;
2925 SelectObject(hdc
, hOldFont
);
2926 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2928 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
2933 * A compare function for ranges
2936 * [I] range1 : pointer to range 1;
2937 * [I] range2 : pointer to range 2;
2941 * > 0 : if range 1 > range 2
2942 * < 0 : if range 2 > range 1
2943 * = 0 : if range intersects range 2
2945 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
2949 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
2951 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
2956 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
2962 #define ranges_check(ranges, desc) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
2964 #define ranges_check(ranges, desc) do { } while(0)
2967 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *func
, int line
)
2972 TRACE("*** Checking %s:%d:%s ***\n", func
, line
, desc
);
2974 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
2975 ranges_dump(ranges
);
2976 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
2978 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
2979 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
2980 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2982 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
2983 assert (prev
->upper
<= curr
->lower
);
2984 assert (curr
->lower
< curr
->upper
);
2988 TRACE("--- Done checking---\n");
2991 static RANGES
ranges_create(int count
)
2993 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
2994 if (!ranges
) return NULL
;
2995 ranges
->hdpa
= DPA_Create(count
);
2996 if (ranges
->hdpa
) return ranges
;
3001 static void ranges_clear(RANGES ranges
)
3005 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3006 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3007 DPA_DeleteAllPtrs(ranges
->hdpa
);
3011 static void ranges_destroy(RANGES ranges
)
3013 if (!ranges
) return;
3014 ranges_clear(ranges
);
3015 DPA_Destroy(ranges
->hdpa
);
3019 static RANGES
ranges_clone(RANGES ranges
)
3024 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3026 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3028 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3029 if (!newrng
) goto fail
;
3030 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3031 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3036 TRACE ("clone failed\n");
3037 ranges_destroy(clone
);
3041 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3045 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3046 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3051 static void ranges_dump(RANGES ranges
)
3055 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3056 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3059 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3061 RANGE srchrng
= { nItem
, nItem
+ 1 };
3063 TRACE("(nItem=%d)\n", nItem
);
3064 ranges_check(ranges
, "before contain");
3065 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3068 static INT
ranges_itemcount(RANGES ranges
)
3072 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3074 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3075 count
+= sel
->upper
- sel
->lower
;
3081 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3083 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3086 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3087 if (index
== -1) return TRUE
;
3089 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3091 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3092 if (chkrng
->lower
>= nItem
)
3093 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3094 if (chkrng
->upper
> nItem
)
3095 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3100 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3105 TRACE("(%s)\n", debugrange(&range
));
3106 ranges_check(ranges
, "before add");
3108 /* try find overlapping regions first */
3109 srchrgn
.lower
= range
.lower
- 1;
3110 srchrgn
.upper
= range
.upper
+ 1;
3111 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3117 TRACE("Adding new range\n");
3119 /* create the brand new range to insert */
3120 newrgn
= Alloc(sizeof(RANGE
));
3121 if(!newrgn
) goto fail
;
3124 /* figure out where to insert it */
3125 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3126 TRACE("index=%d\n", index
);
3127 if (index
== -1) index
= 0;
3129 /* and get it over with */
3130 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3138 RANGE
*chkrgn
, *mrgrgn
;
3139 INT fromindex
, mergeindex
;
3141 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3142 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3144 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3145 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3147 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3149 /* merge now common ranges */
3151 srchrgn
.lower
= chkrgn
->lower
- 1;
3152 srchrgn
.upper
= chkrgn
->upper
+ 1;
3156 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3157 if (mergeindex
== -1) break;
3158 if (mergeindex
== index
)
3160 fromindex
= index
+ 1;
3164 TRACE("Merge with index %i\n", mergeindex
);
3166 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3167 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3168 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3170 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3171 if (mergeindex
< index
) index
--;
3175 ranges_check(ranges
, "after add");
3179 ranges_check(ranges
, "failed add");
3183 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3188 TRACE("(%s)\n", debugrange(&range
));
3189 ranges_check(ranges
, "before del");
3191 /* we don't use DPAS_SORTED here, since we need *
3192 * to find the first overlapping range */
3193 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3196 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3198 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3200 /* case 1: Same range */
3201 if ( (chkrgn
->upper
== range
.upper
) &&
3202 (chkrgn
->lower
== range
.lower
) )
3204 DPA_DeletePtr(ranges
->hdpa
, index
);
3208 /* case 2: engulf */
3209 else if ( (chkrgn
->upper
<= range
.upper
) &&
3210 (chkrgn
->lower
>= range
.lower
) )
3212 DPA_DeletePtr(ranges
->hdpa
, index
);
3215 /* case 3: overlap upper */
3216 else if ( (chkrgn
->upper
<= range
.upper
) &&
3217 (chkrgn
->lower
< range
.lower
) )
3219 chkrgn
->upper
= range
.lower
;
3221 /* case 4: overlap lower */
3222 else if ( (chkrgn
->upper
> range
.upper
) &&
3223 (chkrgn
->lower
>= range
.lower
) )
3225 chkrgn
->lower
= range
.upper
;
3228 /* case 5: fully internal */
3231 RANGE tmprgn
= *chkrgn
, *newrgn
;
3233 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3234 newrgn
->lower
= chkrgn
->lower
;
3235 newrgn
->upper
= range
.lower
;
3236 chkrgn
->lower
= range
.upper
;
3237 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3246 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3249 ranges_check(ranges
, "after del");
3253 ranges_check(ranges
, "failed del");
3259 * Removes all selection ranges
3262 * [I] infoPtr : valid pointer to the listview structure
3263 * [I] toSkip : item range to skip removing the selection
3269 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3278 lvItem
.stateMask
= LVIS_SELECTED
;
3280 /* need to clone the DPA because callbacks can change it */
3281 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3282 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3283 while(iterator_next(&i
))
3284 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3285 /* note that the iterator destructor will free the cloned range */
3286 iterator_destroy(&i
);
3291 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3295 if (!(toSkip
= ranges_create(1))) return FALSE
;
3296 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3297 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3298 ranges_destroy(toSkip
);
3302 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3304 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3309 * Retrieves the number of items that are marked as selected.
3312 * [I] infoPtr : valid pointer to the listview structure
3315 * Number of items selected.
3317 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3319 INT nSelectedCount
= 0;
3321 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3324 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3326 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3331 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3333 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3334 return nSelectedCount
;
3339 * Manages the item focus.
3342 * [I] infoPtr : valid pointer to the listview structure
3343 * [I] nItem : item index
3346 * TRUE : focused item changed
3347 * FALSE : focused item has NOT changed
3349 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3351 INT oldFocus
= infoPtr
->nFocusedItem
;
3354 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3356 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3357 lvItem
.stateMask
= LVIS_FOCUSED
;
3358 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3360 return oldFocus
!= infoPtr
->nFocusedItem
;
3363 /* Helper function for LISTVIEW_ShiftIndices *only* */
3364 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3366 if (nShiftItem
< nItem
) return nShiftItem
;
3368 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3370 if (direction
> 0) return nShiftItem
+ direction
;
3372 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3377 * Updates the various indices after an item has been inserted or deleted.
3380 * [I] infoPtr : valid pointer to the listview structure
3381 * [I] nItem : item index
3382 * [I] direction : Direction of shift, +1 or -1.
3387 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3392 /* temporarily disable change notification while shifting items */
3393 bOldChange
= infoPtr
->bDoChangeNotify
;
3394 infoPtr
->bDoChangeNotify
= FALSE
;
3396 TRACE("Shifting %iu, %i steps\n", nItem
, direction
);
3398 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3400 assert(abs(direction
) == 1);
3402 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3404 nNewFocus
= shift_item(infoPtr
, infoPtr
->nFocusedItem
, nItem
, direction
);
3405 if (nNewFocus
!= infoPtr
->nFocusedItem
)
3406 LISTVIEW_SetItemFocus(infoPtr
, nNewFocus
);
3408 /* But we are not supposed to modify nHotItem! */
3410 infoPtr
->bDoChangeNotify
= bOldChange
;
3416 * Adds a block of selections.
3419 * [I] infoPtr : valid pointer to the listview structure
3420 * [I] nItem : item index
3423 * Whether the window is still valid.
3425 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3427 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3428 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3429 HWND hwndSelf
= infoPtr
->hwndSelf
;
3430 NMLVODSTATECHANGE nmlv
;
3435 /* Temporarily disable change notification
3436 * If the control is LVS_OWNERDATA, we need to send
3437 * only one LVN_ODSTATECHANGED notification.
3438 * See MSDN documentation for LVN_ITEMCHANGED.
3440 bOldChange
= infoPtr
->bDoChangeNotify
;
3441 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3443 if (nFirst
== -1) nFirst
= nItem
;
3445 item
.state
= LVIS_SELECTED
;
3446 item
.stateMask
= LVIS_SELECTED
;
3448 for (i
= nFirst
; i
<= nLast
; i
++)
3449 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3451 ZeroMemory(&nmlv
, sizeof(nmlv
));
3452 nmlv
.iFrom
= nFirst
;
3455 nmlv
.uOldState
= item
.state
;
3457 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3458 if (!IsWindow(hwndSelf
))
3460 infoPtr
->bDoChangeNotify
= bOldChange
;
3467 * Sets a single group selection.
3470 * [I] infoPtr : valid pointer to the listview structure
3471 * [I] nItem : item index
3476 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3483 if (!(selection
= ranges_create(100))) return;
3485 item
.state
= LVIS_SELECTED
;
3486 item
.stateMask
= LVIS_SELECTED
;
3488 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3490 if (infoPtr
->nSelectionMark
== -1)
3492 infoPtr
->nSelectionMark
= nItem
;
3493 ranges_additem(selection
, nItem
);
3499 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3500 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3501 ranges_add(selection
, sel
);
3506 RECT rcItem
, rcSel
, rcSelMark
;
3509 rcItem
.left
= LVIR_BOUNDS
;
3510 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return;
3511 rcSelMark
.left
= LVIR_BOUNDS
;
3512 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) return;
3513 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3514 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3515 while(iterator_next(&i
))
3517 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3518 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3520 iterator_destroy(&i
);
3523 /* disable per item notifications on LVS_OWNERDATA style
3524 FIXME: single LVN_ODSTATECHANGED should be used */
3525 bOldChange
= infoPtr
->bDoChangeNotify
;
3526 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3528 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3531 iterator_rangesitems(&i
, selection
);
3532 while(iterator_next(&i
))
3533 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3534 /* this will also destroy the selection */
3535 iterator_destroy(&i
);
3537 infoPtr
->bDoChangeNotify
= bOldChange
;
3539 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3544 * Sets a single selection.
3547 * [I] infoPtr : valid pointer to the listview structure
3548 * [I] nItem : item index
3553 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3557 TRACE("nItem=%d\n", nItem
);
3559 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3561 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3562 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3563 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3565 infoPtr
->nSelectionMark
= nItem
;
3570 * Set selection(s) with keyboard.
3573 * [I] infoPtr : valid pointer to the listview structure
3574 * [I] nItem : item index
3575 * [I] space : VK_SPACE code sent
3578 * SUCCESS : TRUE (needs to be repainted)
3579 * FAILURE : FALSE (nothing has changed)
3581 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3583 /* FIXME: pass in the state */
3584 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3585 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3586 BOOL bResult
= FALSE
;
3588 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3589 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3593 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3594 LISTVIEW_SetSelection(infoPtr
, nItem
);
3598 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3602 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3603 lvItem
.stateMask
= LVIS_SELECTED
;
3606 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3607 if (lvItem
.state
& LVIS_SELECTED
)
3608 infoPtr
->nSelectionMark
= nItem
;
3610 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3613 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3616 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3620 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3622 LVHITTESTINFO lvHitTestInfo
;
3624 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3625 lvHitTestInfo
.pt
.x
= pt
.x
;
3626 lvHitTestInfo
.pt
.y
= pt
.y
;
3628 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3630 lpLVItem
->mask
= LVIF_PARAM
;
3631 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3632 lpLVItem
->iSubItem
= 0;
3634 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3637 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3639 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3640 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3641 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3646 * Called when the mouse is being actively tracked and has hovered for a specified
3650 * [I] infoPtr : valid pointer to the listview structure
3651 * [I] fwKeys : key indicator
3652 * [I] x,y : mouse position
3655 * 0 if the message was processed, non-zero if there was an error
3658 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3659 * over the item for a certain period of time.
3662 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3666 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3668 if (LISTVIEW_IsHotTracking(infoPtr
))
3676 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3677 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3679 SetFocus(infoPtr
->hwndSelf
);
3685 #define SCROLL_LEFT 0x1
3686 #define SCROLL_RIGHT 0x2
3687 #define SCROLL_UP 0x4
3688 #define SCROLL_DOWN 0x8
3692 * Utility routine to draw and highlight items within a marquee selection rectangle.
3695 * [I] infoPtr : valid pointer to the listview structure
3696 * [I] coords_orig : original co-ordinates of the cursor
3697 * [I] coords_offs : offsetted coordinates of the cursor
3698 * [I] offset : offset amount
3699 * [I] scroll : Bitmask of which directions we should scroll, if at all
3704 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, LPPOINT coords_orig
, LPPOINT coords_offs
, LPPOINT offset
, INT scroll
)
3706 BOOL controlDown
= FALSE
;
3711 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3713 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3714 rect
.right
= coords_offs
->x
;
3718 rect
.left
= coords_offs
->x
;
3719 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3722 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3724 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3725 rect
.bottom
= coords_offs
->y
;
3729 rect
.top
= coords_offs
->y
;
3730 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3733 /* Cancel out the old marquee rectangle and draw the new one */
3734 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3736 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3737 the cursor is further away */
3739 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3740 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3742 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3743 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3745 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3746 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3748 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3749 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3751 /* Invert the items in the old marquee rectangle */
3752 iterator_frameditems_absolute(&i
, infoPtr
, &infoPtr
->marqueeRect
);
3754 while (iterator_next(&i
))
3758 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3761 item
.state
= LVIS_SELECTED
;
3763 item
.stateMask
= LVIS_SELECTED
;
3765 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3769 iterator_destroy(&i
);
3771 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3773 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3774 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3776 /* Iterate over the items within our marquee rectangle */
3777 iterator_frameditems_absolute(&i
, infoPtr
, &infoPtr
->marqueeRect
);
3779 if (GetKeyState(VK_CONTROL
) & 0x8000)
3782 while (iterator_next(&i
))
3786 /* If CTRL is pressed, invert. If not, always select the item. */
3787 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
)))
3790 item
.state
= LVIS_SELECTED
;
3792 item
.stateMask
= LVIS_SELECTED
;
3794 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3798 iterator_destroy(&i
);
3799 LISTVIEW_InvalidateRect(infoPtr
, &rect
);
3804 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3805 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3808 * [I] hwnd : Handle to the listview
3809 * [I] uMsg : WM_TIMER (ignored)
3810 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3811 * [I] dwTimer : The elapsed time (ignored)
3816 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3818 LISTVIEW_INFO
*infoPtr
;
3819 SCROLLINFO scrollInfo
;
3825 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3830 /* Get the current cursor position and convert to client coordinates */
3831 GetCursorPos(&coords_orig
);
3832 ScreenToClient(hWnd
, &coords_orig
);
3834 /* Ensure coordinates are within client bounds */
3835 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3836 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3839 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3841 /* Offset coordinates by the appropriate amount */
3842 coords_offs
.x
-= offset
.x
;
3843 coords_offs
.y
-= offset
.y
;
3845 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3846 scrollInfo
.fMask
= SIF_ALL
;
3848 /* Work out in which directions we can scroll */
3849 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3851 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3852 scroll
|= SCROLL_UP
;
3854 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3855 scroll
|= SCROLL_DOWN
;
3858 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3860 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3861 scroll
|= SCROLL_LEFT
;
3863 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3864 scroll
|= SCROLL_RIGHT
;
3867 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3868 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3869 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3870 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3872 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3878 * Called whenever WM_MOUSEMOVE is received.
3881 * [I] infoPtr : valid pointer to the listview structure
3882 * [I] fwKeys : key indicator
3883 * [I] x,y : mouse position
3886 * 0 if the message is processed, non-zero if there was an error
3888 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3890 if (!(fwKeys
& MK_LBUTTON
))
3891 infoPtr
->bLButtonDown
= FALSE
;
3893 if (infoPtr
->bLButtonDown
)
3897 LVHITTESTINFO lvHitTestInfo
;
3898 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3899 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3901 if (infoPtr
->bMarqueeSelect
)
3911 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3913 /* Ensure coordinates are within client bounds */
3914 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
3915 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
3917 /* Offset coordinates by the appropriate amount */
3918 coords_offs
.x
-= offset
.x
;
3919 coords_offs
.y
-= offset
.y
;
3921 /* Enable the timer if we're going outside our bounds, in case the user doesn't
3922 move the mouse again */
3924 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
3925 (y
>= infoPtr
->rcList
.bottom
))
3927 if (!infoPtr
->bScrolling
)
3929 infoPtr
->bScrolling
= TRUE
;
3930 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
3935 infoPtr
->bScrolling
= FALSE
;
3936 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
3939 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
3943 rect
.left
= infoPtr
->ptClickPos
.x
- wDragWidth
;
3944 rect
.right
= infoPtr
->ptClickPos
.x
+ wDragWidth
;
3945 rect
.top
= infoPtr
->ptClickPos
.y
- wDragHeight
;
3946 rect
.bottom
= infoPtr
->ptClickPos
.y
+ wDragHeight
;
3951 lvHitTestInfo
.pt
= tmp
;
3952 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
3954 /* reset item marker */
3955 if (infoPtr
->nLButtonDownItem
!= lvHitTestInfo
.iItem
)
3956 infoPtr
->nLButtonDownItem
= -1;
3958 if (!PtInRect(&rect
, tmp
))
3960 /* this path covers the following:
3961 1. WM_LBUTTONDOWN over selected item (sets focus on it)
3962 2. change focus with keys
3963 3. move mouse over item from step 1 selects it and moves focus on it */
3964 if (infoPtr
->nLButtonDownItem
!= -1 &&
3965 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
3969 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3970 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3972 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
3973 infoPtr
->nLButtonDownItem
= -1;
3976 if (!infoPtr
->bDragging
)
3978 lvHitTestInfo
.pt
= infoPtr
->ptClickPos
;
3979 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
3981 /* If the click is outside the range of an item, begin a
3982 highlight. If not, begin an item drag. */
3983 if (lvHitTestInfo
.iItem
== -1)
3987 /* If we're allowing multiple selections, send notification.
3988 If return value is non-zero, cancel. */
3989 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
3991 /* Store the absolute coordinates of the click */
3993 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3995 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
3996 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
3998 /* Begin selection and capture mouse */
3999 infoPtr
->bMarqueeSelect
= TRUE
;
4000 SetCapture(infoPtr
->hwndSelf
);
4007 ZeroMemory(&nmlv
, sizeof(nmlv
));
4008 nmlv
.iItem
= lvHitTestInfo
.iItem
;
4009 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4011 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4012 infoPtr
->bDragging
= TRUE
;
4020 /* see if we are supposed to be tracking mouse hovering */
4021 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4022 TRACKMOUSEEVENT trackinfo
;
4024 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4025 trackinfo
.dwFlags
= TME_QUERY
;
4027 /* see if we are already tracking this hwnd */
4028 _TrackMouseEvent(&trackinfo
);
4030 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4031 trackinfo
.dwFlags
= TME_HOVER
;
4032 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4033 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4035 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4036 _TrackMouseEvent(&trackinfo
);
4045 * Tests whether the item is assignable to a list with style lStyle
4047 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4049 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4050 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4051 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4059 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
4062 * [I] infoPtr : valid pointer to the listview structure
4063 * [I] lpLVItem : valid pointer to new item attributes
4064 * [I] isNew : the item being set is being inserted
4065 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4066 * [O] bChanged : will be set to TRUE if the item really changed
4072 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4078 /* stateMask is ignored for LVM_INSERTITEM */
4079 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4083 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4085 if (lpLVItem
->mask
== 0) return TRUE
;
4087 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4089 /* a virtual listview only stores selection and focus */
4090 if (lpLVItem
->mask
& ~LVIF_STATE
)
4096 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4097 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4101 /* we need to get the lParam and state of the item */
4102 item
.iItem
= lpLVItem
->iItem
;
4103 item
.iSubItem
= lpLVItem
->iSubItem
;
4104 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4105 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4109 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4111 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4112 /* determine what fields will change */
4113 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4114 uChanged
|= LVIF_STATE
;
4116 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4117 uChanged
|= LVIF_IMAGE
;
4119 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4120 uChanged
|= LVIF_PARAM
;
4122 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4123 uChanged
|= LVIF_INDENT
;
4125 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4126 uChanged
|= LVIF_TEXT
;
4128 TRACE("uChanged=0x%x\n", uChanged
);
4129 if (!uChanged
) return TRUE
;
4132 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
4133 nmlv
.iItem
= lpLVItem
->iItem
;
4134 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4135 nmlv
.uOldState
= item
.state
;
4136 nmlv
.uChanged
= uChanged
;
4137 nmlv
.lParam
= item
.lParam
;
4139 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
4140 /* and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications */
4142 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4144 HWND hwndSelf
= infoPtr
->hwndSelf
;
4146 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4148 if (!IsWindow(hwndSelf
))
4152 /* copy information */
4153 if (lpLVItem
->mask
& LVIF_TEXT
)
4154 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4156 if (lpLVItem
->mask
& LVIF_IMAGE
)
4157 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4159 if (lpLVItem
->mask
& LVIF_PARAM
)
4160 lpItem
->lParam
= lpLVItem
->lParam
;
4162 if (lpLVItem
->mask
& LVIF_INDENT
)
4163 lpItem
->iIndent
= lpLVItem
->iIndent
;
4165 if (uChanged
& LVIF_STATE
)
4167 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4169 lpItem
->state
&= ~stateMask
;
4170 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4172 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4174 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4175 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4177 else if (stateMask
& LVIS_SELECTED
)
4179 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4181 /* if we are asked to change focus, and we manage it, do it */
4182 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4184 if (lpLVItem
->state
& LVIS_FOCUSED
)
4186 if (infoPtr
->nFocusedItem
!= -1)
4188 /* remove current focus */
4189 item
.mask
= LVIF_STATE
;
4191 item
.stateMask
= LVIS_FOCUSED
;
4193 /* recurse with redrawing an item */
4194 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4197 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4198 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4200 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4202 infoPtr
->nFocusedItem
= -1;
4207 /* if we're inserting the item, we're done */
4208 if (isNew
) return TRUE
;
4210 /* send LVN_ITEMCHANGED notification */
4211 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4212 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4219 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4222 * [I] infoPtr : valid pointer to the listview structure
4223 * [I] lpLVItem : valid pointer to new subitem attributes
4224 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4225 * [O] bChanged : will be set to TRUE if the item really changed
4231 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4234 SUBITEM_INFO
*lpSubItem
;
4236 /* we do not support subitems for virtual listviews */
4237 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4239 /* set subitem only if column is present */
4240 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4242 /* First do some sanity checks */
4243 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4244 particularly useful. We currently do not actually do anything with
4245 the flag on subitems.
4247 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
)) return FALSE
;
4248 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4250 /* get the subitem structure, and create it if not there */
4251 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4252 assert (hdpaSubItems
);
4254 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4257 SUBITEM_INFO
*tmpSubItem
;
4260 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4261 if (!lpSubItem
) return FALSE
;
4262 /* we could binary search here, if need be...*/
4263 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4265 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4266 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4268 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4273 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4274 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4278 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4280 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4284 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4286 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4295 * Sets item attributes.
4298 * [I] infoPtr : valid pointer to the listview structure
4299 * [I] lpLVItem : new item attributes
4300 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4306 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4308 HWND hwndSelf
= infoPtr
->hwndSelf
;
4309 LPWSTR pszText
= NULL
;
4310 BOOL bResult
, bChanged
= FALSE
;
4312 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4314 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4317 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4318 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_textW(lpLVItem
->pszText
))
4320 pszText
= lpLVItem
->pszText
;
4321 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4324 /* actually set the fields */
4325 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4327 if (lpLVItem
->iSubItem
)
4328 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4330 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4331 if (!IsWindow(hwndSelf
))
4334 /* redraw item, if necessary */
4335 if (bChanged
&& !infoPtr
->bIsDrawing
)
4337 /* this little optimization eliminates some nasty flicker */
4338 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4339 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4340 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4341 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4343 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4348 textfreeT(lpLVItem
->pszText
, isW
);
4349 lpLVItem
->pszText
= pszText
;
4357 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4360 * [I] infoPtr : valid pointer to the listview structure
4365 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4368 SCROLLINFO scrollInfo
;
4370 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4371 scrollInfo
.fMask
= SIF_POS
;
4373 if (infoPtr
->uView
== LV_VIEW_LIST
)
4375 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4376 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4378 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4380 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4381 nItem
= scrollInfo
.nPos
;
4385 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4386 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4389 TRACE("nItem=%d\n", nItem
);
4397 * Erases the background of the given rectangle
4400 * [I] infoPtr : valid pointer to the listview structure
4401 * [I] hdc : device context handle
4402 * [I] lprcBox : clipping rectangle
4408 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4410 if (!infoPtr
->hBkBrush
) return FALSE
;
4412 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4414 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4422 * [I] infoPtr : valid pointer to the listview structure
4423 * [I] hdc : device context handle
4424 * [I] nItem : item index
4425 * [I] nSubItem : subitem index
4426 * [I] pos : item position in client coordinates
4427 * [I] cdmode : custom draw mode
4433 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
4436 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4437 static WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4438 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4440 RECT rcSelect
, rcBox
, rcIcon
, rcLabel
, rcStateIcon
;
4441 NMLVCUSTOMDRAW nmlvcd
;
4446 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, wine_dbgstr_point(&pos
));
4448 /* get information needed for drawing the item */
4449 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
4450 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
;
4451 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4452 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
;
4453 lvItem
.iItem
= nItem
;
4454 lvItem
.iSubItem
= nSubItem
;
4457 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4458 lvItem
.pszText
= szDispText
;
4459 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4460 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4461 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4462 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
4463 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4465 /* now check if we need to update the focus rectangle */
4466 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4468 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4469 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4470 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4471 OffsetRect(&rcSelect
, pos
.x
, pos
.y
);
4472 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
4473 OffsetRect(&rcStateIcon
, pos
.x
, pos
.y
);
4474 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
4475 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4476 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4477 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4479 /* fill in the custom draw structure */
4480 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4482 hOldFont
= GetCurrentObject(hdc
, OBJ_FONT
);
4483 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
4484 if (cdmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4485 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4486 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4487 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
4488 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4489 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
4490 if (nSubItem
== 0 && cdsubitemmode
== CDRF_NOTIFYITEMDRAW
)
4492 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4493 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4495 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4496 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4497 else if ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) == FALSE
)
4498 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4500 /* in full row select, subitems, will just use main item's colors */
4501 if (nSubItem
&& infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4502 nmlvcd
.clrTextBk
= CLR_NONE
;
4504 /* FIXME: temporary hack */
4505 rcSelect
.left
= rcLabel
.left
;
4507 /* draw the selection background, if we're drawing the main item */
4510 /* in icon mode, the label rect is really what we want to draw the
4512 if (infoPtr
->uView
== LV_VIEW_ICON
)
4515 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4517 /* we have to update left focus bound too if item isn't in leftmost column
4518 and reduce right box bound */
4519 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4523 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4525 INT Originx
= pos
.x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4526 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4527 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4529 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4530 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4534 rcSelect
.right
= rcBox
.right
;
4537 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
4538 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4539 /* store new focus rectangle */
4540 if (infoPtr
->nFocusedItem
== nItem
) infoPtr
->rcFocus
= rcSelect
;
4544 if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && (nSubItem
== 0))
4546 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
4549 TRACE("uStateImage=%d\n", uStateImage
);
4550 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
,
4551 rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4556 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4557 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4561 TRACE("iImage=%d\n", lvItem
.iImage
);
4563 if (lvItem
.state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4564 style
= ILD_SELECTED
;
4568 ImageList_DrawEx(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
4569 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4570 lvItem
.state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4574 /* Don't bother painting item being edited */
4575 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
4577 /* figure out the text drawing flags */
4578 uFormat
= (infoPtr
->uView
== LV_VIEW_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4579 if (infoPtr
->uView
== LV_VIEW_ICON
)
4580 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4583 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4585 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
4586 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
4587 default: uFormat
|= DT_LEFT
;
4590 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
4592 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4593 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4595 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4597 /* for GRIDLINES reduce the bottom so the text formats correctly */
4598 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4601 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
4604 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4605 notify_postpaint(infoPtr
, &nmlvcd
);
4606 if (cdsubitemmode
& CDRF_NEWFONT
)
4607 SelectObject(hdc
, hOldFont
);
4613 * Draws listview items when in owner draw mode.
4616 * [I] infoPtr : valid pointer to the listview structure
4617 * [I] hdc : device context handle
4622 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4624 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4625 DWORD cditemmode
= CDRF_DODEFAULT
;
4626 NMLVCUSTOMDRAW nmlvcd
;
4627 POINT Origin
, Position
;
4633 ZeroMemory(&dis
, sizeof(dis
));
4635 /* Get scroll info once before loop */
4636 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4638 /* iterate through the invalidated rows */
4639 while(iterator_next(i
))
4641 item
.iItem
= i
->nItem
;
4643 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4644 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4645 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4647 dis
.CtlType
= ODT_LISTVIEW
;
4649 dis
.itemID
= item
.iItem
;
4650 dis
.itemAction
= ODA_DRAWENTIRE
;
4652 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4653 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4654 dis
.hwndItem
= infoPtr
->hwndSelf
;
4656 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4657 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4658 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4659 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4660 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4661 dis
.itemData
= item
.lParam
;
4663 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4666 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4667 * structure for the rest. of the paint cycle
4669 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4670 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4671 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4673 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4675 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4676 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4679 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4680 notify_postpaint(infoPtr
, &nmlvcd
);
4686 * Draws listview items when in report display mode.
4689 * [I] infoPtr : valid pointer to the listview structure
4690 * [I] hdc : device context handle
4691 * [I] cdmode : custom draw mode
4696 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4699 RECT rcClip
, rcItem
;
4700 POINT Origin
, Position
;
4707 /* figure out what to draw */
4708 rgntype
= GetClipBox(hdc
, &rcClip
);
4709 if (rgntype
== NULLREGION
) return;
4711 /* Get scroll info once before loop */
4712 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4714 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4716 /* narrow down the columns we need to paint */
4717 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4719 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4721 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4722 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4723 ranges_additem(colRanges
, index
);
4725 iterator_rangesitems(&j
, colRanges
);
4727 /* in full row select, we _have_ to draw the main item */
4728 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4731 /* iterate through the invalidated rows */
4732 while(iterator_next(i
))
4734 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4735 Position
.y
+= Origin
.y
;
4737 /* iterate through the invalidated columns */
4738 while(iterator_next(&j
))
4740 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4741 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4743 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4746 rcItem
.bottom
= infoPtr
->nItemHeight
;
4747 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4748 if (!RectVisible(hdc
, &rcItem
)) continue;
4751 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
4754 iterator_destroy(&j
);
4759 * Draws the gridlines if necessary when in report display mode.
4762 * [I] infoPtr : valid pointer to the listview structure
4763 * [I] hdc : device context handle
4768 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4774 RECT rcClip
, rcItem
= {0};
4782 /* figure out what to draw */
4783 rgntype
= GetClipBox(hdc
, &rcClip
);
4784 if (rgntype
== NULLREGION
) return;
4786 /* Get scroll info once before loop */
4787 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4789 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4791 /* narrow down the columns we need to paint */
4792 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4794 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4796 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4797 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4798 ranges_additem(colRanges
, index
);
4801 /* is right most vertical line visible? */
4802 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4804 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4805 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4806 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
4809 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
4811 hOldPen
= SelectObject ( hdc
, hPen
);
4813 /* draw the vertical lines for the columns */
4814 iterator_rangesitems(&j
, colRanges
);
4815 while(iterator_next(&j
))
4817 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4818 if (rcItem
.left
== 0) continue; /* skip leftmost column */
4819 rcItem
.left
+= Origin
.x
;
4820 rcItem
.right
+= Origin
.x
;
4821 rcItem
.top
= infoPtr
->rcList
.top
;
4822 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
4823 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
4824 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4825 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
4827 iterator_destroy(&j
);
4828 /* draw rightmost grid line if visible */
4831 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4832 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4833 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4835 rcItem
.right
+= Origin
.x
;
4837 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
4838 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
4841 /* draw the horizontial lines for the rows */
4842 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
4843 rcItem
.left
= infoPtr
->rcList
.left
;
4844 rcItem
.right
= infoPtr
->rcList
.right
;
4845 rcItem
.bottom
= rcItem
.top
= Origin
.y
- 1;
4846 MoveToEx(hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4847 LineTo(hdc
, rcItem
.right
, rcItem
.top
);
4848 for(y
=itemheight
-1+Origin
.y
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
4850 rcItem
.bottom
= rcItem
.top
= y
;
4851 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
4852 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4853 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
4856 SelectObject( hdc
, hOldPen
);
4857 DeleteObject( hPen
);
4863 * Draws listview items when in list display mode.
4866 * [I] infoPtr : valid pointer to the listview structure
4867 * [I] hdc : device context handle
4868 * [I] cdmode : custom draw mode
4873 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4875 POINT Origin
, Position
;
4877 /* Get scroll info once before loop */
4878 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4880 while(iterator_prev(i
))
4882 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4883 Position
.x
+= Origin
.x
;
4884 Position
.y
+= Origin
.y
;
4886 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
4893 * Draws listview items.
4896 * [I] infoPtr : valid pointer to the listview structure
4897 * [I] hdc : device context handle
4898 * [I] prcErase : rect to be erased before refresh (may be NULL)
4903 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
4905 COLORREF oldTextColor
= 0, oldBkColor
= 0, oldClrTextBk
, oldClrText
;
4906 NMLVCUSTOMDRAW nmlvcd
;
4913 HBITMAP hbmp
= NULL
;
4916 LISTVIEW_DUMP(infoPtr
);
4918 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4919 TRACE("double buffering\n");
4921 hdc
= CreateCompatibleDC(hdcOrig
);
4923 ERR("Failed to create DC for backbuffer\n");
4926 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
4927 infoPtr
->rcList
.bottom
);
4929 ERR("Failed to create bitmap for backbuffer\n");
4934 SelectObject(hdc
, hbmp
);
4935 SelectObject(hdc
, infoPtr
->hFont
);
4937 /* Save dc values we're gonna trash while drawing
4938 * FIXME: Should be done in LISTVIEW_DrawItem() */
4939 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4940 oldBkMode
= GetBkMode(hdc
);
4941 oldBkColor
= GetBkColor(hdc
);
4942 oldTextColor
= GetTextColor(hdc
);
4945 infoPtr
->bIsDrawing
= TRUE
;
4948 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
4949 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4950 /* If no erasing was done (usually because RedrawWindow was called
4951 * with RDW_INVALIDATE only) we need to copy the old contents into
4952 * the backbuffer before continuing. */
4953 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
4954 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
4955 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
4956 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
4959 /* FIXME: Shouldn't need to do this */
4960 oldClrTextBk
= infoPtr
->clrTextBk
;
4961 oldClrText
= infoPtr
->clrText
;
4963 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
4965 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
4966 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
4967 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4968 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
4969 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4971 /* Use these colors to draw the items */
4972 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
4973 infoPtr
->clrText
= nmlvcd
.clrText
;
4975 /* nothing to draw */
4976 if(infoPtr
->nItemCount
== 0) goto enddraw
;
4978 /* figure out what we need to draw */
4979 iterator_visibleitems(&i
, infoPtr
, hdc
);
4980 range
= iterator_range(&i
);
4982 /* send cache hint notification */
4983 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4987 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
4988 nmlv
.iFrom
= range
.lower
;
4989 nmlv
.iTo
= range
.upper
- 1;
4990 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
4993 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
4994 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
4997 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4998 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
4999 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5000 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5002 /* if we have a focus rect and it's visible, draw it */
5003 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5004 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5005 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5007 iterator_destroy(&i
);
5010 /* For LVS_EX_GRIDLINES go and draw lines */
5011 /* This includes the case where there were *no* items */
5012 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5013 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5015 /* Draw marquee rectangle if appropriate */
5016 if (infoPtr
->bMarqueeSelect
)
5017 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5019 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5020 notify_postpaint(infoPtr
, &nmlvcd
);
5022 infoPtr
->clrTextBk
= oldClrTextBk
;
5023 infoPtr
->clrText
= oldClrText
;
5026 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5027 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5028 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5029 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5034 SelectObject(hdc
, hOldFont
);
5035 SetBkMode(hdc
, oldBkMode
);
5036 SetBkColor(hdc
, oldBkColor
);
5037 SetTextColor(hdc
, oldTextColor
);
5040 infoPtr
->bIsDrawing
= FALSE
;
5046 * Calculates the approximate width and height of a given number of items.
5049 * [I] infoPtr : valid pointer to the listview structure
5050 * [I] nItemCount : number of items
5051 * [I] wWidth : width
5052 * [I] wHeight : height
5055 * Returns a DWORD. The width in the low word and the height in high word.
5057 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5058 WORD wWidth
, WORD wHeight
)
5060 INT nItemCountPerColumn
= 1;
5061 INT nColumnCount
= 0;
5062 DWORD dwViewRect
= 0;
5064 if (nItemCount
== -1)
5065 nItemCount
= infoPtr
->nItemCount
;
5067 if (infoPtr
->uView
== LV_VIEW_LIST
)
5069 if (wHeight
== 0xFFFF)
5071 /* use current height */
5072 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5075 if (wHeight
< infoPtr
->nItemHeight
)
5076 wHeight
= infoPtr
->nItemHeight
;
5080 if (infoPtr
->nItemHeight
> 0)
5082 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5083 if (nItemCountPerColumn
== 0)
5084 nItemCountPerColumn
= 1;
5086 if (nItemCount
% nItemCountPerColumn
!= 0)
5087 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5089 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5093 /* Microsoft padding magic */
5094 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5095 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5097 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5099 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5103 if (infoPtr
->nItemCount
> 0)
5105 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5106 wWidth
= rcBox
.right
- rcBox
.left
;
5107 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5111 /* use current height and width */
5112 if (wHeight
== 0xffff)
5113 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5114 if (wWidth
== 0xffff)
5115 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5118 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5120 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5126 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5127 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5129 if (nItemCount
== -1)
5130 nItemCount
= infoPtr
->nItemCount
;
5132 if (wWidth
== 0xffff)
5133 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5135 if (wWidth
< nItemWidth
)
5136 wWidth
= nItemWidth
;
5138 cols
= wWidth
/ nItemWidth
;
5139 if (cols
> nItemCount
)
5146 rows
= nItemCount
/ cols
;
5147 if (nItemCount
% cols
)
5153 wHeight
= (nItemHeight
* rows
)+2;
5154 wWidth
= (nItemWidth
* cols
)+2;
5156 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5158 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5159 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5166 * Cancel edit label with saving item text.
5169 * [I] infoPtr : valid pointer to the listview structure
5172 * Always returns TRUE.
5174 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5176 if (infoPtr
->hwndEdit
)
5178 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5179 HWND edit
= infoPtr
->hwndEdit
;
5181 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5182 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5190 * Create a drag image list for the specified item.
5193 * [I] infoPtr : valid pointer to the listview structure
5194 * [I] iItem : index of item
5195 * [O] lppt : Upper-left corner of the image
5198 * Returns a handle to the image list if successful, NULL otherwise.
5200 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5206 HBITMAP hbmp
, hOldbmp
;
5207 HIMAGELIST dragList
= 0;
5208 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5210 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5213 rcItem
.left
= LVIR_BOUNDS
;
5214 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5217 lppt
->x
= rcItem
.left
;
5218 lppt
->y
= rcItem
.top
;
5220 size
.cx
= rcItem
.right
- rcItem
.left
;
5221 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5223 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5224 hdc
= CreateCompatibleDC(hdcOrig
);
5225 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5226 hOldbmp
= SelectObject(hdc
, hbmp
);
5228 rcItem
.left
= rcItem
.top
= 0;
5229 rcItem
.right
= size
.cx
;
5230 rcItem
.bottom
= size
.cy
;
5231 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5234 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
5236 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5237 SelectObject(hdc
, hOldbmp
);
5238 ImageList_Add(dragList
, hbmp
, 0);
5241 SelectObject(hdc
, hOldbmp
);
5245 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5247 TRACE("ret=%p\n", dragList
);
5255 * Removes all listview items and subitems.
5258 * [I] infoPtr : valid pointer to the listview structure
5264 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5267 HDPA hdpaSubItems
= NULL
;
5276 /* we do it directly, to avoid notifications */
5277 ranges_clear(infoPtr
->selectionRanges
);
5278 infoPtr
->nSelectionMark
= -1;
5279 infoPtr
->nFocusedItem
= -1;
5280 SetRectEmpty(&infoPtr
->rcFocus
);
5281 /* But we are supposed to leave nHotItem as is! */
5284 /* send LVN_DELETEALLITEMS notification */
5285 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
5287 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5289 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5291 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5293 /* send LVN_DELETEITEM notification, if not suppressed
5294 and if it is not a virtual listview */
5295 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
5296 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5297 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5298 /* free id struct */
5299 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5300 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5301 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5303 /* both item and subitem start with ITEMHDR header */
5304 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5306 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5307 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5310 DPA_Destroy(hdpaSubItems
);
5311 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5313 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5314 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5315 infoPtr
->nItemCount
--;
5320 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5321 LISTVIEW_UpdateScroll(infoPtr
);
5323 LISTVIEW_InvalidateList(infoPtr
);
5330 * Scrolls, and updates the columns, when a column is changing width.
5333 * [I] infoPtr : valid pointer to the listview structure
5334 * [I] nColumn : column to scroll
5335 * [I] dx : amount of scroll, in pixels
5340 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5342 COLUMN_INFO
*lpColumnInfo
;
5348 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5349 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5350 rcCol
= lpColumnInfo
->rcHeader
;
5351 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5352 rcCol
.left
= rcCol
.right
;
5354 /* adjust the other columns */
5355 hdi
.mask
= HDI_ORDER
;
5356 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5358 INT nOrder
= hdi
.iOrder
;
5359 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5361 hdi
.mask
= HDI_ORDER
;
5362 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5363 if (hdi
.iOrder
>= nOrder
) {
5364 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5365 lpColumnInfo
->rcHeader
.left
+= dx
;
5366 lpColumnInfo
->rcHeader
.right
+= dx
;
5371 /* do not update screen if not in report mode */
5372 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5374 /* Need to reset the item width when inserting a new column */
5375 infoPtr
->nItemWidth
+= dx
;
5377 LISTVIEW_UpdateScroll(infoPtr
);
5378 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5380 /* scroll to cover the deleted column, and invalidate for redraw */
5381 rcOld
= infoPtr
->rcList
;
5382 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5383 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5388 * Removes a column from the listview control.
5391 * [I] infoPtr : valid pointer to the listview structure
5392 * [I] nColumn : column index
5398 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5402 TRACE("nColumn=%d\n", nColumn
);
5404 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5405 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5407 /* While the MSDN specifically says that column zero should not be deleted,
5408 what actually happens is that the column itself is deleted but no items or subitems
5412 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5414 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5417 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5418 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5420 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5422 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5424 INT nItem
, nSubItem
, i
;
5426 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5428 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5431 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5433 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5434 if (lpSubItem
->iSubItem
== nColumn
)
5437 lpDelItem
= lpSubItem
;
5439 else if (lpSubItem
->iSubItem
> nColumn
)
5441 lpSubItem
->iSubItem
--;
5445 /* if we found our subitem, zapp it */
5449 if (is_textW(lpDelItem
->hdr
.pszText
))
5450 Free(lpDelItem
->hdr
.pszText
);
5455 /* free dpa memory */
5456 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5461 /* update the other column info */
5462 LISTVIEW_UpdateItemSize(infoPtr
);
5463 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5464 LISTVIEW_InvalidateList(infoPtr
);
5466 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5473 * Invalidates the listview after an item's insertion or deletion.
5476 * [I] infoPtr : valid pointer to the listview structure
5477 * [I] nItem : item index
5478 * [I] dir : -1 if deleting, 1 if inserting
5483 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5485 INT nPerCol
, nItemCol
, nItemRow
;
5489 /* if we don't refresh, what's the point of scrolling? */
5490 if (!is_redrawing(infoPtr
)) return;
5492 assert (abs(dir
) == 1);
5494 /* arrange icons if autoarrange is on */
5495 if (is_autoarrange(infoPtr
))
5497 BOOL arrange
= TRUE
;
5498 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5499 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5500 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5503 /* scrollbars need updating */
5504 LISTVIEW_UpdateScroll(infoPtr
);
5506 /* figure out the item's position */
5507 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5508 nPerCol
= infoPtr
->nItemCount
+ 1;
5509 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5510 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5511 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5514 nItemCol
= nItem
/ nPerCol
;
5515 nItemRow
= nItem
% nPerCol
;
5516 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5518 /* move the items below up a slot */
5519 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5520 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5521 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5522 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5523 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5524 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5525 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5527 TRACE("Scrolling rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5528 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5529 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5532 /* report has only that column, so we're done */
5533 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5535 /* now for LISTs, we have to deal with the columns to the right */
5536 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5538 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5539 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5540 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5541 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5542 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5543 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5548 * Removes an item from the listview control.
5551 * [I] infoPtr : valid pointer to the listview structure
5552 * [I] nItem : item index
5558 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5561 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5563 TRACE("(nItem=%d)\n", nItem
);
5565 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5567 /* remove selection, and focus */
5569 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5570 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5572 /* send LVN_DELETEITEM notification. */
5573 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5575 /* we need to do this here, because we'll be deleting stuff */
5577 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5579 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5587 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5588 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5590 /* free id struct */
5591 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5592 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5593 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5595 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5597 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5598 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5601 DPA_Destroy(hdpaSubItems
);
5606 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5607 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5610 infoPtr
->nItemCount
--;
5611 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5613 /* now is the invalidation fun */
5615 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5622 * Callback implementation for editlabel control
5625 * [I] infoPtr : valid pointer to the listview structure
5626 * [I] storeText : store edit box text as item text
5627 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5633 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5635 HWND hwndSelf
= infoPtr
->hwndSelf
;
5636 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5637 NMLVDISPINFOW dispInfo
;
5638 INT editedItem
= infoPtr
->nEditLabelItem
;
5640 WCHAR
*pszText
= NULL
;
5645 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5649 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5651 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5652 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5657 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5659 infoPtr
->nEditLabelItem
= -1;
5660 infoPtr
->hwndEdit
= 0;
5662 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5663 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5664 dispInfo
.item
.iItem
= editedItem
;
5665 dispInfo
.item
.iSubItem
= 0;
5666 dispInfo
.item
.stateMask
= ~0;
5667 dispInfo
.item
.pszText
= szDispText
;
5668 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5669 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5676 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5679 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5680 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5681 textfreeT(tmp
, FALSE
);
5684 /* add the text from the edit in */
5685 dispInfo
.item
.mask
|= LVIF_TEXT
;
5686 dispInfo
.item
.pszText
= bSame
? NULL
: pszText
;
5687 dispInfo
.item
.cchTextMax
= bSame
? 0 : textlenT(pszText
, isW
);
5689 /* Do we need to update the Item Text */
5690 if (!notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
))
5695 if (!IsWindow(hwndSelf
))
5700 if (!pszText
) return TRUE
;
5707 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5709 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5710 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5711 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5713 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5719 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5720 dispInfo
.item
.mask
= LVIF_TEXT
;
5721 dispInfo
.item
.iItem
= editedItem
;
5722 dispInfo
.item
.iSubItem
= 0;
5723 dispInfo
.item
.pszText
= pszText
;
5724 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5725 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5735 * Subclassed edit control windproc function
5738 * [I] hwnd : the edit window handle
5739 * [I] uMsg : the message that is to be processed
5740 * [I] wParam : first message parameter
5741 * [I] lParam : second message parameter
5742 * [I] isW : TRUE if input is Unicode
5747 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5749 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5752 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5753 hwnd
, uMsg
, wParam
, lParam
, isW
);
5758 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5762 WNDPROC editProc
= infoPtr
->EditWndProc
;
5763 infoPtr
->EditWndProc
= 0;
5764 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5765 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5769 if (VK_ESCAPE
== (INT
)wParam
)
5774 else if (VK_RETURN
== (INT
)wParam
)
5778 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5782 if (infoPtr
->hwndEdit
)
5783 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5785 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
5791 * Subclassed edit control Unicode windproc function
5794 * [I] hwnd : the edit window handle
5795 * [I] uMsg : the message that is to be processed
5796 * [I] wParam : first message parameter
5797 * [I] lParam : second message parameter
5801 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5803 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
5808 * Subclassed edit control ANSI windproc function
5811 * [I] hwnd : the edit window handle
5812 * [I] uMsg : the message that is to be processed
5813 * [I] wParam : first message parameter
5814 * [I] lParam : second message parameter
5818 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5820 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
5825 * Creates a subclassed edit control
5828 * [I] infoPtr : valid pointer to the listview structure
5829 * [I] text : initial text for the edit
5830 * [I] style : the window style
5831 * [I] isW : TRUE if input is Unicode
5835 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
5837 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
5838 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
5841 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
5843 /* Window will be resized and positioned after LVN_BEGINLABELEDIT */
5845 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5847 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5849 if (!hedit
) return 0;
5851 infoPtr
->EditWndProc
= (WNDPROC
)
5852 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
5853 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
5855 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
5862 * Begin in place editing of specified list view item
5865 * [I] infoPtr : valid pointer to the listview structure
5866 * [I] nItem : item index
5867 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
5873 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
5875 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5876 NMLVDISPINFOW dispInfo
;
5879 HWND hwndSelf
= infoPtr
->hwndSelf
;
5881 HFONT hOldFont
= NULL
;
5882 TEXTMETRICW textMetric
;
5884 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
5886 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
5888 /* Is the EditBox still there, if so remove it */
5889 if(infoPtr
->hwndEdit
!= 0)
5891 SetFocus(infoPtr
->hwndSelf
);
5892 infoPtr
->hwndEdit
= 0;
5895 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5897 infoPtr
->nEditLabelItem
= nItem
;
5899 LISTVIEW_SetSelection(infoPtr
, nItem
);
5900 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
5901 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5903 rect
.left
= LVIR_LABEL
;
5904 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
5906 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5907 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5908 dispInfo
.item
.iItem
= nItem
;
5909 dispInfo
.item
.iSubItem
= 0;
5910 dispInfo
.item
.stateMask
= ~0;
5911 dispInfo
.item
.pszText
= szDispText
;
5912 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5913 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
5915 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
5916 if (!infoPtr
->hwndEdit
) return 0;
5918 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
5920 if (!IsWindow(hwndSelf
))
5922 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
5923 infoPtr
->hwndEdit
= 0;
5927 /* Now position and display edit box */
5928 hdc
= GetDC(infoPtr
->hwndSelf
);
5930 /* Select the font to get appropriate metric dimensions */
5931 if(infoPtr
->hFont
!= 0)
5932 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5934 /* Get String Length in pixels */
5935 GetTextExtentPoint32W(hdc
, dispInfo
.item
.pszText
, lstrlenW(dispInfo
.item
.pszText
), &sz
);
5937 /* Add Extra spacing for the next character */
5938 GetTextMetricsW(hdc
, &textMetric
);
5939 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
5941 if(infoPtr
->hFont
!= 0)
5942 SelectObject(hdc
, hOldFont
);
5944 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
5946 MoveWindow(infoPtr
->hwndEdit
, rect
.left
- 2, rect
.top
- 1, sz
.cx
,
5947 rect
.bottom
- rect
.top
+ 2, FALSE
);
5948 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
5949 SetFocus(infoPtr
->hwndEdit
);
5950 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
5951 return infoPtr
->hwndEdit
;
5957 * Ensures the specified item is visible, scrolling into view if necessary.
5960 * [I] infoPtr : valid pointer to the listview structure
5961 * [I] nItem : item index
5962 * [I] bPartial : partially or entirely visible
5968 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
5970 INT nScrollPosHeight
= 0;
5971 INT nScrollPosWidth
= 0;
5972 INT nHorzAdjust
= 0;
5973 INT nVertAdjust
= 0;
5976 RECT rcItem
, rcTemp
;
5978 rcItem
.left
= LVIR_BOUNDS
;
5979 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
5981 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
5983 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
5985 /* scroll left/right, but in LV_VIEW_DETAILS mode */
5986 if (infoPtr
->uView
== LV_VIEW_LIST
)
5987 nScrollPosWidth
= infoPtr
->nItemWidth
;
5988 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
5989 nScrollPosWidth
= 1;
5991 if (rcItem
.left
< infoPtr
->rcList
.left
)
5994 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
5999 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6003 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6005 /* scroll up/down, but not in LVS_LIST mode */
6006 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6007 nScrollPosHeight
= infoPtr
->nItemHeight
;
6008 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6009 nScrollPosHeight
= 1;
6011 if (rcItem
.top
< infoPtr
->rcList
.top
)
6014 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6019 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6023 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6025 if (nScrollPosWidth
)
6027 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6028 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6029 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
6032 if (nScrollPosHeight
)
6034 INT diff
= nVertDiff
/ nScrollPosHeight
;
6035 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6036 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
6044 * Searches for an item with specific characteristics.
6047 * [I] hwnd : window handle
6048 * [I] nStart : base item index
6049 * [I] lpFindInfo : item information to look for
6052 * SUCCESS : index of item
6055 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6056 const LVFINDINFOW
*lpFindInfo
)
6058 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6059 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6060 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6061 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6062 POINT Position
, Destination
;
6065 /* Search in virtual listviews should be done by application, not by
6066 listview control, so we just send LVN_ODFINDITEMW and return the result */
6067 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6071 nmlv
.iStart
= nStart
;
6072 nmlv
.lvfi
= *lpFindInfo
;
6073 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6076 if (!lpFindInfo
|| nItem
< 0) return -1;
6079 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6080 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6082 lvItem
.mask
|= LVIF_TEXT
;
6083 lvItem
.pszText
= szDispText
;
6084 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6087 if (lpFindInfo
->flags
& LVFI_WRAP
)
6090 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6091 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6096 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6097 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6098 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6099 switch(lpFindInfo
->vkDirection
)
6101 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6102 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6103 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6104 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6105 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6106 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6107 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6109 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6110 Destination
.x
= rcArea
.right
;
6111 Destination
.y
= rcArea
.bottom
;
6113 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6117 else Destination
.x
= Destination
.y
= 0;
6119 /* if LVFI_PARAM is specified, all other flags are ignored */
6120 if (lpFindInfo
->flags
& LVFI_PARAM
)
6122 lvItem
.mask
|= LVIF_PARAM
;
6124 lvItem
.mask
&= ~LVIF_TEXT
;
6128 for (; nItem
< nLast
; nItem
++)
6130 lvItem
.iItem
= nItem
;
6131 lvItem
.iSubItem
= 0;
6132 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6134 if (lvItem
.mask
& LVIF_PARAM
)
6136 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6142 if (lvItem
.mask
& LVIF_TEXT
)
6144 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6146 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6147 if (!p
|| p
!= lvItem
.pszText
) continue;
6151 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6155 if (!bNearest
) return nItem
;
6157 /* This is very inefficient. To do a good job here,
6158 * we need a sorted array of (x,y) item positions */
6159 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6161 /* compute the distance^2 to the destination */
6162 xdist
= Destination
.x
- Position
.x
;
6163 ydist
= Destination
.y
- Position
.y
;
6164 dist
= xdist
* xdist
+ ydist
* ydist
;
6166 /* remember the distance, and item if it's closer */
6170 nNearestItem
= nItem
;
6177 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6182 return nNearestItem
;
6187 * Searches for an item with specific characteristics.
6190 * [I] hwnd : window handle
6191 * [I] nStart : base item index
6192 * [I] lpFindInfo : item information to look for
6195 * SUCCESS : index of item
6198 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6199 const LVFINDINFOA
*lpFindInfo
)
6201 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6202 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6207 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6208 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6209 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6210 textfreeT(strW
, FALSE
);
6216 * Retrieves the background image of the listview control.
6219 * [I] infoPtr : valid pointer to the listview structure
6220 * [O] lpBkImage : background image attributes
6226 /* static BOOL LISTVIEW_GetBkImage(const LISTVIEW_INFO *infoPtr, LPLVBKIMAGE lpBkImage) */
6228 /* FIXME (listview, "empty stub!\n"); */
6234 * Retrieves column attributes.
6237 * [I] infoPtr : valid pointer to the listview structure
6238 * [I] nColumn : column index
6239 * [IO] lpColumn : column information
6240 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6241 * otherwise it is in fact a LPLVCOLUMNA
6247 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6249 COLUMN_INFO
*lpColumnInfo
;
6252 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6253 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6255 /* initialize memory */
6256 ZeroMemory(&hdi
, sizeof(hdi
));
6258 if (lpColumn
->mask
& LVCF_TEXT
)
6260 hdi
.mask
|= HDI_TEXT
;
6261 hdi
.pszText
= lpColumn
->pszText
;
6262 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6265 if (lpColumn
->mask
& LVCF_IMAGE
)
6266 hdi
.mask
|= HDI_IMAGE
;
6268 if (lpColumn
->mask
& LVCF_ORDER
)
6269 hdi
.mask
|= HDI_ORDER
;
6271 if (lpColumn
->mask
& LVCF_SUBITEM
)
6272 hdi
.mask
|= HDI_LPARAM
;
6274 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6276 if (lpColumn
->mask
& LVCF_FMT
)
6277 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6279 if (lpColumn
->mask
& LVCF_WIDTH
)
6280 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6282 if (lpColumn
->mask
& LVCF_IMAGE
)
6283 lpColumn
->iImage
= hdi
.iImage
;
6285 if (lpColumn
->mask
& LVCF_ORDER
)
6286 lpColumn
->iOrder
= hdi
.iOrder
;
6288 if (lpColumn
->mask
& LVCF_SUBITEM
)
6289 lpColumn
->iSubItem
= hdi
.lParam
;
6291 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6292 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6298 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6300 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
6305 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6310 * Retrieves the column width.
6313 * [I] infoPtr : valid pointer to the listview structure
6314 * [I] int : column index
6317 * SUCCESS : column width
6320 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6322 INT nColumnWidth
= 0;
6325 TRACE("nColumn=%d\n", nColumn
);
6327 /* we have a 'column' in LIST and REPORT mode only */
6328 switch(infoPtr
->uView
)
6331 nColumnWidth
= infoPtr
->nItemWidth
;
6333 case LV_VIEW_DETAILS
:
6334 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6335 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6336 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6338 * TODO: should we do the same in LVM_GETCOLUMN?
6340 hdItem
.mask
= HDI_WIDTH
;
6341 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6343 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6346 nColumnWidth
= hdItem
.cxy
;
6350 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6351 return nColumnWidth
;
6356 * In list or report display mode, retrieves the number of items that can fit
6357 * vertically in the visible area. In icon or small icon display mode,
6358 * retrieves the total number of visible items.
6361 * [I] infoPtr : valid pointer to the listview structure
6364 * Number of fully visible items.
6366 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6368 switch (infoPtr
->uView
)
6371 case LV_VIEW_SMALLICON
:
6372 return infoPtr
->nItemCount
;
6373 case LV_VIEW_DETAILS
:
6374 return LISTVIEW_GetCountPerColumn(infoPtr
);
6376 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6384 * Retrieves an image list handle.
6387 * [I] infoPtr : valid pointer to the listview structure
6388 * [I] nImageList : image list identifier
6391 * SUCCESS : image list handle
6394 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6398 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6399 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6400 case LVSIL_STATE
: return infoPtr
->himlState
;
6401 case LVSIL_GROUPHEADER
:
6402 FIXME("LVSIL_GROUPHEADER not supported\n");
6405 WARN("got unknown imagelist index - %d\n", nImageList
);
6410 /* LISTVIEW_GetISearchString */
6414 * Retrieves item attributes.
6417 * [I] hwnd : window handle
6418 * [IO] lpLVItem : item info
6419 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6420 * if FALSE, then lpLVItem is a LPLVITEMA.
6423 * This is the internal 'GetItem' interface -- it tries to
6424 * be smart and avoid text copies, if possible, by modifying
6425 * lpLVItem->pszText to point to the text string. Please note
6426 * that this is not always possible (e.g. OWNERDATA), so on
6427 * entry you *must* supply valid values for pszText, and cchTextMax.
6428 * The only difference to the documented interface is that upon
6429 * return, you should use *only* the lpLVItem->pszText, rather than
6430 * the buffer pointer you provided on input. Most code already does
6431 * that, so it's not a problem.
6432 * For the two cases when the text must be copied (that is,
6433 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6439 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6441 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6442 NMLVDISPINFOW dispInfo
;
6448 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6450 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6453 if (lpLVItem
->mask
== 0) return TRUE
;
6455 /* make a local copy */
6456 isubitem
= lpLVItem
->iSubItem
;
6458 /* a quick optimization if all we're asked is the focus state
6459 * these queries are worth optimising since they are common,
6460 * and can be answered in constant time, without the heavy accesses */
6461 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6462 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6464 lpLVItem
->state
= 0;
6465 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6466 lpLVItem
->state
|= LVIS_FOCUSED
;
6470 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6472 /* if the app stores all the data, handle it separately */
6473 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6475 dispInfo
.item
.state
= 0;
6477 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6478 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6479 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6481 UINT mask
= lpLVItem
->mask
;
6483 /* NOTE: copy only fields which we _know_ are initialized, some apps
6484 * depend on the uninitialized fields being 0 */
6485 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6486 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6487 dispInfo
.item
.iSubItem
= isubitem
;
6488 if (lpLVItem
->mask
& LVIF_TEXT
)
6490 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6492 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6495 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6496 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6499 if (lpLVItem
->mask
& LVIF_STATE
)
6500 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6501 /* could be zeroed on LVIF_NORECOMPUTE case */
6502 if (dispInfo
.item
.mask
!= 0)
6504 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6505 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6506 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6508 /* full size structure expected - _WIN32IE >= 0x560 */
6509 *lpLVItem
= dispInfo
.item
;
6511 else if (lpLVItem
->mask
& LVIF_INDENT
)
6513 /* indent member expected - _WIN32IE >= 0x300 */
6514 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6518 /* minimal structure expected */
6519 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6521 lpLVItem
->mask
= mask
;
6522 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6526 /* make sure lParam is zeroed out */
6527 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6529 /* callback marked pointer required here */
6530 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6531 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6533 /* we store only a little state, so if we're not asked, we're done */
6534 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6536 /* if focus is handled by us, report it */
6537 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6539 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6540 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6541 lpLVItem
->state
|= LVIS_FOCUSED
;
6544 /* and do the same for selection, if we handle it */
6545 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6547 lpLVItem
->state
&= ~LVIS_SELECTED
;
6548 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6549 lpLVItem
->state
|= LVIS_SELECTED
;
6555 /* find the item and subitem structures before we proceed */
6556 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6557 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6562 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6563 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6566 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6571 pItemHdr
= &lpItem
->hdr
;
6573 /* Do we need to query the state from the app? */
6574 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6576 dispInfo
.item
.mask
|= LVIF_STATE
;
6577 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6580 /* Do we need to enquire about the image? */
6581 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6582 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6584 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6585 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6588 /* Only items support indentation */
6589 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6592 dispInfo
.item
.mask
|= LVIF_INDENT
;
6593 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6596 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6597 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6598 !is_textW(pItemHdr
->pszText
))
6600 dispInfo
.item
.mask
|= LVIF_TEXT
;
6601 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6602 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6603 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6604 *dispInfo
.item
.pszText
= '\0';
6607 /* If we don't have all the requested info, query the application */
6608 if (dispInfo
.item
.mask
!= 0)
6610 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6611 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6612 dispInfo
.item
.lParam
= lpItem
->lParam
;
6613 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6614 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6617 /* we should not store values for subitems */
6618 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6620 /* Now, handle the iImage field */
6621 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6623 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6624 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6625 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6627 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6629 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6630 lpLVItem
->iImage
= pItemHdr
->iImage
;
6632 lpLVItem
->iImage
= 0;
6635 /* The pszText field */
6636 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6638 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6639 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6641 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6643 else if (lpLVItem
->mask
& LVIF_TEXT
)
6645 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6646 if (isW
|| !is_textW(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6647 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6650 /* Next is the lParam field */
6651 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6653 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6654 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6655 lpItem
->lParam
= dispInfo
.item
.lParam
;
6657 else if (lpLVItem
->mask
& LVIF_PARAM
)
6658 lpLVItem
->lParam
= lpItem
->lParam
;
6660 /* if this is a subitem, we're done */
6661 if (isubitem
) return TRUE
;
6663 /* ... the state field (this one is different due to uCallbackmask) */
6664 if (lpLVItem
->mask
& LVIF_STATE
)
6666 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6667 if (dispInfo
.item
.mask
& LVIF_STATE
)
6669 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6670 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6672 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6674 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6675 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6676 lpLVItem
->state
|= LVIS_FOCUSED
;
6678 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6680 lpLVItem
->state
&= ~LVIS_SELECTED
;
6681 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6682 lpLVItem
->state
|= LVIS_SELECTED
;
6686 /* and last, but not least, the indent field */
6687 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6689 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6690 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6691 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6693 else if (lpLVItem
->mask
& LVIF_INDENT
)
6695 lpLVItem
->iIndent
= lpItem
->iIndent
;
6703 * Retrieves item attributes.
6706 * [I] hwnd : window handle
6707 * [IO] lpLVItem : item info
6708 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6709 * if FALSE, then lpLVItem is a LPLVITEMA.
6712 * This is the external 'GetItem' interface -- it properly copies
6713 * the text in the provided buffer.
6719 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6724 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6727 pszText
= lpLVItem
->pszText
;
6728 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6729 if (bResult
&& lpLVItem
->pszText
!= pszText
)
6731 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6732 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6734 pszText
= LPSTR_TEXTCALLBACKW
;
6736 lpLVItem
->pszText
= pszText
;
6744 * Retrieves the position (upper-left) of the listview control item.
6745 * Note that for LVS_ICON style, the upper-left is that of the icon
6746 * and not the bounding box.
6749 * [I] infoPtr : valid pointer to the listview structure
6750 * [I] nItem : item index
6751 * [O] lpptPosition : coordinate information
6757 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6761 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6763 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6765 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6766 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6768 if (infoPtr
->uView
== LV_VIEW_ICON
)
6770 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6771 lpptPosition
->y
+= ICON_TOP_PADDING
;
6773 lpptPosition
->x
+= Origin
.x
;
6774 lpptPosition
->y
+= Origin
.y
;
6776 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6783 * Retrieves the bounding rectangle for a listview control item.
6786 * [I] infoPtr : valid pointer to the listview structure
6787 * [I] nItem : item index
6788 * [IO] lprc : bounding rectangle coordinates
6789 * lprc->left specifies the portion of the item for which the bounding
6790 * rectangle will be retrieved.
6792 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6793 * including the icon and label.
6796 * * Experiment shows that native control returns:
6797 * * width = min (48, length of text line)
6798 * * .left = position.x - (width - iconsize.cx)/2
6799 * * .right = .left + width
6800 * * height = #lines of text * ntmHeight + icon height + 8
6801 * * .top = position.y - 2
6802 * * .bottom = .top + height
6803 * * separation between items .y = itemSpacing.cy - height
6804 * * .x = itemSpacing.cx - width
6805 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6808 * * Experiment shows that native control returns:
6809 * * width = iconSize.cx + 16
6810 * * .left = position.x - (width - iconsize.cx)/2
6811 * * .right = .left + width
6812 * * height = iconSize.cy + 4
6813 * * .top = position.y - 2
6814 * * .bottom = .top + height
6815 * * separation between items .y = itemSpacing.cy - height
6816 * * .x = itemSpacing.cx - width
6817 * LVIR_LABEL Returns the bounding rectangle of the item text.
6820 * * Experiment shows that native control returns:
6821 * * width = text length
6822 * * .left = position.x - width/2
6823 * * .right = .left + width
6824 * * height = ntmH * linecount + 2
6825 * * .top = position.y + iconSize.cy + 6
6826 * * .bottom = .top + height
6827 * * separation between items .y = itemSpacing.cy - height
6828 * * .x = itemSpacing.cx - width
6829 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6830 * rectangles, but excludes columns in report view.
6837 * Note that the bounding rectangle of the label in the LVS_ICON view depends
6838 * upon whether the window has the focus currently and on whether the item
6839 * is the one with the focus. Ensure that the control's record of which
6840 * item has the focus agrees with the items' records.
6842 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6844 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6845 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
6846 POINT Position
, Origin
;
6850 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
6852 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6854 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6855 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6857 /* Be smart and try to figure out the minimum we have to do */
6858 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
6859 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
6860 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
6861 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
6862 oversizedBox
= TRUE
;
6864 /* get what we need from the item before hand, so we make
6865 * only one request. This can speed up things, if data
6866 * is stored on the app side */
6868 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6869 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
6870 lvItem
.iItem
= nItem
;
6871 lvItem
.iSubItem
= 0;
6872 lvItem
.pszText
= szDispText
;
6873 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6874 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6875 /* we got the state already up, simulate it here, to avoid a reget */
6876 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
6878 lvItem
.mask
|= LVIF_STATE
;
6879 lvItem
.stateMask
= LVIS_FOCUSED
;
6880 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
6883 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
6884 lprc
->left
= LVIR_BOUNDS
;
6890 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
6894 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
6898 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
6901 case LVIR_SELECTBOUNDS
:
6902 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
6906 WARN("Unknown value: %d\n", lprc
->left
);
6910 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6912 if (mode
!= LVIR_BOUNDS
)
6913 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
6914 Position
.y
+ Origin
.y
);
6916 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
6919 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
6921 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
6928 * Retrieves the spacing between listview control items.
6931 * [I] infoPtr : valid pointer to the listview structure
6932 * [IO] lprc : rectangle to receive the output
6933 * on input, lprc->top = nSubItem
6934 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
6936 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
6937 * not only those of the first column.
6938 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
6944 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6950 if (!lprc
) return FALSE
;
6952 nColumn
= lprc
->top
;
6954 TRACE("(nItem=%d, nSubItem=%d)\n", nItem
, lprc
->top
);
6955 /* On WinNT, a subitem of '0' calls LISTVIEW_GetItemRect */
6957 return LISTVIEW_GetItemRect(infoPtr
, nItem
, lprc
);
6959 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
6961 /* special case for header items */
6964 if (lprc
->left
!= LVIR_BOUNDS
)
6966 FIXME("Only LVIR_BOUNDS is implemented for header, got %d\n", lprc
->left
);
6970 if (infoPtr
->hwndHeader
)
6971 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)lprc
);
6974 memset(lprc
, 0, sizeof(RECT
));
6979 if (!LISTVIEW_GetItemPosition(infoPtr
, nItem
, &Position
)) return FALSE
;
6981 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6984 lvItem
.iItem
= nItem
;
6985 lvItem
.iSubItem
= nColumn
;
6987 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6991 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
6996 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7000 ERR("Unknown bounds=%d\n", lprc
->left
);
7004 OffsetRect(lprc
, Position
.x
- REPORT_MARGINX
, Position
.y
);
7010 * Retrieves the spacing between listview control items.
7013 * [I] infoPtr : valid pointer to the listview structure
7014 * [I] bSmall : flag for small or large icon
7017 * Horizontal + vertical spacing
7019 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7025 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7029 if (infoPtr
->uView
== LV_VIEW_ICON
)
7030 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7032 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7039 * Retrieves the state of a listview control item.
7042 * [I] infoPtr : valid pointer to the listview structure
7043 * [I] nItem : item index
7044 * [I] uMask : state mask
7047 * State specified by the mask.
7049 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7053 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7055 lvItem
.iItem
= nItem
;
7056 lvItem
.iSubItem
= 0;
7057 lvItem
.mask
= LVIF_STATE
;
7058 lvItem
.stateMask
= uMask
;
7059 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7061 return lvItem
.state
& uMask
;
7066 * Retrieves the text of a listview control item or subitem.
7069 * [I] hwnd : window handle
7070 * [I] nItem : item index
7071 * [IO] lpLVItem : item information
7072 * [I] isW : TRUE if lpLVItem is Unicode
7075 * SUCCESS : string length
7078 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7080 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7082 lpLVItem
->mask
= LVIF_TEXT
;
7083 lpLVItem
->iItem
= nItem
;
7084 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7086 return textlenT(lpLVItem
->pszText
, isW
);
7091 * Searches for an item based on properties + relationships.
7094 * [I] infoPtr : valid pointer to the listview structure
7095 * [I] nItem : item index
7096 * [I] uFlags : relationship flag
7099 * SUCCESS : item index
7102 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7105 LVFINDINFOW lvFindInfo
;
7106 INT nCountPerColumn
;
7110 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7111 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7113 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7115 if (uFlags
& LVNI_CUT
)
7118 if (uFlags
& LVNI_DROPHILITED
)
7119 uMask
|= LVIS_DROPHILITED
;
7121 if (uFlags
& LVNI_FOCUSED
)
7122 uMask
|= LVIS_FOCUSED
;
7124 if (uFlags
& LVNI_SELECTED
)
7125 uMask
|= LVIS_SELECTED
;
7127 /* if we're asked for the focused item, that's only one,
7128 * so it's worth optimizing */
7129 if (uFlags
& LVNI_FOCUSED
)
7131 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7132 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7135 if (uFlags
& LVNI_ABOVE
)
7137 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7142 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7148 /* Special case for autoarrange - move 'til the top of a list */
7149 if (is_autoarrange(infoPtr
))
7151 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7152 while (nItem
- nCountPerRow
>= 0)
7154 nItem
-= nCountPerRow
;
7155 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7160 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7161 lvFindInfo
.vkDirection
= VK_UP
;
7162 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7163 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7165 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7170 else if (uFlags
& LVNI_BELOW
)
7172 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7174 while (nItem
< infoPtr
->nItemCount
)
7177 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7183 /* Special case for autoarrange - move 'til the bottom of a list */
7184 if (is_autoarrange(infoPtr
))
7186 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7187 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7189 nItem
+= nCountPerRow
;
7190 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7195 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7196 lvFindInfo
.vkDirection
= VK_DOWN
;
7197 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7198 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7200 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7205 else if (uFlags
& LVNI_TOLEFT
)
7207 if (infoPtr
->uView
== LV_VIEW_LIST
)
7209 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7210 while (nItem
- nCountPerColumn
>= 0)
7212 nItem
-= nCountPerColumn
;
7213 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7217 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7219 /* Special case for autoarrange - move 'til the beginning of a row */
7220 if (is_autoarrange(infoPtr
))
7222 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7223 while (nItem
% nCountPerRow
> 0)
7226 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7231 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7232 lvFindInfo
.vkDirection
= VK_LEFT
;
7233 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7234 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7236 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7241 else if (uFlags
& LVNI_TORIGHT
)
7243 if (infoPtr
->uView
== LV_VIEW_LIST
)
7245 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7246 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7248 nItem
+= nCountPerColumn
;
7249 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7253 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7255 /* Special case for autoarrange - move 'til the end of a row */
7256 if (is_autoarrange(infoPtr
))
7258 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7259 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7262 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7267 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7268 lvFindInfo
.vkDirection
= VK_RIGHT
;
7269 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7270 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7272 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7281 /* search by index */
7282 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7284 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7292 /* LISTVIEW_GetNumberOfWorkAreas */
7296 * Retrieves the origin coordinates when in icon or small icon display mode.
7299 * [I] infoPtr : valid pointer to the listview structure
7300 * [O] lpptOrigin : coordinate information
7305 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7307 INT nHorzPos
= 0, nVertPos
= 0;
7308 SCROLLINFO scrollInfo
;
7310 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7311 scrollInfo
.fMask
= SIF_POS
;
7313 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7314 nHorzPos
= scrollInfo
.nPos
;
7315 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7316 nVertPos
= scrollInfo
.nPos
;
7318 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7320 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7321 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7322 if (infoPtr
->uView
== LV_VIEW_LIST
)
7323 nHorzPos
*= infoPtr
->nItemWidth
;
7324 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7325 nVertPos
*= infoPtr
->nItemHeight
;
7327 lpptOrigin
->x
-= nHorzPos
;
7328 lpptOrigin
->y
-= nVertPos
;
7330 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7335 * Retrieves the width of a string.
7338 * [I] hwnd : window handle
7339 * [I] lpszText : text string to process
7340 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7343 * SUCCESS : string width (in pixels)
7346 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7351 if (is_textT(lpszText
, isW
))
7353 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7354 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7355 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7358 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7360 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7361 SelectObject(hdc
, hOldFont
);
7362 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7364 return stringSize
.cx
;
7369 * Determines which listview item is located at the specified position.
7372 * [I] infoPtr : valid pointer to the listview structure
7373 * [IO] lpht : hit test information
7374 * [I] subitem : fill out iSubItem.
7375 * [I] select : return the index only if the hit selects the item
7378 * (mm 20001022): We must not allow iSubItem to be touched, for
7379 * an app might pass only a structure with space up to iItem!
7380 * (MS Office 97 does that for instance in the file open dialog)
7383 * SUCCESS : item index
7386 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7388 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7389 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7390 POINT Origin
, Position
, opt
;
7395 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7399 if (subitem
) lpht
->iSubItem
= 0;
7401 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7403 /* set whole list relation flags */
7404 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7406 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7407 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7408 lpht
->flags
|= LVHT_TOLEFT
;
7410 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7411 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7415 if (infoPtr
->rcList
.bottom
< opt
.y
)
7416 lpht
->flags
|= LVHT_BELOW
;
7420 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7421 lpht
->flags
|= LVHT_TOLEFT
;
7422 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7423 lpht
->flags
|= LVHT_TORIGHT
;
7425 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7426 lpht
->flags
|= LVHT_ABOVE
;
7427 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7428 lpht
->flags
|= LVHT_BELOW
;
7431 /* even if item is invalid try to find subitem */
7432 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7437 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7439 lpht
->iSubItem
= -1;
7440 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7442 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7444 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7450 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7452 /* if we're outside horizontal columns bounds there's nothing to test further */
7453 if (lpht
->iSubItem
== -1)
7456 lpht
->flags
= LVHT_NOWHERE
;
7461 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7462 if (lpht
->flags
) return -1;
7464 lpht
->flags
|= LVHT_NOWHERE
;
7466 /* first deal with the large items */
7467 rcSearch
.left
= lpht
->pt
.x
;
7468 rcSearch
.top
= lpht
->pt
.y
;
7469 rcSearch
.right
= rcSearch
.left
+ 1;
7470 rcSearch
.bottom
= rcSearch
.top
+ 1;
7472 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7473 iterator_next(&i
); /* go to first item in the sequence */
7475 iterator_destroy(&i
);
7477 TRACE("lpht->iItem=%d\n", iItem
);
7478 if (iItem
== -1) return -1;
7480 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7481 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7482 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7483 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7484 lvItem
.iItem
= iItem
;
7485 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7486 lvItem
.pszText
= szDispText
;
7487 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7488 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7489 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7491 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7492 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7493 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7495 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7496 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7498 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7500 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7503 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7504 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7508 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7509 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7511 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7512 if (!PtInRect(&rcBounds
, opt
)) return -1;
7514 if (PtInRect(&rcIcon
, opt
))
7515 lpht
->flags
|= LVHT_ONITEMICON
;
7516 else if (PtInRect(&rcLabel
, opt
))
7517 lpht
->flags
|= LVHT_ONITEMLABEL
;
7518 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7519 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7520 /* special case for LVS_EX_FULLROWSELECT */
7521 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
7522 !(lpht
->flags
& LVHT_ONITEM
))
7524 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7526 if (lpht
->flags
& LVHT_ONITEM
)
7527 lpht
->flags
&= ~LVHT_NOWHERE
;
7528 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7530 if (select
&& !(infoPtr
->uView
== LV_VIEW_DETAILS
&&
7531 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
7532 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
7534 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7536 /* get main item bounds */
7537 lvItem
.iSubItem
= 0;
7538 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7539 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7540 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7542 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7544 return lpht
->iItem
= iItem
;
7549 * Inserts a new item in the listview control.
7552 * [I] infoPtr : valid pointer to the listview structure
7553 * [I] lpLVItem : item information
7554 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7557 * SUCCESS : new item index
7560 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7567 BOOL is_sorted
, has_changed
;
7569 HWND hwndSelf
= infoPtr
->hwndSelf
;
7571 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7573 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7575 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7576 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7578 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7580 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7582 /* insert item in listview control data structure */
7583 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7584 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7586 /* link with id struct */
7587 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7589 lpID
->item
= hdpaSubItems
;
7590 lpID
->id
= get_next_itemid(infoPtr
);
7591 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7593 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7594 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7596 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7598 /* calculate new item index */
7605 while (i
< infoPtr
->nItemCount
)
7607 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7608 item_s
= DPA_GetPtr(hItem
, 0);
7610 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7611 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7613 if (cmpv
>= 0) break;
7619 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7621 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7622 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7623 if (nItem
== -1) goto fail
;
7624 infoPtr
->nItemCount
++;
7626 /* shift indices first so they don't get tangled */
7627 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7629 /* set the item attributes */
7630 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7632 /* full size structure expected - _WIN32IE >= 0x560 */
7635 else if (lpLVItem
->mask
& LVIF_INDENT
)
7637 /* indent member expected - _WIN32IE >= 0x300 */
7638 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7642 /* minimal structure expected */
7643 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7646 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7648 item
.mask
|= LVIF_STATE
;
7649 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7650 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7651 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7653 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7655 /* make room for the position, if we are in the right mode */
7656 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7658 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7660 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7662 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7667 /* send LVN_INSERTITEM notification */
7668 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
7670 nmlv
.lParam
= lpItem
->lParam
;
7671 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7672 if (!IsWindow(hwndSelf
))
7675 /* align items (set position of each item) */
7676 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7680 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7681 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7683 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7685 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7688 /* now is the invalidation fun */
7689 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7693 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7694 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7695 infoPtr
->nItemCount
--;
7697 DPA_DeletePtr(hdpaSubItems
, 0);
7698 DPA_Destroy (hdpaSubItems
);
7705 * Checks item visibility.
7708 * [I] infoPtr : valid pointer to the listview structure
7709 * [I] nFirst : item index to check for
7712 * Item visible : TRUE
7713 * Item invisible or failure : FALSE
7715 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7717 POINT Origin
, Position
;
7722 TRACE("nItem=%d\n", nItem
);
7724 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7726 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7727 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7728 rcItem
.left
= Position
.x
+ Origin
.x
;
7729 rcItem
.top
= Position
.y
+ Origin
.y
;
7730 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7731 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7733 hdc
= GetDC(infoPtr
->hwndSelf
);
7734 if (!hdc
) return FALSE
;
7735 ret
= RectVisible(hdc
, &rcItem
);
7736 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7743 * Redraws a range of items.
7746 * [I] infoPtr : valid pointer to the listview structure
7747 * [I] nFirst : first item
7748 * [I] nLast : last item
7754 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7758 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7759 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7762 for (i
= nFirst
; i
<= nLast
; i
++)
7763 LISTVIEW_InvalidateItem(infoPtr
, i
);
7770 * Scroll the content of a listview.
7773 * [I] infoPtr : valid pointer to the listview structure
7774 * [I] dx : horizontal scroll amount in pixels
7775 * [I] dy : vertical scroll amount in pixels
7782 * If the control is in report view (LV_VIEW_DETAILS) the control can
7783 * be scrolled only in line increments. "dy" will be rounded to the
7784 * nearest number of pixels that are a whole line. Ex: if line height
7785 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7786 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7788 * For: (per experimentation with native control and CSpy ListView)
7789 * LV_VIEW_ICON dy=1 = 1 pixel (vertical only)
7791 * LV_VIEW_SMALLICON dy=1 = 1 pixel (vertical only)
7793 * LV_VIEW_LIST dx=1 = 1 column (horizontal only)
7794 * but will only scroll 1 column per message
7795 * no matter what the value.
7796 * dy must be 0 or FALSE returned.
7797 * LV_VIEW_DETAILS dx=1 = 1 pixel
7801 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7803 switch(infoPtr
->uView
) {
7804 case LV_VIEW_DETAILS
:
7805 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7806 dy
/= infoPtr
->nItemHeight
;
7809 if (dy
!= 0) return FALSE
;
7816 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
, 0);
7817 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
, 0);
7824 * Sets the background color.
7827 * [I] infoPtr : valid pointer to the listview structure
7828 * [I] clrBk : background color
7834 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrBk
)
7836 TRACE("(clrBk=%x)\n", clrBk
);
7838 if(infoPtr
->clrBk
!= clrBk
) {
7839 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7840 infoPtr
->clrBk
= clrBk
;
7841 if (clrBk
== CLR_NONE
)
7842 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
7845 infoPtr
->hBkBrush
= CreateSolidBrush(clrBk
);
7846 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
7848 LISTVIEW_InvalidateList(infoPtr
);
7854 /* LISTVIEW_SetBkImage */
7856 /*** Helper for {Insert,Set}ColumnT *only* */
7857 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
7858 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7860 if (lpColumn
->mask
& LVCF_FMT
)
7862 /* format member is valid */
7863 lphdi
->mask
|= HDI_FORMAT
;
7865 /* set text alignment (leftmost column must be left-aligned) */
7866 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7867 lphdi
->fmt
|= HDF_LEFT
;
7868 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
7869 lphdi
->fmt
|= HDF_RIGHT
;
7870 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
7871 lphdi
->fmt
|= HDF_CENTER
;
7873 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
7874 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
7876 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
7878 lphdi
->fmt
|= HDF_IMAGE
;
7879 lphdi
->iImage
= I_IMAGECALLBACK
;
7882 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
7883 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
7886 if (lpColumn
->mask
& LVCF_WIDTH
)
7888 lphdi
->mask
|= HDI_WIDTH
;
7889 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
7891 /* make it fill the remainder of the controls width */
7895 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
7897 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
7898 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
7901 /* retrieve the layout of the header */
7902 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
7903 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
7905 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
7908 lphdi
->cxy
= lpColumn
->cx
;
7911 if (lpColumn
->mask
& LVCF_TEXT
)
7913 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
7914 lphdi
->fmt
|= HDF_STRING
;
7915 lphdi
->pszText
= lpColumn
->pszText
;
7916 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
7919 if (lpColumn
->mask
& LVCF_IMAGE
)
7921 lphdi
->mask
|= HDI_IMAGE
;
7922 lphdi
->iImage
= lpColumn
->iImage
;
7925 if (lpColumn
->mask
& LVCF_ORDER
)
7927 lphdi
->mask
|= HDI_ORDER
;
7928 lphdi
->iOrder
= lpColumn
->iOrder
;
7935 * Inserts a new column.
7938 * [I] infoPtr : valid pointer to the listview structure
7939 * [I] nColumn : column index
7940 * [I] lpColumn : column information
7941 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
7944 * SUCCESS : new column index
7947 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
7948 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7950 COLUMN_INFO
*lpColumnInfo
;
7954 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
7956 if (!lpColumn
|| nColumn
< 0) return -1;
7957 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
7959 ZeroMemory(&hdi
, sizeof(HDITEMW
));
7960 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
7963 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
7964 * (can be seen in SPY) otherwise column never gets added.
7966 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
7967 hdi
.mask
|= HDI_WIDTH
;
7972 * when the iSubItem is available Windows copies it to the header lParam. It seems
7973 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
7975 if (lpColumn
->mask
& LVCF_SUBITEM
)
7977 hdi
.mask
|= HDI_LPARAM
;
7978 hdi
.lParam
= lpColumn
->iSubItem
;
7981 /* create header if not present */
7982 LISTVIEW_CreateHeader(infoPtr
);
7983 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
7984 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
7986 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
7989 /* insert item in header control */
7990 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
7991 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
7992 nColumn
, (LPARAM
)&hdi
);
7993 if (nNewColumn
== -1) return -1;
7994 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
7996 /* create our own column info */
7997 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
7998 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8000 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8001 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8002 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8005 /* now we have to actually adjust the data */
8006 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8008 SUBITEM_INFO
*lpSubItem
;
8014 item
.iSubItem
= nNewColumn
;
8015 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8016 item
.iImage
= I_IMAGECALLBACK
;
8017 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8019 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8021 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8022 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8024 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8025 if (lpSubItem
->iSubItem
>= nNewColumn
)
8026 lpSubItem
->iSubItem
++;
8029 /* add new subitem for each item */
8031 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8035 /* make space for the new column */
8036 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8037 LISTVIEW_UpdateItemSize(infoPtr
);
8042 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8045 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8053 * Sets the attributes of a header item.
8056 * [I] infoPtr : valid pointer to the listview structure
8057 * [I] nColumn : column index
8058 * [I] lpColumn : column attributes
8059 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8065 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8066 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8068 HDITEMW hdi
, hdiget
;
8071 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8073 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8075 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8076 if (lpColumn
->mask
& LVCF_FMT
)
8078 hdi
.mask
|= HDI_FORMAT
;
8079 hdiget
.mask
= HDI_FORMAT
;
8080 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8081 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8083 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8085 /* set header item attributes */
8086 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8087 if (!bResult
) return FALSE
;
8089 if (lpColumn
->mask
& LVCF_FMT
)
8091 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8092 INT oldFmt
= lpColumnInfo
->fmt
;
8094 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8095 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8097 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8101 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8102 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8109 * Sets the column order array
8112 * [I] infoPtr : valid pointer to the listview structure
8113 * [I] iCount : number of elements in column order array
8114 * [I] lpiArray : pointer to column order array
8120 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8122 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
8124 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
8126 infoPtr
->colRectsDirty
= TRUE
;
8128 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8133 * Sets the width of a column
8136 * [I] infoPtr : valid pointer to the listview structure
8137 * [I] nColumn : column index
8138 * [I] cx : column width
8144 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8146 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8150 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
8152 /* set column width only if in report or list mode */
8153 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8155 /* take care of invalid cx values */
8156 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
8157 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
8159 /* resize all columns if in LV_VIEW_LIST mode */
8160 if(infoPtr
->uView
== LV_VIEW_LIST
)
8162 infoPtr
->nItemWidth
= cx
;
8163 LISTVIEW_InvalidateList(infoPtr
);
8167 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8169 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8174 lvItem
.mask
= LVIF_TEXT
;
8176 lvItem
.iSubItem
= nColumn
;
8177 lvItem
.pszText
= szDispText
;
8178 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8179 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8181 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8182 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8183 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8185 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8186 max_cx
+= infoPtr
->iconSize
.cx
;
8187 max_cx
+= TRAILING_LABEL_PADDING
;
8190 /* autosize based on listview items width */
8191 if(cx
== LVSCW_AUTOSIZE
)
8193 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8195 /* if iCol is the last column make it fill the remainder of the controls width */
8196 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8201 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8202 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8204 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8208 /* Despite what the MS docs say, if this is not the last
8209 column, then MS resizes the column to the width of the
8210 largest text string in the column, including headers
8211 and items. This is different from LVSCW_AUTOSIZE in that
8212 LVSCW_AUTOSIZE ignores the header string length. */
8215 /* retrieve header text */
8216 hdi
.mask
= HDI_TEXT
;
8217 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8218 hdi
.pszText
= szDispText
;
8219 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8221 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8222 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8225 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8226 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8227 /* FIXME: Take into account the header image, if one is present */
8228 SelectObject(hdc
, old_font
);
8229 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8231 cx
= max (cx
, max_cx
);
8235 if (cx
< 0) return FALSE
;
8237 /* call header to update the column change */
8238 hdi
.mask
= HDI_WIDTH
;
8239 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8240 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8241 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8245 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8248 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8251 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8253 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8254 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8257 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8258 ILC_COLOR
| ILC_MASK
, 2, 2);
8259 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8260 hdc
= CreateCompatibleDC(hdc_wnd
);
8261 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8262 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8263 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8265 rc
.left
= rc
.top
= 0;
8266 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8267 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8269 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8270 FillRect(hdc
, &rc
, hbr_white
);
8271 InflateRect(&rc
, -2, -2);
8272 FillRect(hdc
, &rc
, hbr_black
);
8274 SelectObject(hdc
, hbm_im
);
8275 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8276 SelectObject(hdc
, hbm_orig
);
8277 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8279 SelectObject(hdc
, hbm_im
);
8280 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8281 SelectObject(hdc
, hbm_orig
);
8282 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8284 DeleteObject(hbm_mask
);
8285 DeleteObject(hbm_im
);
8293 * Sets the extended listview style.
8296 * [I] infoPtr : valid pointer to the listview structure
8298 * [I] dwStyle : style
8301 * SUCCESS : previous style
8304 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD dwMask
, DWORD dwExStyle
)
8306 DWORD dwOldExStyle
= infoPtr
->dwLvExStyle
;
8310 infoPtr
->dwLvExStyle
= (dwOldExStyle
& ~dwMask
) | (dwExStyle
& dwMask
);
8312 infoPtr
->dwLvExStyle
= dwExStyle
;
8314 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_CHECKBOXES
)
8316 HIMAGELIST himl
= 0;
8317 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8320 item
.mask
= LVIF_STATE
;
8321 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8322 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8323 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8325 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8326 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8327 ImageList_Destroy(infoPtr
->himlState
);
8329 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8330 /* checkbox list replaces prevous custom list or... */
8331 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8332 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8333 /* ...previous was checkbox list */
8334 (dwOldExStyle
& LVS_EX_CHECKBOXES
))
8335 ImageList_Destroy(himl
);
8338 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_HEADERDRAGDROP
)
8342 /* if not already created */
8343 LISTVIEW_CreateHeader(infoPtr
);
8345 dwStyle
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8346 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8347 dwStyle
|= HDS_DRAGDROP
;
8349 dwStyle
&= ~HDS_DRAGDROP
;
8350 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, dwStyle
);
8353 /* GRIDLINES adds decoration at top so changes sizes */
8354 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_GRIDLINES
)
8356 LISTVIEW_UpdateSize(infoPtr
);
8359 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_TRANSPARENTBKGND
)
8361 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8362 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8365 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_HEADERINALLVIEWS
)
8367 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8368 LISTVIEW_CreateHeader(infoPtr
);
8370 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8371 LISTVIEW_UpdateSize(infoPtr
);
8372 LISTVIEW_UpdateScroll(infoPtr
);
8375 LISTVIEW_InvalidateList(infoPtr
);
8376 return dwOldExStyle
;
8381 * Sets the new hot cursor used during hot tracking and hover selection.
8384 * [I] infoPtr : valid pointer to the listview structure
8385 * [I] hCursor : the new hot cursor handle
8388 * Returns the previous hot cursor
8390 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8392 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8394 infoPtr
->hHotCursor
= hCursor
;
8402 * Sets the hot item index.
8405 * [I] infoPtr : valid pointer to the listview structure
8406 * [I] iIndex : index
8409 * SUCCESS : previous hot item index
8410 * FAILURE : -1 (no hot item)
8412 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8414 INT iOldIndex
= infoPtr
->nHotItem
;
8416 infoPtr
->nHotItem
= iIndex
;
8424 * Sets the amount of time the cursor must hover over an item before it is selected.
8427 * [I] infoPtr : valid pointer to the listview structure
8428 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8431 * Returns the previous hover time
8433 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8435 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8437 infoPtr
->dwHoverTime
= dwHoverTime
;
8439 return oldHoverTime
;
8444 * Sets spacing for icons of LVS_ICON style.
8447 * [I] infoPtr : valid pointer to the listview structure
8448 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8449 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8452 * MAKELONG(oldcx, oldcy)
8454 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8456 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8458 TRACE("requested=(%d,%d)\n", cx
, cy
);
8460 /* this is supported only for LVS_ICON style */
8461 if (infoPtr
->uView
!= LV_VIEW_ICON
) return oldspacing
;
8463 /* set to defaults, if instructed to */
8464 if (cx
== -1) cx
= GetSystemMetrics(SM_CXICONSPACING
);
8465 if (cy
== -1) cy
= GetSystemMetrics(SM_CYICONSPACING
);
8467 /* if 0 then compute width
8468 * FIXME: Should scan each item and determine max width of
8469 * icon or label, then make that the width */
8471 cx
= infoPtr
->iconSpacing
.cx
;
8473 /* if 0 then compute height */
8475 cy
= infoPtr
->iconSize
.cy
+ 2 * infoPtr
->ntmHeight
+
8476 ICON_BOTTOM_PADDING
+ ICON_TOP_PADDING
+ LABEL_VERT_PADDING
;
8479 infoPtr
->iconSpacing
.cx
= cx
;
8480 infoPtr
->iconSpacing
.cy
= cy
;
8482 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8483 LOWORD(oldspacing
), HIWORD(oldspacing
), cx
, cy
,
8484 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8485 infoPtr
->ntmHeight
);
8487 /* these depend on the iconSpacing */
8488 LISTVIEW_UpdateItemSize(infoPtr
);
8493 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8497 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8504 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8505 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8514 * [I] infoPtr : valid pointer to the listview structure
8515 * [I] nType : image list type
8516 * [I] himl : image list handle
8519 * SUCCESS : old image list
8522 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8524 INT oldHeight
= infoPtr
->nItemHeight
;
8525 HIMAGELIST himlOld
= 0;
8527 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
8532 himlOld
= infoPtr
->himlNormal
;
8533 infoPtr
->himlNormal
= himl
;
8534 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8535 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
8539 himlOld
= infoPtr
->himlSmall
;
8540 infoPtr
->himlSmall
= himl
;
8541 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8545 himlOld
= infoPtr
->himlState
;
8546 infoPtr
->himlState
= himl
;
8547 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8548 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8552 ERR("Unknown icon type=%d\n", nType
);
8556 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8557 if (infoPtr
->nItemHeight
!= oldHeight
)
8558 LISTVIEW_UpdateScroll(infoPtr
);
8565 * Preallocates memory (does *not* set the actual count of items !)
8568 * [I] infoPtr : valid pointer to the listview structure
8569 * [I] nItems : item count (projected number of items to allocate)
8570 * [I] dwFlags : update flags
8576 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8578 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8580 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8582 INT nOldCount
= infoPtr
->nItemCount
;
8584 if (nItems
< nOldCount
)
8586 RANGE range
= { nItems
, nOldCount
};
8587 ranges_del(infoPtr
->selectionRanges
, range
);
8588 if (infoPtr
->nFocusedItem
>= nItems
)
8590 LISTVIEW_SetItemFocus(infoPtr
, -1);
8591 SetRectEmpty(&infoPtr
->rcFocus
);
8595 infoPtr
->nItemCount
= nItems
;
8596 LISTVIEW_UpdateScroll(infoPtr
);
8598 /* the flags are valid only in ownerdata report and list modes */
8599 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8601 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8602 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8604 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8605 LISTVIEW_InvalidateList(infoPtr
);
8612 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8613 nFrom
= min(nOldCount
, nItems
);
8614 nTo
= max(nOldCount
, nItems
);
8616 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8619 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8620 rcErase
.right
= infoPtr
->nItemWidth
;
8621 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8622 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8623 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8624 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8626 else /* LV_VIEW_LIST */
8628 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8630 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8631 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8632 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8633 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8634 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8635 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8636 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8638 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8640 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8641 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8642 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8643 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8644 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8650 /* According to MSDN for non-LVS_OWNERDATA this is just
8651 * a performance issue. The control allocates its internal
8652 * data structures for the number of items specified. It
8653 * cuts down on the number of memory allocations. Therefore
8654 * we will just issue a WARN here
8656 WARN("for non-ownerdata performance option not implemented.\n");
8664 * Sets the position of an item.
8667 * [I] infoPtr : valid pointer to the listview structure
8668 * [I] nItem : item index
8669 * [I] pt : coordinate
8675 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, POINT
*pt
)
8679 TRACE("(nItem=%d, pt=%s\n", nItem
, wine_dbgstr_point(pt
));
8681 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8682 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8685 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8687 /* This point value seems to be an undocumented feature.
8688 * The best guess is that it means either at the origin,
8689 * or at true beginning of the list. I will assume the origin. */
8690 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8693 if (infoPtr
->uView
== LV_VIEW_ICON
)
8695 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8696 Pt
.y
-= ICON_TOP_PADDING
;
8701 infoPtr
->bAutoarrange
= FALSE
;
8703 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8708 * Sets the state of one or many items.
8711 * [I] infoPtr : valid pointer to the listview structure
8712 * [I] nItem : item index
8713 * [I] lpLVItem : item or subitem info
8719 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
)
8721 BOOL bResult
= TRUE
;
8724 lvItem
.iItem
= nItem
;
8725 lvItem
.iSubItem
= 0;
8726 lvItem
.mask
= LVIF_STATE
;
8727 lvItem
.state
= lpLVItem
->state
;
8728 lvItem
.stateMask
= lpLVItem
->stateMask
;
8729 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8733 /* select all isn't allowed in LVS_SINGLESEL */
8734 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8737 /* focus all isn't allowed */
8738 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8740 /* apply to all items */
8741 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8742 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) bResult
= FALSE
;
8745 bResult
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8752 * Sets the text of an item or subitem.
8755 * [I] hwnd : window handle
8756 * [I] nItem : item index
8757 * [I] lpLVItem : item or subitem info
8758 * [I] isW : TRUE if input is Unicode
8764 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8768 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
8770 lvItem
.iItem
= nItem
;
8771 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
8772 lvItem
.mask
= LVIF_TEXT
;
8773 lvItem
.pszText
= lpLVItem
->pszText
;
8774 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
8776 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
8778 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
8783 * Set item index that marks the start of a multiple selection.
8786 * [I] infoPtr : valid pointer to the listview structure
8787 * [I] nIndex : index
8790 * Index number or -1 if there is no selection mark.
8792 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
8794 INT nOldIndex
= infoPtr
->nSelectionMark
;
8796 TRACE("(nIndex=%d)\n", nIndex
);
8798 infoPtr
->nSelectionMark
= nIndex
;
8805 * Sets the text background color.
8808 * [I] infoPtr : valid pointer to the listview structure
8809 * [I] clrTextBk : text background color
8815 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrTextBk
)
8817 TRACE("(clrTextBk=%x)\n", clrTextBk
);
8819 if (infoPtr
->clrTextBk
!= clrTextBk
)
8821 infoPtr
->clrTextBk
= clrTextBk
;
8822 LISTVIEW_InvalidateList(infoPtr
);
8830 * Sets the text foreground color.
8833 * [I] infoPtr : valid pointer to the listview structure
8834 * [I] clrText : text color
8840 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF clrText
)
8842 TRACE("(clrText=%x)\n", clrText
);
8844 if (infoPtr
->clrText
!= clrText
)
8846 infoPtr
->clrText
= clrText
;
8847 LISTVIEW_InvalidateList(infoPtr
);
8855 * Sets new ToolTip window to ListView control.
8858 * [I] infoPtr : valid pointer to the listview structure
8859 * [I] hwndNewToolTip : handle to new ToolTip
8864 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
8866 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
8867 infoPtr
->hwndToolTip
= hwndNewToolTip
;
8868 return hwndOldToolTip
;
8873 * sets the Unicode character format flag for the control
8875 * [I] infoPtr :valid pointer to the listview structure
8876 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
8879 * Old Unicode Format
8881 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL fUnicode
)
8883 SHORT rc
= infoPtr
->notifyFormat
;
8884 infoPtr
->notifyFormat
= (fUnicode
) ? NFR_UNICODE
: NFR_ANSI
;
8885 return rc
== NFR_UNICODE
;
8890 * sets the control view mode
8892 * [I] infoPtr :valid pointer to the listview structure
8893 * [I] nView :new view mode value
8899 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
8901 SIZE oldIconSize
= infoPtr
->iconSize
;
8904 if (infoPtr
->uView
== nView
) return 1;
8906 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
8907 if (nView
== LV_VIEW_TILE
)
8909 FIXME("View LV_VIEW_TILE unimplemented\n");
8913 infoPtr
->uView
= nView
;
8915 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8916 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8918 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
8919 SetRectEmpty(&infoPtr
->rcFocus
);
8921 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
8922 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
8927 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
8929 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
8930 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
8931 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
8933 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8935 case LV_VIEW_SMALLICON
:
8936 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8938 case LV_VIEW_DETAILS
:
8943 LISTVIEW_CreateHeader( infoPtr
);
8945 hl
.prc
= &infoPtr
->rcList
;
8947 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
8948 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
8949 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
8956 LISTVIEW_UpdateItemSize(infoPtr
);
8957 LISTVIEW_UpdateSize(infoPtr
);
8958 LISTVIEW_UpdateScroll(infoPtr
);
8959 LISTVIEW_InvalidateList(infoPtr
);
8961 TRACE("nView=%d\n", nView
);
8966 /* LISTVIEW_SetWorkAreas */
8970 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
8973 * [I] first : pointer to first ITEM_INFO to compare
8974 * [I] second : pointer to second ITEM_INFO to compare
8975 * [I] lParam : HWND of control
8978 * if first comes before second : negative
8979 * if first comes after second : positive
8980 * if first and second are equivalent : zero
8982 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
8984 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
8985 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
8986 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
8988 /* Forward the call to the client defined callback */
8989 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
8994 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
8997 * [I] first : pointer to first ITEM_INFO to compare
8998 * [I] second : pointer to second ITEM_INFO to compare
8999 * [I] lParam : HWND of control
9002 * if first comes before second : negative
9003 * if first comes after second : positive
9004 * if first and second are equivalent : zero
9006 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9008 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9009 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9010 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9012 /* Forward the call to the client defined callback */
9013 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9018 * Sorts the listview items.
9021 * [I] infoPtr : valid pointer to the listview structure
9022 * [I] pfnCompare : application-defined value
9023 * [I] lParamSort : pointer to comparison callback
9024 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9030 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9031 LPARAM lParamSort
, BOOL IsEx
)
9035 LPVOID selectionMarkItem
= NULL
;
9036 LPVOID focusedItem
= NULL
;
9039 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9041 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9043 if (!pfnCompare
) return FALSE
;
9044 if (!infoPtr
->hdpaItems
) return FALSE
;
9046 /* if there are 0 or 1 items, there is no need to sort */
9047 if (infoPtr
->nItemCount
< 2) return TRUE
;
9049 /* clear selection */
9050 ranges_clear(infoPtr
->selectionRanges
);
9052 /* save selection mark and focused item */
9053 if (infoPtr
->nSelectionMark
>= 0)
9054 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9055 if (infoPtr
->nFocusedItem
>= 0)
9056 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9058 infoPtr
->pfnCompare
= pfnCompare
;
9059 infoPtr
->lParamSort
= lParamSort
;
9061 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9063 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9065 /* restore selection ranges */
9066 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9068 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9069 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9071 if (lpItem
->state
& LVIS_SELECTED
)
9072 ranges_additem(infoPtr
->selectionRanges
, i
);
9074 /* restore selection mark and focused item */
9075 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9076 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9078 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9080 /* refresh the display */
9081 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
)
9082 LISTVIEW_InvalidateList(infoPtr
);
9089 * Update theme handle after a theme change.
9092 * [I] infoPtr : valid pointer to the listview structure
9096 * FAILURE : something else
9098 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9100 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9101 CloseThemeData(theme
);
9102 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9108 * Updates an items or rearranges the listview control.
9111 * [I] infoPtr : valid pointer to the listview structure
9112 * [I] nItem : item index
9118 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9120 TRACE("(nItem=%d)\n", nItem
);
9122 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9124 /* rearrange with default alignment style */
9125 if (is_autoarrange(infoPtr
))
9126 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9128 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9135 * Draw the track line at the place defined in the infoPtr structure.
9136 * The line is drawn with a XOR pen so drawing the line for the second time
9137 * in the same place erases the line.
9140 * [I] infoPtr : valid pointer to the listview structure
9146 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9152 if (infoPtr
->xTrackLine
== -1)
9155 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9157 hOldPen
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
9158 oldROP
= SetROP2(hdc
, R2_XORPEN
);
9159 MoveToEx(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
, NULL
);
9160 LineTo(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.bottom
);
9161 SetROP2(hdc
, oldROP
);
9162 SelectObject(hdc
, hOldPen
);
9163 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9169 * Called when an edit control should be displayed. This function is called after
9170 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9173 * [I] hwnd : Handle to the listview
9174 * [I] uMsg : WM_TIMER (ignored)
9175 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9176 * [I] dwTimer : The elapsed time (ignored)
9181 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9183 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9184 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9186 KillTimer(hwnd
, idEvent
);
9187 editItem
->fEnabled
= FALSE
;
9188 /* check if the item is still selected */
9189 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9190 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9195 * Creates the listview control - the WM_NCCREATE phase.
9198 * [I] hwnd : window handle
9199 * [I] lpcs : the create parameters
9205 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9207 LISTVIEW_INFO
*infoPtr
;
9210 TRACE("(lpcs=%p)\n", lpcs
);
9212 /* initialize info pointer */
9213 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9214 if (!infoPtr
) return FALSE
;
9216 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9218 infoPtr
->hwndSelf
= hwnd
;
9219 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9220 map_style_view(infoPtr
);
9221 /* determine the type of structures to use */
9222 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9223 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9225 /* initialize color information */
9226 infoPtr
->clrBk
= CLR_NONE
;
9227 infoPtr
->clrText
= CLR_DEFAULT
;
9228 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9229 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9231 /* set default values */
9232 infoPtr
->nFocusedItem
= -1;
9233 infoPtr
->nSelectionMark
= -1;
9234 infoPtr
->nHotItem
= -1;
9235 infoPtr
->bRedraw
= TRUE
;
9236 infoPtr
->bNoItemMetrics
= TRUE
;
9237 infoPtr
->bDoChangeNotify
= TRUE
;
9238 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
);
9239 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
);
9240 infoPtr
->nEditLabelItem
= -1;
9241 infoPtr
->nLButtonDownItem
= -1;
9242 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9243 infoPtr
->nMeasureItemHeight
= 0;
9244 infoPtr
->xTrackLine
= -1; /* no track line */
9245 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9246 infoPtr
->iVersion
= COMCTL32_VERSION
;
9247 infoPtr
->colRectsDirty
= FALSE
;
9249 /* get default font (icon title) */
9250 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9251 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9252 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9253 LISTVIEW_SaveTextMetrics(infoPtr
);
9255 /* allocate memory for the data structure */
9256 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9257 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9258 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9259 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9260 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9261 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9265 DestroyWindow(infoPtr
->hwndHeader
);
9266 ranges_destroy(infoPtr
->selectionRanges
);
9267 DPA_Destroy(infoPtr
->hdpaItems
);
9268 DPA_Destroy(infoPtr
->hdpaItemIds
);
9269 DPA_Destroy(infoPtr
->hdpaPosX
);
9270 DPA_Destroy(infoPtr
->hdpaPosY
);
9271 DPA_Destroy(infoPtr
->hdpaColumns
);
9278 * Creates the listview control - the WM_CREATE phase. Most of the data is
9279 * already set up in LISTVIEW_NCCreate
9282 * [I] hwnd : window handle
9283 * [I] lpcs : the create parameters
9289 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9291 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9293 TRACE("(lpcs=%p)\n", lpcs
);
9295 infoPtr
->dwStyle
= lpcs
->style
;
9296 map_style_view(infoPtr
);
9298 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9299 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9300 /* on error defaulting to ANSI notifications */
9301 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9303 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9305 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9308 infoPtr
->hwndHeader
= 0;
9310 /* init item size to avoid division by 0 */
9311 LISTVIEW_UpdateItemSize (infoPtr
);
9313 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9315 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9317 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9319 LISTVIEW_UpdateScroll(infoPtr
);
9320 /* send WM_MEASUREITEM notification */
9321 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9324 OpenThemeData(hwnd
, themeClass
);
9326 /* initialize the icon sizes */
9327 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9328 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9334 * Destroys the listview control.
9337 * [I] infoPtr : valid pointer to the listview structure
9343 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9345 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9346 CloseThemeData(theme
);
9348 /* delete all items */
9349 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9356 * Enables the listview control.
9359 * [I] infoPtr : valid pointer to the listview structure
9360 * [I] bEnable : specifies whether to enable or disable the window
9366 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
, BOOL bEnable
)
9368 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9369 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9375 * Erases the background of the listview control.
9378 * [I] infoPtr : valid pointer to the listview structure
9379 * [I] hdc : device context handle
9385 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9389 TRACE("(hdc=%p)\n", hdc
);
9391 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9393 if (infoPtr
->clrBk
== CLR_NONE
)
9395 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9396 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9397 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9399 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9402 /* for double buffered controls we need to do this during refresh */
9403 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9405 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9411 * Helper function for LISTVIEW_[HV]Scroll *only*.
9412 * Performs vertical/horizontal scrolling by a give amount.
9415 * [I] infoPtr : valid pointer to the listview structure
9416 * [I] dx : amount of horizontal scroll
9417 * [I] dy : amount of vertical scroll
9419 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9421 /* now we can scroll the list */
9422 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9423 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9424 /* if we have focus, adjust rect */
9425 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9426 UpdateWindow(infoPtr
->hwndSelf
);
9431 * Performs vertical scrolling.
9434 * [I] infoPtr : valid pointer to the listview structure
9435 * [I] nScrollCode : scroll code
9436 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9437 * [I] hScrollWnd : scrollbar control window handle
9443 * SB_LINEUP/SB_LINEDOWN:
9444 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9445 * for LVS_REPORT is 1 line
9446 * for LVS_LIST cannot occur
9449 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9450 INT nScrollDiff
, HWND hScrollWnd
)
9452 INT nOldScrollPos
, nNewScrollPos
;
9453 SCROLLINFO scrollInfo
;
9456 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9457 debugscrollcode(nScrollCode
), nScrollDiff
);
9459 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9461 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9462 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9464 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9466 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9468 nOldScrollPos
= scrollInfo
.nPos
;
9469 switch (nScrollCode
)
9475 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9479 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9483 nScrollDiff
= -scrollInfo
.nPage
;
9487 nScrollDiff
= scrollInfo
.nPage
;
9490 case SB_THUMBPOSITION
:
9492 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9499 /* quit right away if pos isn't changing */
9500 if (nScrollDiff
== 0) return 0;
9502 /* calculate new position, and handle overflows */
9503 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9504 if (nScrollDiff
> 0) {
9505 if (nNewScrollPos
< nOldScrollPos
||
9506 nNewScrollPos
> scrollInfo
.nMax
)
9507 nNewScrollPos
= scrollInfo
.nMax
;
9509 if (nNewScrollPos
> nOldScrollPos
||
9510 nNewScrollPos
< scrollInfo
.nMin
)
9511 nNewScrollPos
= scrollInfo
.nMin
;
9514 /* set the new position, and reread in case it changed */
9515 scrollInfo
.fMask
= SIF_POS
;
9516 scrollInfo
.nPos
= nNewScrollPos
;
9517 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9519 /* carry on only if it really changed */
9520 if (nNewScrollPos
== nOldScrollPos
) return 0;
9522 /* now adjust to client coordinates */
9523 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9524 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9526 /* and scroll the window */
9527 scroll_list(infoPtr
, 0, nScrollDiff
);
9534 * Performs horizontal scrolling.
9537 * [I] infoPtr : valid pointer to the listview structure
9538 * [I] nScrollCode : scroll code
9539 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9540 * [I] hScrollWnd : scrollbar control window handle
9546 * SB_LINELEFT/SB_LINERIGHT:
9547 * for LVS_ICON, LVS_SMALLICON 1 pixel
9548 * for LVS_REPORT is 1 pixel
9549 * for LVS_LIST is 1 column --> which is a 1 because the
9550 * scroll is based on columns not pixels
9553 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9554 INT nScrollDiff
, HWND hScrollWnd
)
9556 INT nOldScrollPos
, nNewScrollPos
;
9557 SCROLLINFO scrollInfo
;
9559 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9560 debugscrollcode(nScrollCode
), nScrollDiff
);
9562 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9564 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9565 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9567 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9569 nOldScrollPos
= scrollInfo
.nPos
;
9571 switch (nScrollCode
)
9585 nScrollDiff
= -scrollInfo
.nPage
;
9589 nScrollDiff
= scrollInfo
.nPage
;
9592 case SB_THUMBPOSITION
:
9594 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9601 /* quit right away if pos isn't changing */
9602 if (nScrollDiff
== 0) return 0;
9604 /* calculate new position, and handle overflows */
9605 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9606 if (nScrollDiff
> 0) {
9607 if (nNewScrollPos
< nOldScrollPos
||
9608 nNewScrollPos
> scrollInfo
.nMax
)
9609 nNewScrollPos
= scrollInfo
.nMax
;
9611 if (nNewScrollPos
> nOldScrollPos
||
9612 nNewScrollPos
< scrollInfo
.nMin
)
9613 nNewScrollPos
= scrollInfo
.nMin
;
9616 /* set the new position, and reread in case it changed */
9617 scrollInfo
.fMask
= SIF_POS
;
9618 scrollInfo
.nPos
= nNewScrollPos
;
9619 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9621 /* carry on only if it really changed */
9622 if (nNewScrollPos
== nOldScrollPos
) return 0;
9624 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9626 /* now adjust to client coordinates */
9627 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9628 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9630 /* and scroll the window */
9631 scroll_list(infoPtr
, nScrollDiff
, 0);
9636 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9638 INT gcWheelDelta
= 0;
9639 INT pulScrollLines
= 3;
9641 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9643 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9644 gcWheelDelta
-= wheelDelta
;
9646 switch(infoPtr
->uView
)
9649 case LV_VIEW_SMALLICON
:
9651 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9652 * should be fixed in the future.
9654 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (gcWheelDelta
< 0) ?
9655 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
, 0);
9658 case LV_VIEW_DETAILS
:
9659 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
9661 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9662 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
9663 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, cLineScroll
, 0);
9668 LISTVIEW_HScroll(infoPtr
, (gcWheelDelta
< 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0, 0);
9679 * [I] infoPtr : valid pointer to the listview structure
9680 * [I] nVirtualKey : virtual key
9681 * [I] lKeyData : key data
9686 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9688 HWND hwndSelf
= infoPtr
->hwndSelf
;
9690 NMLVKEYDOWN nmKeyDown
;
9692 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9694 /* send LVN_KEYDOWN notification */
9695 nmKeyDown
.wVKey
= nVirtualKey
;
9696 nmKeyDown
.flags
= 0;
9697 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9698 if (!IsWindow(hwndSelf
))
9701 switch (nVirtualKey
)
9704 nItem
= infoPtr
->nFocusedItem
;
9705 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9706 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9710 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9712 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9713 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9718 if (infoPtr
->nItemCount
> 0)
9723 if (infoPtr
->nItemCount
> 0)
9724 nItem
= infoPtr
->nItemCount
- 1;
9728 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9732 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9736 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9740 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9744 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9746 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9747 if (infoPtr
->nFocusedItem
== topidx
)
9748 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9753 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9754 * LISTVIEW_GetCountPerRow(infoPtr
);
9755 if(nItem
< 0) nItem
= 0;
9759 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9761 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9762 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9763 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9764 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9766 nItem
= topidx
+ cnt
- 1;
9769 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9770 * LISTVIEW_GetCountPerRow(infoPtr
);
9771 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9775 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9776 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
9786 * [I] infoPtr : valid pointer to the listview structure
9791 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
9795 /* if we did not have the focus, there's nothing to do */
9796 if (!infoPtr
->bFocus
) return 0;
9798 /* send NM_KILLFOCUS notification */
9799 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
9801 /* if we have a focus rectangle, get rid of it */
9802 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
9804 /* if have a marquee selection, stop it */
9805 if (infoPtr
->bMarqueeSelect
)
9807 /* Remove the marquee rectangle and release our mouse capture */
9808 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
9811 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
9813 infoPtr
->bMarqueeSelect
= FALSE
;
9814 infoPtr
->bScrolling
= FALSE
;
9815 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
9818 /* set window focus flag */
9819 infoPtr
->bFocus
= FALSE
;
9821 /* invalidate the selected items before resetting focus flag */
9822 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9829 * Processes double click messages (left mouse button).
9832 * [I] infoPtr : valid pointer to the listview structure
9833 * [I] wKey : key flag
9834 * [I] x,y : mouse coordinate
9839 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9841 LVHITTESTINFO htInfo
;
9843 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
9845 /* Cancel the item edition if any */
9846 if (infoPtr
->itemEdit
.fEnabled
)
9848 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
9849 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9852 /* send NM_RELEASEDCAPTURE notification */
9853 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9858 /* send NM_DBLCLK notification */
9859 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
9860 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
9862 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
9863 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
9870 * Processes mouse down messages (left mouse button).
9873 * infoPtr [I ] valid pointer to the listview structure
9874 * wKey [I ] key flag
9875 * x,y [I ] mouse coordinate
9880 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9882 LVHITTESTINFO lvHitTestInfo
;
9883 static BOOL bGroupSelect
= TRUE
;
9884 POINT pt
= { x
, y
};
9887 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
9889 /* send NM_RELEASEDCAPTURE notification */
9890 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9892 /* set left button down flag and record the click position */
9893 infoPtr
->bLButtonDown
= TRUE
;
9894 infoPtr
->ptClickPos
= pt
;
9895 infoPtr
->bDragging
= FALSE
;
9896 infoPtr
->bMarqueeSelect
= FALSE
;
9897 infoPtr
->bScrolling
= FALSE
;
9899 lvHitTestInfo
.pt
.x
= x
;
9900 lvHitTestInfo
.pt
.y
= y
;
9902 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
9903 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
9904 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
9906 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
9908 toggle_checkbox_state(infoPtr
, nItem
);
9912 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
9914 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9915 infoPtr
->nEditLabelItem
= nItem
;
9917 LISTVIEW_SetSelection(infoPtr
, nItem
);
9921 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
9925 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
9926 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9927 infoPtr
->nSelectionMark
= nItem
;
9933 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
9934 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9936 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
9937 infoPtr
->nSelectionMark
= nItem
;
9940 else if (wKey
& MK_CONTROL
)
9944 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
9946 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
9947 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9948 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
9949 infoPtr
->nSelectionMark
= nItem
;
9951 else if (wKey
& MK_SHIFT
)
9953 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
9957 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9959 infoPtr
->nEditLabelItem
= nItem
;
9960 infoPtr
->nLButtonDownItem
= nItem
;
9962 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9965 /* set selection (clears other pre-existing selections) */
9966 LISTVIEW_SetSelection(infoPtr
, nItem
);
9970 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
9971 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
9975 if (!infoPtr
->bFocus
)
9976 SetFocus(infoPtr
->hwndSelf
);
9978 /* remove all selections */
9979 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
9980 LISTVIEW_DeselectAll(infoPtr
);
9989 * Processes mouse up messages (left mouse button).
9992 * infoPtr [I ] valid pointer to the listview structure
9993 * wKey [I ] key flag
9994 * x,y [I ] mouse coordinate
9999 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10001 LVHITTESTINFO lvHitTestInfo
;
10003 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
10005 if (!infoPtr
->bLButtonDown
) return 0;
10007 lvHitTestInfo
.pt
.x
= x
;
10008 lvHitTestInfo
.pt
.y
= y
;
10010 /* send NM_CLICK notification */
10011 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10012 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10014 /* set left button flag */
10015 infoPtr
->bLButtonDown
= FALSE
;
10017 /* set a single selection, reset others */
10018 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10019 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10020 infoPtr
->nLButtonDownItem
= -1;
10022 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10024 /* Remove the marquee rectangle and release our mouse capture */
10025 if (infoPtr
->bMarqueeSelect
)
10027 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10031 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10032 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10034 infoPtr
->bDragging
= FALSE
;
10035 infoPtr
->bMarqueeSelect
= FALSE
;
10036 infoPtr
->bScrolling
= FALSE
;
10038 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10042 /* if we clicked on a selected item, edit the label */
10043 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10045 /* we want to make sure the user doesn't want to do a double click. So we will
10046 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10048 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10049 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10050 SetTimer(infoPtr
->hwndSelf
,
10051 (UINT_PTR
)&infoPtr
->itemEdit
,
10052 GetDoubleClickTime(),
10053 LISTVIEW_DelayedEditItem
);
10056 if (!infoPtr
->bFocus
)
10057 SetFocus(infoPtr
->hwndSelf
);
10064 * Destroys the listview control (called after WM_DESTROY).
10067 * [I] infoPtr : valid pointer to the listview structure
10072 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10078 /* destroy data structure */
10079 DPA_Destroy(infoPtr
->hdpaItems
);
10080 DPA_Destroy(infoPtr
->hdpaItemIds
);
10081 DPA_Destroy(infoPtr
->hdpaPosX
);
10082 DPA_Destroy(infoPtr
->hdpaPosY
);
10084 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10085 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10086 DPA_Destroy(infoPtr
->hdpaColumns
);
10087 ranges_destroy(infoPtr
->selectionRanges
);
10089 /* destroy image lists */
10090 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10092 ImageList_Destroy(infoPtr
->himlNormal
);
10093 ImageList_Destroy(infoPtr
->himlSmall
);
10094 ImageList_Destroy(infoPtr
->himlState
);
10097 /* destroy font, bkgnd brush */
10098 infoPtr
->hFont
= 0;
10099 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10100 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10102 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10104 /* free listview info pointer*/
10112 * Handles notifications from header.
10115 * [I] infoPtr : valid pointer to the listview structure
10116 * [I] nCtrlId : control identifier
10117 * [I] lpnmh : notification information
10122 static LRESULT
LISTVIEW_HeaderNotification(LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
10124 HWND hwndSelf
= infoPtr
->hwndSelf
;
10126 TRACE("(lpnmh=%p)\n", lpnmh
);
10128 if (!lpnmh
|| lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10130 switch (lpnmh
->hdr
.code
)
10135 COLUMN_INFO
*lpColumnInfo
;
10139 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10142 /* remove the old line (if any) */
10143 LISTVIEW_DrawTrackLine(infoPtr
);
10145 /* compute & draw the new line */
10146 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10147 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10148 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10149 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10150 LISTVIEW_DrawTrackLine(infoPtr
);
10154 case HDN_ENDTRACKA
:
10155 case HDN_ENDTRACKW
:
10156 /* remove the track line (if any) */
10157 LISTVIEW_DrawTrackLine(infoPtr
);
10158 infoPtr
->xTrackLine
= -1;
10161 case HDN_BEGINDRAG
:
10162 notify_forward_header(infoPtr
, lpnmh
);
10163 return (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0;
10166 infoPtr
->colRectsDirty
= TRUE
;
10167 LISTVIEW_InvalidateList(infoPtr
);
10168 notify_forward_header(infoPtr
, lpnmh
);
10171 case HDN_ITEMCHANGINGW
:
10172 case HDN_ITEMCHANGINGA
:
10173 return notify_forward_header(infoPtr
, lpnmh
);
10175 case HDN_ITEMCHANGEDW
:
10176 case HDN_ITEMCHANGEDA
:
10178 COLUMN_INFO
*lpColumnInfo
;
10182 notify_forward_header(infoPtr
, lpnmh
);
10183 if (!IsWindow(hwndSelf
))
10186 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10188 hdi
.mask
= HDI_WIDTH
;
10189 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10193 cxy
= lpnmh
->pitem
->cxy
;
10195 /* determine how much we change since the last know position */
10196 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10197 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10200 lpColumnInfo
->rcHeader
.right
+= dx
;
10202 hdi
.mask
= HDI_ORDER
;
10203 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10205 /* not the rightmost one */
10206 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10208 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10209 hdi
.iOrder
+ 1, 0);
10210 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10214 /* only needs to update the scrolls */
10215 infoPtr
->nItemWidth
+= dx
;
10216 LISTVIEW_UpdateScroll(infoPtr
);
10218 LISTVIEW_UpdateItemSize(infoPtr
);
10219 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10222 RECT rcCol
= lpColumnInfo
->rcHeader
;
10224 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10225 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10227 rcCol
.top
= infoPtr
->rcList
.top
;
10228 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10230 /* resizing left-aligned columns leaves most of the left side untouched */
10231 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10233 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10236 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10239 /* when shrinking the last column clear the now unused field */
10240 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10246 /* deal with right from rightmost column area */
10247 right
.left
= rcCol
.right
;
10248 right
.top
= rcCol
.top
;
10249 right
.bottom
= rcCol
.bottom
;
10250 right
.right
= infoPtr
->rcList
.right
;
10252 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10255 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10261 case HDN_ITEMCLICKW
:
10262 case HDN_ITEMCLICKA
:
10264 /* Handle sorting by Header Column */
10267 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10269 nmlv
.iSubItem
= lpnmh
->iItem
;
10270 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10271 notify_forward_header(infoPtr
, lpnmh
);
10275 case HDN_DIVIDERDBLCLICKW
:
10276 case HDN_DIVIDERDBLCLICKA
:
10277 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10278 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10279 split needed for that */
10280 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10281 notify_forward_header(infoPtr
, lpnmh
);
10290 * Paint non-client area of control.
10293 * [I] infoPtr : valid pointer to the listview structureof the sender
10294 * [I] region : update region
10297 * TRUE - frame was painted
10298 * FALSE - call default window proc
10300 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10302 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10306 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10307 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10310 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10312 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10314 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10315 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10316 if (region
!= (HRGN
)1)
10317 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10318 OffsetRect(&r
, -r
.left
, -r
.top
);
10320 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10321 OffsetRect(&r
, -r
.left
, -r
.top
);
10323 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10324 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10325 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10326 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10328 /* Call default proc to get the scrollbars etc. painted */
10329 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10336 * Determines the type of structure to use.
10339 * [I] infoPtr : valid pointer to the listview structureof the sender
10340 * [I] hwndFrom : listview window handle
10341 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10346 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10348 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10350 if (nCommand
== NF_REQUERY
)
10351 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10353 return infoPtr
->notifyFormat
;
10358 * Paints/Repaints the listview control. Internal use.
10361 * [I] infoPtr : valid pointer to the listview structure
10362 * [I] hdc : device context handle
10367 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10369 TRACE("(hdc=%p)\n", hdc
);
10371 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10373 infoPtr
->bNoItemMetrics
= FALSE
;
10374 LISTVIEW_UpdateItemSize(infoPtr
);
10375 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10376 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10377 LISTVIEW_UpdateScroll(infoPtr
);
10380 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10383 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10388 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10389 if (!hdc
) return 1;
10390 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10391 EndPaint(infoPtr
->hwndSelf
, &ps
);
10399 * Paints/Repaints the listview control, WM_PAINT handler.
10402 * [I] infoPtr : valid pointer to the listview structure
10403 * [I] hdc : device context handle
10408 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10410 TRACE("(hdc=%p)\n", hdc
);
10412 if (!is_redrawing(infoPtr
))
10413 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10415 return LISTVIEW_Paint(infoPtr
, hdc
);
10420 * Paints/Repaints the listview control.
10423 * [I] infoPtr : valid pointer to the listview structure
10424 * [I] hdc : device context handle
10425 * [I] options : drawing options
10430 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10432 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10434 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10437 if (options
& PRF_ERASEBKGND
)
10438 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10440 if (options
& PRF_CLIENT
)
10441 LISTVIEW_Paint(infoPtr
, hdc
);
10449 * Processes double click messages (right mouse button).
10452 * [I] infoPtr : valid pointer to the listview structure
10453 * [I] wKey : key flag
10454 * [I] x,y : mouse coordinate
10459 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10461 LVHITTESTINFO lvHitTestInfo
;
10463 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
10465 /* send NM_RELEASEDCAPTURE notification */
10466 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10468 /* send NM_RDBLCLK notification */
10469 lvHitTestInfo
.pt
.x
= x
;
10470 lvHitTestInfo
.pt
.y
= y
;
10471 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10472 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10479 * Processes mouse down messages (right mouse button).
10482 * [I] infoPtr : valid pointer to the listview structure
10483 * [I] wKey : key flag
10484 * [I] x,y : mouse coordinate
10489 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10491 LVHITTESTINFO lvHitTestInfo
;
10494 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
10496 /* send NM_RELEASEDCAPTURE notification */
10497 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10499 /* make sure the listview control window has the focus */
10500 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10502 /* set right button down flag */
10503 infoPtr
->bRButtonDown
= TRUE
;
10505 /* determine the index of the selected item */
10506 lvHitTestInfo
.pt
.x
= x
;
10507 lvHitTestInfo
.pt
.y
= y
;
10508 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10510 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10512 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10513 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10514 !LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10515 LISTVIEW_SetSelection(infoPtr
, nItem
);
10519 LISTVIEW_DeselectAll(infoPtr
);
10527 * Processes mouse up messages (right mouse button).
10530 * [I] infoPtr : valid pointer to the listview structure
10531 * [I] wKey : key flag
10532 * [I] x,y : mouse coordinate
10537 static LRESULT
LISTVIEW_RButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10539 LVHITTESTINFO lvHitTestInfo
;
10542 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
10544 if (!infoPtr
->bRButtonDown
) return 0;
10546 /* set button flag */
10547 infoPtr
->bRButtonDown
= FALSE
;
10549 /* Send NM_RCLICK notification */
10550 lvHitTestInfo
.pt
.x
= x
;
10551 lvHitTestInfo
.pt
.y
= y
;
10552 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10553 if (!notify_click(infoPtr
, NM_RCLICK
, &lvHitTestInfo
)) return 0;
10555 /* Change to screen coordinate for WM_CONTEXTMENU */
10556 pt
= lvHitTestInfo
.pt
;
10557 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
10559 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
10560 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10561 (WPARAM
)infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
10572 * [I] infoPtr : valid pointer to the listview structure
10573 * [I] hwnd : window handle of window containing the cursor
10574 * [I] nHittest : hit-test code
10575 * [I] wMouseMsg : ideintifier of the mouse message
10578 * TRUE if cursor is set
10581 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10583 LVHITTESTINFO lvHitTestInfo
;
10585 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10587 if (!infoPtr
->hHotCursor
) goto forward
;
10589 GetCursorPos(&lvHitTestInfo
.pt
);
10590 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10592 SetCursor(infoPtr
->hHotCursor
);
10598 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10606 * [I] infoPtr : valid pointer to the listview structure
10607 * [I] hwndLoseFocus : handle of previously focused window
10612 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10614 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10616 /* if we have the focus already, there's nothing to do */
10617 if (infoPtr
->bFocus
) return 0;
10619 /* send NM_SETFOCUS notification */
10620 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10622 /* set window focus flag */
10623 infoPtr
->bFocus
= TRUE
;
10625 /* put the focus rect back on */
10626 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10628 /* redraw all visible selected items */
10629 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10639 * [I] infoPtr : valid pointer to the listview structure
10640 * [I] fRedraw : font handle
10641 * [I] fRedraw : redraw flag
10646 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10648 HFONT oldFont
= infoPtr
->hFont
;
10650 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10652 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10653 if (infoPtr
->hFont
== oldFont
) return 0;
10655 LISTVIEW_SaveTextMetrics(infoPtr
);
10657 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10659 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10660 LISTVIEW_UpdateSize(infoPtr
);
10661 LISTVIEW_UpdateScroll(infoPtr
);
10664 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10671 * Message handling for WM_SETREDRAW.
10672 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10675 * [I] infoPtr : valid pointer to the listview structure
10676 * [I] bRedraw: state of redraw flag
10679 * DefWinProc return value
10681 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10683 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10685 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10686 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10688 infoPtr
->bRedraw
= bRedraw
;
10690 if(!bRedraw
) return 0;
10692 if (is_autoarrange(infoPtr
))
10693 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10694 LISTVIEW_UpdateScroll(infoPtr
);
10696 /* despite what the WM_SETREDRAW docs says, apps expect us
10697 * to invalidate the listview here... stupid! */
10698 LISTVIEW_InvalidateList(infoPtr
);
10705 * Resizes the listview control. This function processes WM_SIZE
10706 * messages. At this time, the width and height are not used.
10709 * [I] infoPtr : valid pointer to the listview structure
10710 * [I] Width : new width
10711 * [I] Height : new height
10716 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10718 RECT rcOld
= infoPtr
->rcList
;
10720 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10722 LISTVIEW_UpdateSize(infoPtr
);
10723 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10725 /* do not bother with display related stuff if we're not redrawing */
10726 if (!is_redrawing(infoPtr
)) return 0;
10728 if (is_autoarrange(infoPtr
))
10729 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10731 LISTVIEW_UpdateScroll(infoPtr
);
10733 /* refresh all only for lists whose height changed significantly */
10734 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10735 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10736 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10737 LISTVIEW_InvalidateList(infoPtr
);
10744 * Sets the size information.
10747 * [I] infoPtr : valid pointer to the listview structure
10752 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10754 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
10756 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
10758 if (infoPtr
->uView
== LV_VIEW_LIST
)
10760 /* Apparently the "LIST" style is supposed to have the same
10761 * number of items in a column even if there is no scroll bar.
10762 * Since if a scroll bar already exists then the bottom is already
10763 * reduced, only reduce if the scroll bar does not currently exist.
10764 * The "2" is there to mimic the native control. I think it may be
10765 * related to either padding or edges. (GLA 7/2002)
10767 if (!(infoPtr
->dwStyle
& WS_HSCROLL
))
10768 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
10769 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
10772 /* if control created invisible header isn't created */
10773 if (infoPtr
->hwndHeader
)
10778 hl
.prc
= &infoPtr
->rcList
;
10780 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10781 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10783 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
10784 wp
.flags
|= SWP_SHOWWINDOW
;
10787 wp
.flags
|= SWP_HIDEWINDOW
;
10791 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
10792 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10794 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
10796 /* extra padding for grid */
10797 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
10798 infoPtr
->rcList
.top
+= 2;
10800 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
10805 * Processes WM_STYLECHANGED messages.
10808 * [I] infoPtr : valid pointer to the listview structure
10809 * [I] wStyleType : window style type (normal or extended)
10810 * [I] lpss : window style information
10815 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10816 const STYLESTRUCT
*lpss
)
10818 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
10819 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
10822 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10823 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10825 if (wStyleType
!= GWL_STYLE
) return 0;
10827 infoPtr
->dwStyle
= lpss
->styleNew
;
10828 map_style_view(infoPtr
);
10830 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
10831 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
10832 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
10834 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
10835 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
10836 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
10838 if (uNewView
!= uOldView
)
10840 SIZE oldIconSize
= infoPtr
->iconSize
;
10843 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
10844 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
10846 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
10847 SetRectEmpty(&infoPtr
->rcFocus
);
10849 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
10850 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
10852 if (uNewView
== LVS_ICON
)
10854 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
10856 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
10857 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
10858 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
10861 else if (uNewView
== LVS_REPORT
)
10866 LISTVIEW_CreateHeader( infoPtr
);
10868 hl
.prc
= &infoPtr
->rcList
;
10870 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10871 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
10872 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
10873 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
10876 LISTVIEW_UpdateItemSize(infoPtr
);
10879 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
10881 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
10883 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
10885 /* Turn off the header control */
10886 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
10887 TRACE("Hide header control, was 0x%08x\n", style
);
10888 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
10890 /* Turn on the header control */
10891 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
10893 TRACE("Show header control, was 0x%08x\n", style
);
10894 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
10900 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
10901 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
10902 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10904 /* update the size of the client area */
10905 LISTVIEW_UpdateSize(infoPtr
);
10907 /* add scrollbars if needed */
10908 LISTVIEW_UpdateScroll(infoPtr
);
10910 /* invalidate client area + erase background */
10911 LISTVIEW_InvalidateList(infoPtr
);
10918 * Processes WM_STYLECHANGING messages.
10921 * [I] infoPtr : valid pointer to the listview structure
10922 * [I] wStyleType : window style type (normal or extended)
10923 * [I0] lpss : window style information
10928 static INT
LISTVIEW_StyleChanging(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10931 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10932 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10934 /* don't forward LVS_OWNERDATA only if not already set to */
10935 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
10937 if (lpss
->styleOld
& LVS_OWNERDATA
)
10938 lpss
->styleNew
|= LVS_OWNERDATA
;
10940 lpss
->styleNew
&= ~LVS_OWNERDATA
;
10948 * Processes WM_SHOWWINDOW messages.
10951 * [I] infoPtr : valid pointer to the listview structure
10952 * [I] bShown : window is being shown (FALSE when hidden)
10953 * [I] iStatus : window show status
10958 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
10960 /* header delayed creation */
10961 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
10963 LISTVIEW_CreateHeader(infoPtr
);
10965 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
10966 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
10969 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
10974 * Processes CCM_GETVERSION messages.
10977 * [I] infoPtr : valid pointer to the listview structure
10982 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
10984 return infoPtr
->iVersion
;
10989 * Processes CCM_SETVERSION messages.
10992 * [I] infoPtr : valid pointer to the listview structure
10993 * [I] iVersion : version to be set
10996 * -1 when requested version is greater than DLL version;
10997 * previous version otherwise
10999 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11001 INT iOldVersion
= infoPtr
->iVersion
;
11003 if (iVersion
> COMCTL32_VERSION
)
11006 infoPtr
->iVersion
= iVersion
;
11008 TRACE("new version %d\n", iVersion
);
11010 return iOldVersion
;
11015 * Window procedure of the listview control.
11018 static LRESULT WINAPI
11019 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11021 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11023 TRACE("(uMsg=%x wParam=%lx lParam=%lx)\n", uMsg
, wParam
, lParam
);
11025 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11026 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11030 case LVM_APPROXIMATEVIEWRECT
:
11031 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11032 LOWORD(lParam
), HIWORD(lParam
));
11034 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11036 case LVM_CANCELEDITLABEL
:
11037 return LISTVIEW_CancelEditLabel(infoPtr
);
11039 case LVM_CREATEDRAGIMAGE
:
11040 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11042 case LVM_DELETEALLITEMS
:
11043 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11045 case LVM_DELETECOLUMN
:
11046 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11048 case LVM_DELETEITEM
:
11049 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11051 case LVM_EDITLABELA
:
11052 case LVM_EDITLABELW
:
11053 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11054 uMsg
== LVM_EDITLABELW
);
11055 /* case LVM_ENABLEGROUPVIEW: */
11057 case LVM_ENSUREVISIBLE
:
11058 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11060 case LVM_FINDITEMW
:
11061 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11063 case LVM_FINDITEMA
:
11064 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11066 case LVM_GETBKCOLOR
:
11067 return infoPtr
->clrBk
;
11069 /* case LVM_GETBKIMAGE: */
11071 case LVM_GETCALLBACKMASK
:
11072 return infoPtr
->uCallbackMask
;
11074 case LVM_GETCOLUMNA
:
11075 case LVM_GETCOLUMNW
:
11076 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11077 uMsg
== LVM_GETCOLUMNW
);
11079 case LVM_GETCOLUMNORDERARRAY
:
11080 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11082 case LVM_GETCOLUMNWIDTH
:
11083 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11085 case LVM_GETCOUNTPERPAGE
:
11086 return LISTVIEW_GetCountPerPage(infoPtr
);
11088 case LVM_GETEDITCONTROL
:
11089 return (LRESULT
)infoPtr
->hwndEdit
;
11091 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11092 return infoPtr
->dwLvExStyle
;
11094 /* case LVM_GETGROUPINFO: */
11096 /* case LVM_GETGROUPMETRICS: */
11098 case LVM_GETHEADER
:
11099 return (LRESULT
)infoPtr
->hwndHeader
;
11101 case LVM_GETHOTCURSOR
:
11102 return (LRESULT
)infoPtr
->hHotCursor
;
11104 case LVM_GETHOTITEM
:
11105 return infoPtr
->nHotItem
;
11107 case LVM_GETHOVERTIME
:
11108 return infoPtr
->dwHoverTime
;
11110 case LVM_GETIMAGELIST
:
11111 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11113 /* case LVM_GETINSERTMARK: */
11115 /* case LVM_GETINSERTMARKCOLOR: */
11117 /* case LVM_GETINSERTMARKRECT: */
11119 case LVM_GETISEARCHSTRINGA
:
11120 case LVM_GETISEARCHSTRINGW
:
11121 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11126 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11128 case LVM_GETITEMCOUNT
:
11129 return infoPtr
->nItemCount
;
11131 case LVM_GETITEMPOSITION
:
11132 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11134 case LVM_GETITEMRECT
:
11135 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11137 case LVM_GETITEMSPACING
:
11138 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11140 case LVM_GETITEMSTATE
:
11141 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11143 case LVM_GETITEMTEXTA
:
11144 case LVM_GETITEMTEXTW
:
11145 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11146 uMsg
== LVM_GETITEMTEXTW
);
11148 case LVM_GETNEXTITEM
:
11149 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11151 case LVM_GETNUMBEROFWORKAREAS
:
11152 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11155 case LVM_GETORIGIN
:
11156 if (!lParam
) return FALSE
;
11157 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11158 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11159 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11162 /* case LVM_GETOUTLINECOLOR: */
11164 /* case LVM_GETSELECTEDCOLUMN: */
11166 case LVM_GETSELECTEDCOUNT
:
11167 return LISTVIEW_GetSelectedCount(infoPtr
);
11169 case LVM_GETSELECTIONMARK
:
11170 return infoPtr
->nSelectionMark
;
11172 case LVM_GETSTRINGWIDTHA
:
11173 case LVM_GETSTRINGWIDTHW
:
11174 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11175 uMsg
== LVM_GETSTRINGWIDTHW
);
11177 case LVM_GETSUBITEMRECT
:
11178 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11180 case LVM_GETTEXTBKCOLOR
:
11181 return infoPtr
->clrTextBk
;
11183 case LVM_GETTEXTCOLOR
:
11184 return infoPtr
->clrText
;
11186 /* case LVM_GETTILEINFO: */
11188 /* case LVM_GETTILEVIEWINFO: */
11190 case LVM_GETTOOLTIPS
:
11191 if( !infoPtr
->hwndToolTip
)
11192 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11193 return (LRESULT
)infoPtr
->hwndToolTip
;
11195 case LVM_GETTOPINDEX
:
11196 return LISTVIEW_GetTopIndex(infoPtr
);
11198 case LVM_GETUNICODEFORMAT
:
11199 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11202 return infoPtr
->uView
;
11204 case LVM_GETVIEWRECT
:
11205 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11207 case LVM_GETWORKAREAS
:
11208 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11211 /* case LVM_HASGROUP: */
11214 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11216 case LVM_INSERTCOLUMNA
:
11217 case LVM_INSERTCOLUMNW
:
11218 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11219 uMsg
== LVM_INSERTCOLUMNW
);
11221 /* case LVM_INSERTGROUP: */
11223 /* case LVM_INSERTGROUPSORTED: */
11225 case LVM_INSERTITEMA
:
11226 case LVM_INSERTITEMW
:
11227 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11229 /* case LVM_INSERTMARKHITTEST: */
11231 /* case LVM_ISGROUPVIEWENABLED: */
11233 case LVM_ISITEMVISIBLE
:
11234 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11236 case LVM_MAPIDTOINDEX
:
11237 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11239 case LVM_MAPINDEXTOID
:
11240 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11242 /* case LVM_MOVEGROUP: */
11244 /* case LVM_MOVEITEMTOGROUP: */
11246 case LVM_REDRAWITEMS
:
11247 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11249 /* case LVM_REMOVEALLGROUPS: */
11251 /* case LVM_REMOVEGROUP: */
11254 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11256 case LVM_SETBKCOLOR
:
11257 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11259 /* case LVM_SETBKIMAGE: */
11261 case LVM_SETCALLBACKMASK
:
11262 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11265 case LVM_SETCOLUMNA
:
11266 case LVM_SETCOLUMNW
:
11267 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11268 uMsg
== LVM_SETCOLUMNW
);
11270 case LVM_SETCOLUMNORDERARRAY
:
11271 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11273 case LVM_SETCOLUMNWIDTH
:
11274 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11276 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11277 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11279 /* case LVM_SETGROUPINFO: */
11281 /* case LVM_SETGROUPMETRICS: */
11283 case LVM_SETHOTCURSOR
:
11284 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11286 case LVM_SETHOTITEM
:
11287 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11289 case LVM_SETHOVERTIME
:
11290 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11292 case LVM_SETICONSPACING
:
11293 return LISTVIEW_SetIconSpacing(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
11295 case LVM_SETIMAGELIST
:
11296 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11298 /* case LVM_SETINFOTIP: */
11300 /* case LVM_SETINSERTMARK: */
11302 /* case LVM_SETINSERTMARKCOLOR: */
11307 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11308 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11311 case LVM_SETITEMCOUNT
:
11312 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11314 case LVM_SETITEMPOSITION
:
11317 pt
.x
= (short)LOWORD(lParam
);
11318 pt
.y
= (short)HIWORD(lParam
);
11319 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11322 case LVM_SETITEMPOSITION32
:
11323 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11325 case LVM_SETITEMSTATE
:
11326 if (lParam
== 0) return FALSE
;
11327 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11329 case LVM_SETITEMTEXTA
:
11330 case LVM_SETITEMTEXTW
:
11331 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11332 uMsg
== LVM_SETITEMTEXTW
);
11334 /* case LVM_SETOUTLINECOLOR: */
11336 /* case LVM_SETSELECTEDCOLUMN: */
11338 case LVM_SETSELECTIONMARK
:
11339 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11341 case LVM_SETTEXTBKCOLOR
:
11342 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11344 case LVM_SETTEXTCOLOR
:
11345 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11347 /* case LVM_SETTILEINFO: */
11349 /* case LVM_SETTILEVIEWINFO: */
11351 /* case LVM_SETTILEWIDTH: */
11353 case LVM_SETTOOLTIPS
:
11354 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11356 case LVM_SETUNICODEFORMAT
:
11357 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11360 return LISTVIEW_SetView(infoPtr
, wParam
);
11362 /* case LVM_SETWORKAREAS: */
11364 /* case LVM_SORTGROUPS: */
11366 case LVM_SORTITEMS
:
11367 case LVM_SORTITEMSEX
:
11368 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11369 uMsg
== LVM_SORTITEMSEX
);
11370 case LVM_SUBITEMHITTEST
:
11371 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11374 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11376 case CCM_GETVERSION
:
11377 return LISTVIEW_GetVersion(infoPtr
);
11379 case CCM_SETVERSION
:
11380 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11383 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11386 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11389 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11392 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11395 return LISTVIEW_Destroy(infoPtr
);
11398 return LISTVIEW_Enable(infoPtr
, (BOOL
)wParam
);
11400 case WM_ERASEBKGND
:
11401 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11403 case WM_GETDLGCODE
:
11404 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11407 return (LRESULT
)infoPtr
->hFont
;
11410 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
11413 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11416 return LISTVIEW_KillFocus(infoPtr
);
11418 case WM_LBUTTONDBLCLK
:
11419 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11421 case WM_LBUTTONDOWN
:
11422 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11425 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11428 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11430 case WM_MOUSEHOVER
:
11431 return LISTVIEW_MouseHover(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11434 return LISTVIEW_NCDestroy(infoPtr
);
11437 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11440 if (lParam
&& ((LPNMHDR
)lParam
)->hwndFrom
== infoPtr
->hwndHeader
)
11441 return LISTVIEW_HeaderNotification(infoPtr
, (LPNMHEADERW
)lParam
);
11444 case WM_NOTIFYFORMAT
:
11445 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11447 case WM_PRINTCLIENT
:
11448 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11451 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11453 case WM_RBUTTONDBLCLK
:
11454 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11456 case WM_RBUTTONDOWN
:
11457 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11460 return LISTVIEW_RButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11463 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11466 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11469 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11472 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11474 case WM_SHOWWINDOW
:
11475 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11478 return LISTVIEW_Size(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
11480 case WM_STYLECHANGED
:
11481 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11483 case WM_STYLECHANGING
:
11484 return LISTVIEW_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11486 case WM_SYSCOLORCHANGE
:
11487 COMCTL32_RefreshSysColors();
11490 /* case WM_TIMER: */
11491 case WM_THEMECHANGED
:
11492 return LISTVIEW_ThemeChanged(infoPtr
);
11495 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
11497 case WM_MOUSEWHEEL
:
11498 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11499 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11500 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11502 case WM_WINDOWPOSCHANGED
:
11503 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11505 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11506 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11508 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11510 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11513 LISTVIEW_UpdateSize(infoPtr
);
11514 LISTVIEW_UpdateScroll(infoPtr
);
11516 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11518 /* case WM_WININICHANGE: */
11521 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11522 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11524 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11531 * Registers the window class.
11539 void LISTVIEW_Register(void)
11541 WNDCLASSW wndClass
;
11543 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11544 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11545 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11546 wndClass
.cbClsExtra
= 0;
11547 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11548 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11549 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11550 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11551 RegisterClassW(&wndClass
);
11556 * Unregisters the window class.
11564 void LISTVIEW_Unregister(void)
11566 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11571 * Handle any WM_COMMAND messages
11574 * [I] infoPtr : valid pointer to the listview structure
11575 * [I] wParam : the first message parameter
11576 * [I] lParam : the second message parameter
11581 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11583 switch (HIWORD(wParam
))
11588 * Adjust the edit window size
11590 WCHAR buffer
[1024];
11591 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11592 HFONT hFont
, hOldFont
= 0;
11596 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11597 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11598 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11600 /* Select font to get the right dimension of the string */
11601 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11604 hOldFont
= SelectObject(hdc
, hFont
);
11607 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11609 TEXTMETRICW textMetric
;
11611 /* Add Extra spacing for the next character */
11612 GetTextMetricsW(hdc
, &textMetric
);
11613 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11621 rect
.bottom
- rect
.top
,
11622 SWP_DRAWFRAME
|SWP_NOMOVE
);
11625 SelectObject(hdc
, hOldFont
);
11627 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11633 LISTVIEW_CancelEditLabel(infoPtr
);
11638 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);