Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/comctl32/listbox.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c index 50ff5c5..a457d63 100644 --- a/dlls/comctl32/listbox.c +++ b/dlls/comctl32/listbox.c @@ -163,6 +163,11 @@ static WCHAR *get_item_string( const LB_DESCR *descr, UINT index ) return HAS_STRINGS(descr) ? descr->items[index].str : NULL; }
+static UINT get_item_height( const LB_DESCR *descr, UINT index ) +{ + return (descr->style & LBS_NODATA) ? 0 : descr->items[index].height; +} + static BOOL is_item_selected( const LB_DESCR *descr, UINT index ) { if (!(descr->style & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL))) @@ -187,7 +192,7 @@ static INT LISTBOX_GetCurrentPageSize( const LB_DESCR *descr ) if (!(descr->style & LBS_OWNERDRAWVARIABLE)) return descr->page_size; for (i = descr->top_item, height = 0; i < descr->nb_items; i++) { - if ((height += descr->items[i].height) > descr->height) break; + if ((height += get_item_height(descr, i)) > descr->height) break; } if (i == descr->top_item) return 1; else return i - descr->top_item; @@ -207,7 +212,7 @@ static INT LISTBOX_GetMaxTopIndex( const LB_DESCR *descr ) { page = descr->height; for (max = descr->nb_items - 1; max >= 0; max--) - if ((page -= descr->items[max].height) < 0) break; + if ((page -= get_item_height(descr, max)) < 0) break; if (max < descr->nb_items - 1) max++; } else if (descr->style & LBS_MULTICOLUMN) @@ -335,12 +340,12 @@ static LRESULT LISTBOX_SetTopItem( LB_DESCR *descr, INT index, BOOL scroll ) if (index > descr->top_item) { for (i = index - 1; i >= descr->top_item; i--) - dy -= descr->items[i].height; + dy -= get_item_height(descr, i); } else { for (i = index; i < descr->top_item; i++) - dy += descr->items[i].height; + dy += get_item_height(descr, i); } } else @@ -456,14 +461,14 @@ static LRESULT LISTBOX_GetItemRect( const LB_DESCR *descr, INT index, RECT *rect if (index < descr->top_item) { for (i = descr->top_item-1; i >= index; i--) - rect->top -= descr->items[i].height; + rect->top -= get_item_height(descr, i); } else { for (i = descr->top_item; i < index; i++) - rect->top += descr->items[i].height; + rect->top += get_item_height(descr, i); } - rect->bottom = rect->top + descr->items[index].height; + rect->bottom = rect->top + get_item_height(descr, index);
} } @@ -498,7 +503,7 @@ static INT LISTBOX_GetItemFromPoint( const LB_DESCR *descr, INT x, INT y ) { while (index < descr->nb_items) { - if ((pos += descr->items[index].height) > y) break; + if ((pos += get_item_height(descr, index)) > y) break; index++; } } @@ -507,7 +512,7 @@ static INT LISTBOX_GetItemFromPoint( const LB_DESCR *descr, INT x, INT y ) while (index > 0) { index--; - if ((pos -= descr->items[index].height) <= y) break; + if ((pos -= get_item_height(descr, index)) <= y) break; } } } @@ -1057,7 +1062,7 @@ static LRESULT LISTBOX_Paint( LB_DESCR *descr, HDC hdc ) if (!(descr->style & LBS_OWNERDRAWVARIABLE)) rect.bottom = rect.top + descr->item_height; else - rect.bottom = rect.top + descr->items[i].height; + rect.bottom = rect.top + get_item_height(descr, i);
/* keep the focus rect, to paint the focus item after */ if (i == descr->focus_item) @@ -1204,7 +1209,7 @@ static LRESULT LISTBOX_GetItemHeight( const LB_DESCR *descr, INT index ) SetLastError(ERROR_INVALID_INDEX); return LB_ERR; } - return descr->items[index].height; + return get_item_height(descr, index); } else return descr->item_height; } @@ -1374,9 +1379,9 @@ static void LISTBOX_MakeItemVisible( LB_DESCR *descr, INT index, BOOL fully ) } else if (descr->style & LBS_OWNERDRAWVARIABLE) { - INT height = fully ? descr->items[index].height : 1; + INT height = fully ? get_item_height(descr, index) : 1; for (top = index; top > descr->top_item; top--) - if ((height += descr->items[top-1].height) > descr->height) break; + if ((height += get_item_height(descr, top - 1)) > descr->height) break; } else { @@ -1587,7 +1592,7 @@ static LRESULT LISTBOX_InsertItem( LB_DESCR *descr, INT index, SendMessageW( descr->owner, WM_MEASUREITEM, id, (LPARAM)&mis ); item->height = mis.itemHeight ? mis.itemHeight : 1; TRACE("[%p]: measure item %d (%s) = %d\n", - descr->self, index, str ? debugstr_w(str) : "", item->height ); + descr->self, index, str ? debugstr_w(str) : "", get_item_height(descr, index)); }
/* Repaint the items */
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/comctl32/listbox.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c index a457d63..ba8b7ee 100644 --- a/dlls/comctl32/listbox.c +++ b/dlls/comctl32/listbox.c @@ -168,6 +168,11 @@ static UINT get_item_height( const LB_DESCR *descr, UINT index ) return (descr->style & LBS_NODATA) ? 0 : descr->items[index].height; }
+static void set_item_height( LB_DESCR *descr, UINT index, UINT height ) +{ + if (!(descr->style & LBS_NODATA)) descr->items[index].height = height; +} + static BOOL is_item_selected( const LB_DESCR *descr, UINT index ) { if (!(descr->style & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL))) @@ -1233,7 +1238,7 @@ static LRESULT LISTBOX_SetItemHeight( LB_DESCR *descr, INT index, INT height, BO return LB_ERR; } TRACE("[%p]: item %d height = %d\n", descr->self, index, height ); - descr->items[index].height = height; + set_item_height(descr, index, height); LISTBOX_UpdateScroll( descr ); if (repaint) LISTBOX_InvalidateItems( descr, index ); @@ -1590,7 +1595,7 @@ static LRESULT LISTBOX_InsertItem( LB_DESCR *descr, INT index, mis.itemData = data; mis.itemHeight = descr->item_height; SendMessageW( descr->owner, WM_MEASUREITEM, id, (LPARAM)&mis ); - item->height = mis.itemHeight ? mis.itemHeight : 1; + set_item_height(descr, index, mis.itemHeight ? mis.itemHeight : 1); TRACE("[%p]: measure item %d (%s) = %d\n", descr->self, index, str ? debugstr_w(str) : "", get_item_height(descr, index)); }
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/comctl32/listbox.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c index ba8b7ee..6b7cc54 100644 --- a/dlls/comctl32/listbox.c +++ b/dlls/comctl32/listbox.c @@ -186,6 +186,20 @@ static void set_item_selected_state(LB_DESCR *descr, UINT index, BOOL state) descr->items[index].selected = state; }
+static void insert_item_data(LB_DESCR *descr, UINT index, WCHAR *str, ULONG_PTR data) +{ + LB_ITEMDATA *item; + + item = &descr->items[index]; + if (index < descr->nb_items) + RtlMoveMemory(item + 1, item, + (descr->nb_items - index) * sizeof(LB_ITEMDATA)); + item->str = str; + item->data = HAS_STRINGS(descr) ? 0 : data; + item->height = 0; + item->selected = FALSE; +} + /*********************************************************************** * LISTBOX_GetCurrentPageSize * @@ -1563,23 +1577,13 @@ static void LISTBOX_MoveCaret( LB_DESCR *descr, INT index, BOOL fully_visible ) static LRESULT LISTBOX_InsertItem( LB_DESCR *descr, INT index, LPWSTR str, ULONG_PTR data ) { - LB_ITEMDATA *item; INT oldfocus = descr->focus_item;
if (index == -1) index = descr->nb_items; else if ((index < 0) || (index > descr->nb_items)) return LB_ERR; if (!resize_storage(descr, descr->nb_items + 1)) return LB_ERR;
- /* Insert the item structure */ - - item = &descr->items[index]; - if (index < descr->nb_items) - RtlMoveMemory( item + 1, item, - (descr->nb_items - index) * sizeof(LB_ITEMDATA) ); - item->str = str; - item->data = HAS_STRINGS(descr) ? 0 : data; - item->height = 0; - item->selected = FALSE; + insert_item_data(descr, index, str, data); descr->nb_items++;
/* Get item height */
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/comctl32/listbox.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c index 6b7cc54..31e5f71 100644 --- a/dlls/comctl32/listbox.c +++ b/dlls/comctl32/listbox.c @@ -200,6 +200,13 @@ static void insert_item_data(LB_DESCR *descr, UINT index, WCHAR *str, ULONG_PTR item->selected = FALSE; }
+static void remove_item_data(LB_DESCR *descr, UINT index) +{ + if (index < descr->nb_items) + RtlMoveMemory(&descr->items[index], &descr->items[index + 1], + (descr->nb_items - index) * sizeof(LB_ITEMDATA)); +} + /*********************************************************************** * LISTBOX_GetCurrentPageSize * @@ -1699,8 +1706,6 @@ static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index ) */ static LRESULT LISTBOX_RemoveItem( LB_DESCR *descr, INT index ) { - LB_ITEMDATA *item; - if ((index < 0) || (index >= descr->nb_items)) return LB_ERR;
/* We need to invalidate the original rect instead of the updated one. */ @@ -1713,15 +1718,9 @@ static LRESULT LISTBOX_RemoveItem( LB_DESCR *descr, INT index ) } descr->nb_items--; LISTBOX_DeleteItem( descr, index ); + remove_item_data(descr, index);
- /* Remove the item */ - - item = &descr->items[index]; - if (index < descr->nb_items) - RtlMoveMemory( item, item + 1, - (descr->nb_items - index) * sizeof(LB_ITEMDATA) ); if (descr->anchor_item == descr->nb_items) descr->anchor_item--; - resize_storage(descr, descr->nb_items);
/* Repaint the items */
The LBS_NODATA style's purpose is to drastically improve performance and memory usage on very large lists, since they should function as virtual lists. Thus, don't store any data for single-selection listboxes (descr->items always NULL).
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=32374 Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/comctl32/listbox.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c index 31e5f71..db9548d 100644 --- a/dlls/comctl32/listbox.c +++ b/dlls/comctl32/listbox.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * TODO: - * - LBS_NODATA + * - LBS_NODATA for multi-selection listboxes */
#include <string.h> @@ -135,17 +135,20 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size) items_size + LB_ARRAY_GRANULARITY * 2 < descr->items_size) { items_size = (items_size + LB_ARRAY_GRANULARITY - 1) & ~(LB_ARRAY_GRANULARITY - 1); - items = heap_realloc(descr->items, items_size * sizeof(LB_ITEMDATA)); - if (!items) + if ((descr->style & (LBS_NODATA | LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != LBS_NODATA) { - SEND_NOTIFICATION(descr, LBN_ERRSPACE); - return FALSE; + items = heap_realloc(descr->items, items_size * sizeof(LB_ITEMDATA)); + if (!items) + { + SEND_NOTIFICATION(descr, LBN_ERRSPACE); + return FALSE; + } + descr->items = items; } descr->items_size = items_size; - descr->items = items; }
- if ((descr->style & LBS_NODATA) && items_size > descr->nb_items) + if ((descr->style & LBS_NODATA) && descr->items && items_size > descr->nb_items) { memset(&descr->items[descr->nb_items], 0, (items_size - descr->nb_items) * sizeof(LB_ITEMDATA)); @@ -190,6 +193,8 @@ static void insert_item_data(LB_DESCR *descr, UINT index, WCHAR *str, ULONG_PTR { LB_ITEMDATA *item;
+ if (!descr->items) return; + item = &descr->items[index]; if (index < descr->nb_items) RtlMoveMemory(item + 1, item, @@ -202,6 +207,8 @@ static void insert_item_data(LB_DESCR *descr, UINT index, WCHAR *str, ULONG_PTR
static void remove_item_data(LB_DESCR *descr, UINT index) { + if (!descr->items) return; + if (index < descr->nb_items) RtlMoveMemory(&descr->items[index], &descr->items[index + 1], (descr->nb_items - index) * sizeof(LB_ITEMDATA)); @@ -1760,7 +1767,8 @@ static void LISTBOX_ResetContent( LB_DESCR *descr ) { INT i;
- for(i = descr->nb_items - 1; i>=0; i--) LISTBOX_DeleteItem( descr, i); + if (!(descr->style & LBS_NODATA)) + for (i = descr->nb_items - 1; i >= 0; i--) LISTBOX_DeleteItem(descr, i); HeapFree( GetProcessHeap(), 0, descr->items ); descr->nb_items = 0; descr->top_item = 0;
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/comctl32/tests/listbox.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/dlls/comctl32/tests/listbox.c b/dlls/comctl32/tests/listbox.c index 0cdcdea..de73ad2 100644 --- a/dlls/comctl32/tests/listbox.c +++ b/dlls/comctl32/tests/listbox.c @@ -1996,6 +1996,11 @@ static void test_set_count( void ) GetUpdateRect( listbox, &r, TRUE ); ok( !IsRectEmpty( &r ), "got empty rect\n");
+ ret = SendMessageA( listbox, LB_SETCOUNT, -5, 0 ); + ok( ret == 0, "got %d\n", ret ); + ret = SendMessageA( listbox, LB_GETCOUNT, 0, 0 ); + ok( ret == -5, "got %d\n", ret ); + DestroyWindow( listbox );
for (i = 0; i < ARRAY_SIZE(styles); ++i)