diff options
-rw-r--r-- | gtk/gtkmultifilter.c | 105 | ||||
-rw-r--r-- | gtk/gtkmultisorter.c | 89 |
2 files changed, 79 insertions, 115 deletions
diff --git a/gtk/gtkmultifilter.c b/gtk/gtkmultifilter.c index 6fb08cc9da..893c8f1563 100644 --- a/gtk/gtkmultifilter.c +++ b/gtk/gtkmultifilter.c @@ -25,6 +25,13 @@ #include "gtkintl.h" #include "gtktypebuiltins.h" +#define GDK_ARRAY_TYPE_NAME GtkFilters +#define GDK_ARRAY_NAME gtk_filters +#define GDK_ARRAY_ELEMENT_TYPE GtkFilter * +#define GDK_ARRAY_FREE_FUNC g_object_unref + +#include "gdk/gdkarrayimpl.c" + /*** MULTI FILTER ***/ /** @@ -45,7 +52,7 @@ struct _GtkMultiFilter { GtkFilter parent_instance; - GSequence *filters; + GtkFilters filters; }; struct _GtkMultiFilterClass @@ -67,7 +74,7 @@ gtk_multi_filter_get_n_items (GListModel *list) { GtkMultiFilter *self = GTK_MULTI_FILTER (list); - return g_sequence_get_length (self->filters); + return gtk_filters_get_size (&self->filters); } static gpointer @@ -75,14 +82,11 @@ gtk_multi_filter_get_item (GListModel *list, guint position) { GtkMultiFilter *self = GTK_MULTI_FILTER (list); - GSequenceIter *iter; - iter = g_sequence_get_iter_at_pos (self->filters, position); - - if (g_sequence_iter_is_end (iter)) - return NULL; + if (position < gtk_filters_get_size (&self->filters)) + return g_object_ref (gtk_filters_get (&self->filters, position)); else - return g_object_ref (g_sequence_get (iter)); + return NULL; } static void @@ -128,37 +132,20 @@ gtk_multi_filter_changed_cb (GtkFilter *filter, } static void -gtk_multi_filter_remove_iter (GtkMultiFilter *self, - GSequenceIter *iter) -{ - GtkFilter *filter; - - filter = g_sequence_get (iter); - g_signal_handlers_disconnect_by_func (filter, gtk_multi_filter_changed_cb, self); - g_object_unref (filter); - g_sequence_remove (iter); -} - -static void gtk_multi_filter_dispose (GObject *object) { GtkMultiFilter *self = GTK_MULTI_FILTER (object); + guint i; - while (!g_sequence_is_empty (self->filters)) - gtk_multi_filter_remove_iter (self, g_sequence_get_begin_iter (self->filters)); - - G_OBJECT_CLASS (gtk_multi_filter_parent_class)->dispose (object); -} - -static void -gtk_multi_filter_finalize (GObject *object) -{ - GtkMultiFilter *self = GTK_MULTI_FILTER (object); + for (i = 0; i < gtk_filters_get_size (&self->filters); i++) + { + GtkFilter *filter = gtk_filters_get (&self->filters, i); + g_signal_handlers_disconnect_by_func (filter, gtk_multi_filter_changed_cb, self); + } - g_assert (g_sequence_is_empty (self->filters)); - g_sequence_free (self->filters); + gtk_filters_clear (&self->filters); - G_OBJECT_CLASS (gtk_multi_filter_parent_class)->finalize (object); + G_OBJECT_CLASS (gtk_multi_filter_parent_class)->dispose (object); } static void @@ -167,13 +154,12 @@ gtk_multi_filter_class_init (GtkMultiFilterClass *class) GObjectClass *object_class = G_OBJECT_CLASS (class); object_class->dispose = gtk_multi_filter_dispose; - object_class->finalize = gtk_multi_filter_finalize; } static void gtk_multi_filter_init (GtkMultiFilter *self) { - self->filters = g_sequence_new (NULL); + gtk_filters_init (&self->filters); } /** @@ -191,7 +177,7 @@ gtk_multi_filter_append (GtkMultiFilter *self, g_return_if_fail (GTK_IS_FILTER (filter)); g_signal_connect (filter, "changed", G_CALLBACK (gtk_multi_filter_changed_cb), self); - g_sequence_append (self->filters, filter); + gtk_filters_append (&self->filters, filter); gtk_filter_changed (GTK_FILTER (self), GTK_MULTI_FILTER_GET_CLASS (self)->addition_change); @@ -211,15 +197,16 @@ void gtk_multi_filter_remove (GtkMultiFilter *self, guint position) { - GSequenceIter *iter; guint length; + GtkFilter *filter; - length = g_sequence_get_length (self->filters); + length = gtk_filters_get_size (&self->filters); if (position >= length) return; - iter = g_sequence_get_iter_at_pos (self->filters, position); - gtk_multi_filter_remove_iter (self, iter); + filter = gtk_filters_get (&self->filters, position); + g_signal_handlers_disconnect_by_func (filter, gtk_multi_filter_changed_cb, self); + gtk_filters_splice (&self->filters, position, 1, NULL, 0); gtk_filter_changed (GTK_FILTER (self), GTK_MULTI_FILTER_GET_CLASS (self)->removal_change); @@ -244,13 +231,11 @@ gtk_any_filter_match (GtkFilter *filter, gpointer item) { GtkMultiFilter *self = GTK_MULTI_FILTER (filter); - GSequenceIter *iter; + guint i; - for (iter = g_sequence_get_begin_iter (self->filters); - !g_sequence_iter_is_end (iter); - iter = g_sequence_iter_next (iter)) + for (i = 0; i < gtk_filters_get_size (&self->filters); i++) { - GtkFilter *child = g_sequence_get (iter); + GtkFilter *child = gtk_filters_get (&self->filters, i); if (gtk_filter_match (child, item)) return TRUE; @@ -262,15 +247,13 @@ gtk_any_filter_match (GtkFilter *filter, static GtkFilterMatch gtk_any_filter_get_strictness (GtkFilter *filter) { - GtkMultiFilter *multi = GTK_MULTI_FILTER (filter); - GSequenceIter *iter; + GtkMultiFilter *self = GTK_MULTI_FILTER (filter); + guint i; GtkFilterMatch result = GTK_FILTER_MATCH_NONE; - for (iter = g_sequence_get_begin_iter (multi->filters); - !g_sequence_iter_is_end (iter); - iter = g_sequence_iter_next (iter)) + for (i = 0; i < gtk_filters_get_size (&self->filters); i++) { - GtkFilter *child = g_sequence_get (iter); + GtkFilter *child = gtk_filters_get (&self->filters, i); switch (gtk_filter_get_strictness (child)) { @@ -346,13 +329,11 @@ gtk_every_filter_match (GtkFilter *filter, gpointer item) { GtkMultiFilter *self = GTK_MULTI_FILTER (filter); - GSequenceIter *iter; + guint i; - for (iter = g_sequence_get_begin_iter (self->filters); - !g_sequence_iter_is_end (iter); - iter = g_sequence_iter_next (iter)) + for (i = 0; i < gtk_filters_get_size (&self->filters); i++) { - GtkFilter *child = g_sequence_get (iter); + GtkFilter *child = gtk_filters_get (&self->filters, i); if (!gtk_filter_match (child, item)) return FALSE; @@ -364,15 +345,13 @@ gtk_every_filter_match (GtkFilter *filter, static GtkFilterMatch gtk_every_filter_get_strictness (GtkFilter *filter) { - GtkMultiFilter *multi = GTK_MULTI_FILTER (filter); - GSequenceIter *iter; + GtkMultiFilter *self = GTK_MULTI_FILTER (filter); + guint i; GtkFilterMatch result = GTK_FILTER_MATCH_ALL; - for (iter = g_sequence_get_begin_iter (multi->filters); - !g_sequence_iter_is_end (iter); - iter = g_sequence_iter_next (iter)) + for (i = 0; i < gtk_filters_get_size (&self->filters); i++) { - GtkFilter *child = g_sequence_get (iter); + GtkFilter *child = gtk_filters_get (&self->filters, i); switch (gtk_filter_get_strictness (child)) { @@ -413,7 +392,7 @@ gtk_every_filter_init (GtkEveryFilter *self) /** * gtk_every_filter_new: * - * Creates a new empty "every" filter. + * Creates a new empty "every" filter. * Use gtk_multi_filter_append() to add filters to it. * * This filter matches an item if each of the filters added to it diff --git a/gtk/gtkmultisorter.c b/gtk/gtkmultisorter.c index 66400c50a2..6d1f2120b0 100644 --- a/gtk/gtkmultisorter.c +++ b/gtk/gtkmultisorter.c @@ -25,6 +25,13 @@ #include "gtkintl.h" #include "gtktypebuiltins.h" +#define GDK_ARRAY_TYPE_NAME GtkSorters +#define GDK_ARRAY_NAME gtk_sorters +#define GDK_ARRAY_ELEMENT_TYPE GtkSorter * +#define GDK_ARRAY_FREE_FUNC g_object_unref + +#include "gdk/gdkarrayimpl.c" + /** * SECTION:gtkmultisorter * @Title: GtkMultiSorter @@ -38,7 +45,7 @@ struct _GtkMultiSorter { GtkSorter parent_instance; - GSequence *sorters; + GtkSorters sorters; }; static GType @@ -52,7 +59,7 @@ gtk_multi_sorter_get_n_items (GListModel *list) { GtkMultiSorter *self = GTK_MULTI_SORTER (list); - return g_sequence_get_length (self->sorters); + return gtk_sorters_get_size (&self->sorters); } static gpointer @@ -60,14 +67,11 @@ gtk_multi_sorter_get_item (GListModel *list, guint position) { GtkMultiSorter *self = GTK_MULTI_SORTER (list); - GSequenceIter *iter; - - iter = g_sequence_get_iter_at_pos (self->sorters, position); - if (g_sequence_iter_is_end (iter)) - return NULL; + if (position < gtk_sorters_get_size (&self->sorters)) + return g_object_ref (gtk_sorters_get (&self->sorters, position)); else - return g_object_ref (g_sequence_get (iter)); + return NULL; } static void @@ -111,13 +115,11 @@ gtk_multi_sorter_compare (GtkSorter *sorter, { GtkMultiSorter *self = GTK_MULTI_SORTER (sorter); GtkOrdering result = GTK_ORDERING_EQUAL; - GSequenceIter *iter; + guint i; - for (iter = g_sequence_get_begin_iter (self->sorters); - !g_sequence_iter_is_end (iter); - iter = g_sequence_iter_next (iter)) + for (i = 0; i < gtk_sorters_get_size (&self->sorters); i++) { - GtkSorter *child = g_sequence_get (iter); + GtkSorter *child = gtk_sorters_get (&self->sorters, i); result = gtk_sorter_compare (child, item1, item2); if (result != GTK_ORDERING_EQUAL) @@ -132,13 +134,11 @@ gtk_multi_sorter_get_order (GtkSorter *sorter) { GtkMultiSorter *self = GTK_MULTI_SORTER (sorter); GtkSorterOrder result = GTK_SORTER_ORDER_NONE; - GSequenceIter *iter; + guint i; - for (iter = g_sequence_get_begin_iter (self->sorters); - !g_sequence_iter_is_end (iter); - iter = g_sequence_iter_next (iter)) + for (i = 0; i < gtk_sorters_get_size (&self->sorters); i++) { - GtkSorter *child = g_sequence_get (iter); + GtkSorter *child = gtk_sorters_get (&self->sorters, i); GtkSorterOrder child_order; child_order = gtk_sorter_get_order (child); @@ -166,12 +166,14 @@ gtk_multi_sorter_changed_cb (GtkSorter *sorter, GtkMultiSorter *self) { /* Using an enum on purpose, so gcc complains about this case if - * new values are added to the enum */ + * new values are added to the enum + */ switch (change) { case GTK_SORTER_CHANGE_INVERTED: - /* This could do a lot better with change handling, in particular in cases where self->n_sorters == 1 - * or if sorter == self->sorters[0] */ + /* This could do a lot better with change handling, in particular in + * cases where self->n_sorters == 1 or if sorter == self->sorters[0] + */ change = GTK_SORTER_CHANGE_DIFFERENT; break; @@ -188,39 +190,22 @@ gtk_multi_sorter_changed_cb (GtkSorter *sorter, } static void -gtk_multi_sorter_remove_iter (GtkMultiSorter *self, - GSequenceIter *iter) -{ - GtkSorter *sorter; - - sorter = g_sequence_get (iter); - g_signal_handlers_disconnect_by_func (sorter, gtk_multi_sorter_changed_cb, self); - g_object_unref (sorter); - g_sequence_remove (iter); -} - -static void gtk_multi_sorter_dispose (GObject *object) { GtkMultiSorter *self = GTK_MULTI_SORTER (object); + guint i; - while (!g_sequence_is_empty (self->sorters)) - gtk_multi_sorter_remove_iter (self, g_sequence_get_begin_iter (self->sorters)); + for (i = 0; i < gtk_sorters_get_size (&self->sorters); i++) + { + GtkSorter *sorter = gtk_sorters_get (&self->sorters, i); + g_signal_handlers_disconnect_by_func (sorter, gtk_multi_sorter_changed_cb, self); + } + gtk_sorters_clear (&self->sorters); G_OBJECT_CLASS (gtk_multi_sorter_parent_class)->dispose (object); } static void -gtk_multi_sorter_finalize (GObject *object) -{ - GtkMultiSorter *self = GTK_MULTI_SORTER (object); - - g_sequence_free (self->sorters); - - G_OBJECT_CLASS (gtk_multi_sorter_parent_class)->finalize (object); -} - -static void gtk_multi_sorter_class_init (GtkMultiSorterClass *class) { GtkSorterClass *sorter_class = GTK_SORTER_CLASS (class); @@ -230,13 +215,12 @@ gtk_multi_sorter_class_init (GtkMultiSorterClass *class) sorter_class->get_order = gtk_multi_sorter_get_order; object_class->dispose = gtk_multi_sorter_dispose; - object_class->finalize = gtk_multi_sorter_finalize; } static void gtk_multi_sorter_init (GtkMultiSorter *self) { - self->sorters = g_sequence_new (NULL); + gtk_sorters_init (&self->sorters); } /** @@ -274,7 +258,7 @@ gtk_multi_sorter_append (GtkMultiSorter *self, g_return_if_fail (GTK_IS_SORTER (sorter)); g_signal_connect (sorter, "changed", G_CALLBACK (gtk_multi_sorter_changed_cb), self); - g_sequence_append (self->sorters, sorter); + gtk_sorters_append (&self->sorters, sorter); gtk_sorter_changed (GTK_SORTER (self), GTK_SORTER_CHANGE_MORE_STRICT); } @@ -293,17 +277,18 @@ void gtk_multi_sorter_remove (GtkMultiSorter *self, guint position) { - GSequenceIter *iter; guint length; + GtkSorter *sorter; g_return_if_fail (GTK_IS_MULTI_SORTER (self)); - length = g_sequence_get_length (self->sorters); + length = gtk_sorters_get_size (&self->sorters); if (position >= length) return; - iter = g_sequence_get_iter_at_pos (self->sorters, position); - gtk_multi_sorter_remove_iter (self, iter); + sorter = gtk_sorters_get (&self->sorters, position); + g_signal_handlers_disconnect_by_func (sorter, gtk_multi_sorter_changed_cb, self); + gtk_sorters_splice (&self->sorters, position, 1, NULL, 0); gtk_sorter_changed (GTK_SORTER (self), GTK_SORTER_CHANGE_LESS_STRICT); } |