[gtk/misc-multiselection] multiselection: Rewrite the select_callback implementation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/misc-multiselection] multiselection: Rewrite the select_callback implementation
- Date: Sat, 6 Jun 2020 15:23:53 +0000 (UTC)
commit 3e6e247e56b1ca91a6e5b7f3dd3666cfcfcfbe28
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 6 11:21:29 2020 -0400
multiselection: Rewrite the select_callback implementation
Use a for loop to make this more obvious, and add some
assertions that the callback is behaving properly.
gtk/gtkmultiselection.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkmultiselection.c b/gtk/gtkmultiselection.c
index 11caa78fc1..a852972bee 100644
--- a/gtk/gtkmultiselection.c
+++ b/gtk/gtkmultiselection.c
@@ -180,32 +180,40 @@ gtk_multi_selection_add_or_remove (GtkSelectionModel *model,
gpointer data)
{
GtkMultiSelection *self = GTK_MULTI_SELECTION (model);
- guint pos, start, n;
+ guint pos, start, n_items;
gboolean in;
guint min, max;
+ guint n;
+
+ n = g_list_model_get_n_items (G_LIST_MODEL (self));
min = G_MAXUINT;
max = 0;
- pos = 0;
- do
+ for (pos = 0; pos < n; pos = start + n_items)
{
- callback (pos, &start, &n, &in, data);
+ callback (pos, &start, &n_items, &in, data);
+
+ if (n_items == 0)
+ break;
+
+ g_assert (start <= pos && pos < start + n_items);
+
if (in)
{
if (start < min)
min = start;
- if (start + n - 1 > max)
- max = start + n - 1;
+ if (start + n_items - 1 > max)
+ max = start + n_items - 1;
if (add)
- gtk_set_add_range (self->selected, start, n);
+ gtk_set_add_range (self->selected, start, n_items);
else
- gtk_set_remove_range (self->selected, start, n);
+ gtk_set_remove_range (self->selected, start, n_items);
}
- pos = start + n;
+
+ pos = start + n_items;
}
- while (n > 0);
if (min <= max)
gtk_selection_model_selection_changed (model, min, max - min + 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]