[PATCH v2 09/10] comctl32/listbox: Move the item data insertion into a separate function
Gabriel Ivăncescu
gabrielopcode at gmail.com
Mon Feb 11 11:03:12 CST 2019
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
This is a no-op patch, but note how nb_items is incremented before and this
is taken care of in the helper function. This is for two reasons:
1) This simplifies the next patch (only adds a single line to insert_item).
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 0f74e80..1f56c99 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -182,6 +182,38 @@ static WCHAR *get_item_string( const LB_DESCR *descr, UINT index )
return (descr->style & LBS_NODATA) ? NULL : descr->items[index].str;
}
+static void insert_item(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
*
@@ -1556,42 +1588,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(descr, index, str, data);
/* Repaint the items */
--
2.20.1
More information about the wine-devel
mailing list