comctl32/listbox: Use a helper to set the selected item state.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gabriel Ivăncescu 2019-02-13 16:36:19 +02:00 committed by Alexandre Julliard
parent c033748c66
commit 7834e40989
1 changed files with 10 additions and 4 deletions

View File

@ -170,6 +170,12 @@ static BOOL is_item_selected( const LB_DESCR *descr, UINT index )
return descr->items[index].selected; return descr->items[index].selected;
} }
static void set_item_selected_state(LB_DESCR *descr, UINT index, BOOL state)
{
if (descr->style & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL))
descr->items[index].selected = state;
}
/*********************************************************************** /***********************************************************************
* LISTBOX_GetCurrentPageSize * LISTBOX_GetCurrentPageSize
* *
@ -1435,7 +1441,7 @@ static LRESULT LISTBOX_SelectItemRange( LB_DESCR *descr, INT first,
for (i = first; i <= last; i++) for (i = first; i <= last; i++)
{ {
if (is_item_selected(descr, i)) continue; if (is_item_selected(descr, i)) continue;
descr->items[i].selected = TRUE; set_item_selected_state(descr, i, TRUE);
LISTBOX_InvalidateItemRect(descr, i); LISTBOX_InvalidateItemRect(descr, i);
} }
} }
@ -1444,7 +1450,7 @@ static LRESULT LISTBOX_SelectItemRange( LB_DESCR *descr, INT first,
for (i = first; i <= last; i++) for (i = first; i <= last; i++)
{ {
if (!is_item_selected(descr, i)) continue; if (!is_item_selected(descr, i)) continue;
descr->items[i].selected = FALSE; set_item_selected_state(descr, i, FALSE);
LISTBOX_InvalidateItemRect(descr, i); LISTBOX_InvalidateItemRect(descr, i);
} }
} }
@ -1477,8 +1483,8 @@ static LRESULT LISTBOX_SetSelection( LB_DESCR *descr, INT index,
{ {
INT oldsel = descr->selected_item; INT oldsel = descr->selected_item;
if (index == oldsel) return LB_OKAY; if (index == oldsel) return LB_OKAY;
if (oldsel != -1) descr->items[oldsel].selected = FALSE; if (oldsel != -1) set_item_selected_state(descr, oldsel, FALSE);
if (index != -1) descr->items[index].selected = TRUE; if (index != -1) set_item_selected_state(descr, index, TRUE);
descr->selected_item = index; descr->selected_item = index;
if (oldsel != -1) LISTBOX_RepaintItem( descr, oldsel, ODA_SELECT ); if (oldsel != -1) LISTBOX_RepaintItem( descr, oldsel, ODA_SELECT );
if (index != -1) LISTBOX_RepaintItem( descr, index, ODA_SELECT ); if (index != -1) LISTBOX_RepaintItem( descr, index, ODA_SELECT );