1 | /* |
2 | * Copyright © 2019 Matthias Clasen |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2.1 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | * |
17 | * Authors: Matthias Clasen <mclasen@redhat.com> |
18 | */ |
19 | |
20 | #ifndef __GTK_SORTER_H__ |
21 | #define __GTK_SORTER_H__ |
22 | |
23 | #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) |
24 | #error "Only <gtk/gtk.h> can be included directly." |
25 | #endif |
26 | |
27 | #include <gdk/gdk.h> |
28 | #include <gtk/gtkenums.h> |
29 | |
30 | G_BEGIN_DECLS |
31 | |
32 | /** |
33 | * GtkSorterOrder: |
34 | * @GTK_SORTER_ORDER_PARTIAL: A partial order. Any `GtkOrdering` is possible. |
35 | * @GTK_SORTER_ORDER_NONE: No order, all elements are considered equal. |
36 | * gtk_sorter_compare() will only return %GTK_ORDERING_EQUAL. |
37 | * @GTK_SORTER_ORDER_TOTAL: A total order. gtk_sorter_compare() will only |
38 | * return %GTK_ORDERING_EQUAL if an item is compared with itself. Two |
39 | * different items will never cause this value to be returned. |
40 | * |
41 | * Describes the type of order that a `GtkSorter` may produce. |
42 | */ |
43 | typedef enum { |
44 | GTK_SORTER_ORDER_PARTIAL, |
45 | GTK_SORTER_ORDER_NONE, |
46 | GTK_SORTER_ORDER_TOTAL |
47 | } GtkSorterOrder; |
48 | |
49 | /** |
50 | * GtkSorterChange: |
51 | * @GTK_SORTER_CHANGE_DIFFERENT: The sorter change cannot be described |
52 | * by any of the other enumeration values |
53 | * @GTK_SORTER_CHANGE_INVERTED: The sort order was inverted. Comparisons |
54 | * that returned %GTK_ORDERING_SMALLER now return %GTK_ORDERING_LARGER |
55 | * and vice versa. Other comparisons return the same values as before. |
56 | * @GTK_SORTER_CHANGE_LESS_STRICT: The sorter is less strict: Comparisons |
57 | * may now return %GTK_ORDERING_EQUAL that did not do so before. |
58 | * @GTK_SORTER_CHANGE_MORE_STRICT: The sorter is more strict: Comparisons |
59 | * that did return %GTK_ORDERING_EQUAL may not do so anymore. |
60 | * |
61 | * Describes changes in a sorter in more detail and allows users |
62 | * to optimize resorting. |
63 | */ |
64 | typedef enum { |
65 | GTK_SORTER_CHANGE_DIFFERENT, |
66 | GTK_SORTER_CHANGE_INVERTED, |
67 | GTK_SORTER_CHANGE_LESS_STRICT, |
68 | GTK_SORTER_CHANGE_MORE_STRICT |
69 | } GtkSorterChange; |
70 | |
71 | #define GTK_TYPE_SORTER (gtk_sorter_get_type ()) |
72 | |
73 | GDK_AVAILABLE_IN_ALL |
74 | G_DECLARE_DERIVABLE_TYPE (GtkSorter, gtk_sorter, GTK, SORTER, GObject) |
75 | |
76 | /** |
77 | * GtkSorterClass |
78 | * @compare: Compare two items. See gtk_sorter_compare() for details. |
79 | * @get_order: Get the `GtkSorderOrder` that applies to the current sorter. |
80 | * If unimplemented, it returns %GTK_SORTER_ORDER_PARTIAL. |
81 | * |
82 | * The virtual table for `GtkSorter`. |
83 | */ |
84 | struct _GtkSorterClass |
85 | { |
86 | GObjectClass parent_class; |
87 | |
88 | GtkOrdering (* compare) (GtkSorter *self, |
89 | gpointer item1, |
90 | gpointer item2); |
91 | |
92 | /* optional */ |
93 | GtkSorterOrder (* get_order) (GtkSorter *self); |
94 | |
95 | /* Padding for future expansion */ |
96 | void (*_gtk_reserved1) (void); |
97 | void (*_gtk_reserved2) (void); |
98 | void (*_gtk_reserved3) (void); |
99 | void (*_gtk_reserved4) (void); |
100 | void (*_gtk_reserved5) (void); |
101 | void (*_gtk_reserved6) (void); |
102 | void (*_gtk_reserved7) (void); |
103 | void (*_gtk_reserved8) (void); |
104 | }; |
105 | |
106 | GDK_AVAILABLE_IN_ALL |
107 | GtkOrdering gtk_sorter_compare (GtkSorter *self, |
108 | gpointer item1, |
109 | gpointer item2); |
110 | GDK_AVAILABLE_IN_ALL |
111 | GtkSorterOrder gtk_sorter_get_order (GtkSorter *self); |
112 | |
113 | /* for sorter implementations */ |
114 | GDK_AVAILABLE_IN_ALL |
115 | void gtk_sorter_changed (GtkSorter *self, |
116 | GtkSorterChange change); |
117 | |
118 | |
119 | G_END_DECLS |
120 | |
121 | #endif /* __GTK_SORTER_H__ */ |
122 | |
123 | |