1 | /* gtktreesortable.h |
2 | * Copyright (C) 2001 Red Hat, Inc. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 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 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #ifndef __GTK_TREE_SORTABLE_H__ |
19 | #define __GTK_TREE_SORTABLE_H__ |
20 | |
21 | |
22 | #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) |
23 | #error "Only <gtk/gtk.h> can be included directly." |
24 | #endif |
25 | |
26 | #include <gtk/gtkenums.h> |
27 | #include <gtk/gtktreemodel.h> |
28 | |
29 | |
30 | G_BEGIN_DECLS |
31 | |
32 | #define GTK_TYPE_TREE_SORTABLE (gtk_tree_sortable_get_type ()) |
33 | #define GTK_TREE_SORTABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TREE_SORTABLE, GtkTreeSortable)) |
34 | #define GTK_IS_TREE_SORTABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TREE_SORTABLE)) |
35 | #define GTK_TREE_SORTABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_TREE_SORTABLE, GtkTreeSortableIface)) |
36 | |
37 | /** |
38 | * GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID: |
39 | * |
40 | * Uses the default sort function in a [iface@Gtk.TreeSortable]. |
41 | * |
42 | * See also: [method@Gtk.TreeSortable.set_sort_column_id] |
43 | */ |
44 | #define GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID (-1) |
45 | |
46 | /** |
47 | * GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID: |
48 | * |
49 | * Disables sorting in a [iface@Gtk.TreeSortable]. |
50 | * |
51 | * See also: [method@Gtk.TreeSortable.set_sort_column_id] |
52 | */ |
53 | #define GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID (-2) |
54 | |
55 | typedef struct _GtkTreeSortable GtkTreeSortable; /* Dummy typedef */ |
56 | typedef struct _GtkTreeSortableIface GtkTreeSortableIface; |
57 | |
58 | /** |
59 | * GtkTreeIterCompareFunc: |
60 | * @model: The `GtkTreeModel` the comparison is within |
61 | * @a: A `GtkTreeIter` in @model |
62 | * @b: Another `GtkTreeIter` in @model |
63 | * @user_data: Data passed when the compare func is assigned e.g. by |
64 | * gtk_tree_sortable_set_sort_func() |
65 | * |
66 | * A GtkTreeIterCompareFunc should return a negative integer, zero, or a positive |
67 | * integer if @a sorts before @b, @a sorts with @b, or @a sorts after @b |
68 | * respectively. |
69 | * |
70 | * If two iters compare as equal, their order in the sorted model |
71 | * is undefined. In order to ensure that the `GtkTreeSortable` behaves as |
72 | * expected, the GtkTreeIterCompareFunc must define a partial order on |
73 | * the model, i.e. it must be reflexive, antisymmetric and transitive. |
74 | * |
75 | * For example, if @model is a product catalogue, then a compare function |
76 | * for the “price” column could be one which returns |
77 | * `price_of(@a) - price_of(@b)`. |
78 | * |
79 | * Returns: a negative integer, zero or a positive integer depending on whether |
80 | * @a sorts before, with or after @b |
81 | */ |
82 | typedef int (* GtkTreeIterCompareFunc) (GtkTreeModel *model, |
83 | GtkTreeIter *a, |
84 | GtkTreeIter *b, |
85 | gpointer user_data); |
86 | |
87 | |
88 | /** |
89 | * GtkTreeSortableIface: |
90 | * @sort_column_changed: Signal emitted when the sort column or sort |
91 | * order of sortable is changed. |
92 | * @get_sort_column_id: Fills in sort_column_id and order with the |
93 | * current sort column and the order. |
94 | * @set_sort_column_id: Sets the current sort column to be |
95 | * sort_column_id. |
96 | * @set_sort_func: Sets the comparison function used when sorting to |
97 | * be sort_func. |
98 | * @set_default_sort_func: Sets the default comparison function used |
99 | * when sorting to be sort_func. |
100 | * @has_default_sort_func: %TRUE if the model has a default sort |
101 | * function. |
102 | */ |
103 | struct _GtkTreeSortableIface |
104 | { |
105 | /*< private >*/ |
106 | GTypeInterface g_iface; |
107 | |
108 | /*< public >*/ |
109 | |
110 | /* signals */ |
111 | void (* sort_column_changed) (GtkTreeSortable *sortable); |
112 | |
113 | /* virtual table */ |
114 | gboolean (* get_sort_column_id) (GtkTreeSortable *sortable, |
115 | int *sort_column_id, |
116 | GtkSortType *order); |
117 | void (* set_sort_column_id) (GtkTreeSortable *sortable, |
118 | int sort_column_id, |
119 | GtkSortType order); |
120 | void (* set_sort_func) (GtkTreeSortable *sortable, |
121 | int sort_column_id, |
122 | GtkTreeIterCompareFunc sort_func, |
123 | gpointer user_data, |
124 | GDestroyNotify destroy); |
125 | void (* set_default_sort_func) (GtkTreeSortable *sortable, |
126 | GtkTreeIterCompareFunc sort_func, |
127 | gpointer user_data, |
128 | GDestroyNotify destroy); |
129 | gboolean (* has_default_sort_func) (GtkTreeSortable *sortable); |
130 | }; |
131 | |
132 | |
133 | GDK_AVAILABLE_IN_ALL |
134 | GType gtk_tree_sortable_get_type (void) G_GNUC_CONST; |
135 | |
136 | GDK_AVAILABLE_IN_ALL |
137 | void gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable); |
138 | GDK_AVAILABLE_IN_ALL |
139 | gboolean gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable, |
140 | int *sort_column_id, |
141 | GtkSortType *order); |
142 | GDK_AVAILABLE_IN_ALL |
143 | void gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable, |
144 | int sort_column_id, |
145 | GtkSortType order); |
146 | GDK_AVAILABLE_IN_ALL |
147 | void gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable, |
148 | int sort_column_id, |
149 | GtkTreeIterCompareFunc sort_func, |
150 | gpointer user_data, |
151 | GDestroyNotify destroy); |
152 | GDK_AVAILABLE_IN_ALL |
153 | void gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable, |
154 | GtkTreeIterCompareFunc sort_func, |
155 | gpointer user_data, |
156 | GDestroyNotify destroy); |
157 | GDK_AVAILABLE_IN_ALL |
158 | gboolean gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable); |
159 | |
160 | G_END_DECLS |
161 | |
162 | #endif /* __GTK_TREE_SORTABLE_H__ */ |
163 | |