[PATCH v3 1/4] comctl32/listbox: Move the item data insertion into a separate function
Gabriel Ivăncescu
gabrielopcode at gmail.com
Mon Feb 18 06:09:03 CST 2019
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
This is a no-op patch. nb_items is incremented before the call and this is
taken care of in the helper function. This is for two reasons:
1) This simplifies the nodata patch (only adds a single line to
insert_item_data).
2) This matches what RemoveItem does, so it's more consistent.
dlls/comctl32/listbox.c | 62 ++++++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 29 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
index 50ff5c5..330d3ae 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -176,6 +176,38 @@ 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, INT index, WCHAR *str, ULONG_PTR data)
+{
+ LB_ITEMDATA *item;
+
+ item = &descr->items[index];
+
+ if (index < descr->nb_items - 1)
+ RtlMoveMemory(item + 1, item,
+ (descr->nb_items - 1 - index) * sizeof(LB_ITEMDATA));
+ item->str = str;
+ item->data = HAS_STRINGS(descr) ? 0 : data;
+ item->height = 0;
+ item->selected = FALSE;
+
+ /* Get item height */
+ if (descr->style & LBS_OWNERDRAWVARIABLE)
+ {
+ MEASUREITEMSTRUCT mis;
+ UINT id = (UINT)GetWindowLongPtrW( descr->self, GWLP_ID );
+
+ mis.CtlType = ODT_LISTBOX;
+ mis.CtlID = id;
+ mis.itemID = index;
+ mis.itemData = data;
+ mis.itemHeight = descr->item_height;
+ 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 );
+ }
+}
+
/***********************************************************************
* LISTBOX_GetCurrentPageSize
*
@@ -1553,42 +1585,14 @@ 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;
descr->nb_items++;
-
- /* Get item height */
-
- if (descr->style & LBS_OWNERDRAWVARIABLE)
- {
- MEASUREITEMSTRUCT mis;
- UINT id = (UINT)GetWindowLongPtrW( descr->self, GWLP_ID );
-
- mis.CtlType = ODT_LISTBOX;
- mis.CtlID = id;
- mis.itemID = index;
- mis.itemData = data;
- mis.itemHeight = descr->item_height;
- 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 );
- }
+ insert_item_data(descr, index, str, data);
/* Repaint the items */
--
2.20.1
More information about the wine-devel
mailing list