[gtk/wip/otte/sortlistmodel: 17/38] sortkeys: Add an equal sort keys



commit 3014dc74609720c36e64eff6ec14ef3a870c26dd
Author: Benjamin Otte <otte redhat com>
Date:   Thu Jul 16 12:05:45 2020 +0200

    sortkeys: Add an equal sort keys
    
    Compares every element as equal.
    This is useful when sorters are in an invalid configuration.

 gtk/gtksortkeys.c        | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtksortkeysprivate.h |  2 ++
 2 files changed, 55 insertions(+)
---
diff --git a/gtk/gtksortkeys.c b/gtk/gtksortkeys.c
index d99939fe1b..032c60b4f2 100644
--- a/gtk/gtksortkeys.c
+++ b/gtk/gtksortkeys.c
@@ -95,3 +95,56 @@ gtk_sort_keys_needs_clear_key (GtkSortKeys *self)
   return self->klass->clear_key != NULL;
 }
 
+static void
+gtk_equal_sort_keys_free (GtkSortKeys *keys)
+{
+  g_slice_free (GtkSortKeys, keys);
+}
+
+static int
+gtk_equal_sort_keys_compare (gconstpointer a,
+                             gconstpointer b,
+                             gpointer      unused)
+{
+  return GTK_ORDERING_EQUAL;
+}
+
+static gboolean
+gtk_equal_sort_keys_is_compatible (GtkSortKeys *keys,
+                                   GtkSortKeys *other)
+{
+  return keys->klass == other->klass;
+}
+
+static void
+gtk_equal_sort_keys_init_key (GtkSortKeys *keys,
+                               gpointer     item,
+                               gpointer     key_memory)
+{
+}
+
+static const GtkSortKeysClass GTK_EQUAL_SORT_KEYS_CLASS =
+{
+  gtk_equal_sort_keys_free,
+  gtk_equal_sort_keys_compare,
+  gtk_equal_sort_keys_is_compatible,
+  gtk_equal_sort_keys_init_key,
+  NULL
+};
+
+/*<private>
+ * gtk_sort_keys_new_equal:
+ *
+ * Creates a new #GtkSortKeys that compares every element as equal.
+ * This is useful when sorters are in an invalid configuration.
+ *
+ * Returns: a new #GtkSortKeys
+ **/
+GtkSortKeys *
+gtk_sort_keys_new_equal (void)
+{
+  return gtk_sort_keys_new (GtkSortKeys,
+                            &GTK_EQUAL_SORT_KEYS_CLASS,
+                            0, 1);
+}
+
diff --git a/gtk/gtksortkeysprivate.h b/gtk/gtksortkeysprivate.h
index d213ffb43b..c9f93b69dc 100644
--- a/gtk/gtksortkeysprivate.h
+++ b/gtk/gtksortkeysprivate.h
@@ -59,6 +59,8 @@ GtkSortKeys *           gtk_sort_keys_alloc                     (const GtkSortKe
 GtkSortKeys *           gtk_sort_keys_ref                       (GtkSortKeys            *self);
 void                    gtk_sort_keys_unref                     (GtkSortKeys            *self);
 
+GtkSortKeys *           gtk_sort_keys_new_equal                 (void);
+
 gsize                   gtk_sort_keys_get_key_size              (GtkSortKeys            *self);
 gsize                   gtk_sort_keys_get_key_align             (GtkSortKeys            *self);
 GCompareDataFunc        gtk_sort_keys_get_key_compare_func      (GtkSortKeys            *self);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]