[PATCH 8/9] user32/listbox: Use a helper to set the selected item state

Gabriel Iv─âncescu gabrielopcode at gmail.com
Thu Feb 14 06:06:47 CST 2019


Signed-off-by: Gabriel Iv─âncescu <gabrielopcode at gmail.com>
---
 dlls/user32/listbox.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/dlls/user32/listbox.c b/dlls/user32/listbox.c
index f2d12ed..7f9076f 100644
--- a/dlls/user32/listbox.c
+++ b/dlls/user32/listbox.c
@@ -165,6 +165,12 @@ static BOOL is_item_selected( const LB_DESCR *descr, UINT index )
     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 class descriptor
  */
@@ -1443,7 +1449,7 @@ static LRESULT LISTBOX_SelectItemRange( LB_DESCR *descr, INT first,
         for (i = first; i <= last; i++)
         {
             if (is_item_selected(descr, i)) continue;
-            descr->items[i].selected = TRUE;
+            set_item_selected_state(descr, i, TRUE);
             LISTBOX_InvalidateItemRect(descr, i);
         }
     }
@@ -1452,7 +1458,7 @@ static LRESULT LISTBOX_SelectItemRange( LB_DESCR *descr, INT first,
         for (i = first; i <= last; i++)
         {
             if (!is_item_selected(descr, i)) continue;
-            descr->items[i].selected = FALSE;
+            set_item_selected_state(descr, i, FALSE);
             LISTBOX_InvalidateItemRect(descr, i);
         }
     }
@@ -1485,8 +1491,8 @@ static LRESULT LISTBOX_SetSelection( LB_DESCR *descr, INT index,
     {
         INT oldsel = descr->selected_item;
         if (index == oldsel) return LB_OKAY;
-        if (oldsel != -1) descr->items[oldsel].selected = FALSE;
-        if (index != -1) descr->items[index].selected = TRUE;
+        if (oldsel != -1) set_item_selected_state(descr, oldsel, FALSE);
+        if (index != -1) set_item_selected_state(descr, index, TRUE);
         descr->selected_item = index;
         if (oldsel != -1) LISTBOX_RepaintItem( descr, oldsel, ODA_SELECT );
         if (index != -1) LISTBOX_RepaintItem( descr, index, ODA_SELECT );
-- 
2.20.1




More information about the wine-devel mailing list