[gtk/wip/otte/bitset: 4/4] multiselection: WIP: Port to GtkBitset
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/bitset: 4/4] multiselection: WIP: Port to GtkBitset
- Date: Sat, 13 Jun 2020 03:30:09 +0000 (UTC)
commit 96a4dfcf1ad15d66775f7e6e31dafc844b5499ca
Author: Benjamin Otte <otte redhat com>
Date: Sat Jun 13 05:27:34 2020 +0200
multiselection: WIP: Port to GtkBitset
gtk/gtkmultiselection.c | 53 +++++++++++++++++++++++++++++++++----------------
1 file changed, 36 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtkmultiselection.c b/gtk/gtkmultiselection.c
index 70045b525c..ba5279ffbf 100644
--- a/gtk/gtkmultiselection.c
+++ b/gtk/gtkmultiselection.c
@@ -21,9 +21,9 @@
#include "gtkmultiselection.h"
+#include "gtkbitset.h"
#include "gtkintl.h"
#include "gtkselectionmodel.h"
-#include "gtkset.h"
/**
* SECTION:gtkmultiselection
@@ -47,7 +47,7 @@ struct _GtkMultiSelection
GListModel *model;
- GtkSet *selected;
+ GtkBitset *selected;
};
struct _GtkMultiSelectionClass
@@ -103,7 +103,7 @@ gtk_multi_selection_is_selected (GtkSelectionModel *model,
{
GtkMultiSelection *self = GTK_MULTI_SELECTION (model);
- return gtk_set_contains (self->selected, position);
+ return gtk_bitset_contains (self->selected, position);
}
static gboolean
@@ -118,12 +118,12 @@ gtk_multi_selection_select_range (GtkSelectionModel *model,
if (exclusive)
{
- min = gtk_set_get_min (self->selected);
- max = gtk_set_get_max (self->selected);
- gtk_set_remove_all (self->selected);
+ min = gtk_bitset_get_minimum (self->selected);
+ max = gtk_bitset_get_maximum (self->selected);
+ gtk_bitset_remove_all (self->selected);
}
- gtk_set_add_range (self->selected, position, n_items);
+ gtk_bitset_add_range (self->selected, position, n_items);
min = MIN (position, min);
max = MAX (max, position + n_items - 1);
@@ -140,7 +140,7 @@ gtk_multi_selection_unselect_range (GtkSelectionModel *model,
{
GtkMultiSelection *self = GTK_MULTI_SELECTION (model);
- gtk_set_remove_range (self->selected, position, n_items);
+ gtk_bitset_remove_range (self->selected, position, n_items);
gtk_selection_model_selection_changed (model, position, n_items);
return TRUE;
@@ -193,9 +193,9 @@ gtk_multi_selection_add_or_remove (GtkSelectionModel *model,
if (unselect_rest)
{
- min = gtk_set_get_min (self->selected);
- max = gtk_set_get_max (self->selected);
- gtk_set_remove_all (self->selected);
+ min = gtk_bitset_get_minimum (self->selected);
+ max = gtk_bitset_get_maximum (self->selected);
+ gtk_bitset_remove_all (self->selected);
}
for (pos = 0; pos < n; pos = start + n_items)
@@ -215,9 +215,9 @@ gtk_multi_selection_add_or_remove (GtkSelectionModel *model,
max = start + n_items - 1;
if (add)
- gtk_set_add_range (self->selected, start, n_items);
+ gtk_bitset_add_range (self->selected, start, n_items);
else
- gtk_set_remove_range (self->selected, start, n_items);
+ gtk_bitset_remove_range (self->selected, start, n_items);
}
pos = start + n_items;
@@ -246,6 +246,7 @@ gtk_multi_selection_unselect_callback (GtkSelectionModel *model,
return gtk_multi_selection_add_or_remove (model, FALSE, FALSE, callback, data);
}
+#if 0
static void
gtk_multi_selection_query_range (GtkSelectionModel *model,
guint position,
@@ -258,6 +259,7 @@ gtk_multi_selection_query_range (GtkSelectionModel *model,
gtk_set_find_range (self->selected, position, upper_bound, start_range, n_items, selected);
}
+#endif
static void
gtk_multi_selection_selection_model_init (GtkSelectionModelInterface *iface)
@@ -271,7 +273,9 @@ gtk_multi_selection_selection_model_init (GtkSelectionModelInterface *iface)
iface->unselect_all = gtk_multi_selection_unselect_all;
iface->select_callback = gtk_multi_selection_select_callback;
iface->unselect_callback = gtk_multi_selection_unselect_callback;
+#if 0
iface->query_range = gtk_multi_selection_query_range;
+#endif
}
G_DEFINE_TYPE_EXTENDED (GtkMultiSelection, gtk_multi_selection, G_TYPE_OBJECT, 0,
@@ -287,8 +291,23 @@ gtk_multi_selection_items_changed_cb (GListModel *model,
guint added,
GtkMultiSelection *self)
{
- gtk_set_remove_range (self->selected, position, removed);
- gtk_set_shift (self->selected, position, (int)added - (int)removed);
+ gtk_bitset_remove_range (self->selected, position, removed);
+
+ if (removed != added)
+ {
+ GtkBitset *shift;
+
+ shift = gtk_bitset_copy (self->selected);
+ gtk_bitset_remove_range (shift, 0, position);
+ gtk_bitset_remove_range (self->selected, position, G_MAXUINT - position);
+ if (added > removed)
+ gtk_bitset_shift_right (shift, added - removed);
+ else
+ gtk_bitset_shift_left (shift, removed - added);
+ gtk_bitset_union (self->selected, shift);
+ gtk_bitset_unref (shift);
+ }
+
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
}
@@ -357,7 +376,7 @@ gtk_multi_selection_dispose (GObject *object)
gtk_multi_selection_clear_model (self);
- g_clear_pointer (&self->selected, gtk_set_free);
+ g_clear_pointer (&self->selected, gtk_bitset_unref);
G_OBJECT_CLASS (gtk_multi_selection_parent_class)->dispose (object);
}
@@ -389,7 +408,7 @@ gtk_multi_selection_class_init (GtkMultiSelectionClass *klass)
static void
gtk_multi_selection_init (GtkMultiSelection *self)
{
- self->selected = gtk_set_new ();
+ self->selected = gtk_bitset_new_empty ();
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]