[PATCH v2 08/10] comctl32/listbox: Send LB_RESETCONTENT from RemoveItem rather than DeleteItem
Gabriel Ivăncescu
gabrielopcode at gmail.com
Mon Feb 11 11:03:11 CST 2019
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
Ok, this is how I ended up making the code simpler later. The reason being
that it really makes no sense at all to send LB_RESETCONTENT from within
DeleteItem: that function is called *from* ResetContent itself and it only
happened to work since it updated nb_items afterward. It was too fragile
to begin with.
Note that LB_RESETCONTENT already calls DeleteItem, so we can simply re-use
that, and IMO this makes much more sense and will simplify the code in the
last patch.
dlls/comctl32/listbox.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
index 633e7c6..0f74e80 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -1660,13 +1660,9 @@ static LRESULT LISTBOX_InsertString( LB_DESCR *descr, INT index, LPCWSTR str )
*/
static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index )
{
- /* save the item data before it gets freed by LB_RESETCONTENT */
ULONG_PTR item_data = descr->items[index].data;
LPWSTR item_str = descr->items[index].str;
- if (!descr->nb_items)
- SendMessageW( descr->self, LB_RESETCONTENT, 0, 0 );
-
/* Note: Win 3.1 only sends DELETEITEM on owner-draw items,
* while Win95 sends it for all items with user data.
* It's probably better to send it too often than not
@@ -1703,11 +1699,14 @@ static LRESULT LISTBOX_RemoveItem( LB_DESCR *descr, INT index )
/* We need to invalidate the original rect instead of the updated one. */
LISTBOX_InvalidateItems( descr, index );
+ if (descr->nb_items == 1)
+ {
+ SendMessageW(descr->self, LB_RESETCONTENT, 0, 0);
+ return LB_OKAY;
+ }
descr->nb_items--;
LISTBOX_DeleteItem( descr, index );
- if (!descr->nb_items) return LB_OKAY;
-
/* Remove the item */
item = &descr->items[index];
--
2.20.1
More information about the wine-devel
mailing list