2 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
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.
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.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "gtktreesortable.h"
23 #include "gtkmarshalers.h"
27 static void gtk_tree_sortable_base_init (gpointer g_class);
30 gtk_tree_sortable_get_type (void)
32 static GType tree_sortable_type = 0;
34 if (! tree_sortable_type)
36 const GTypeInfo tree_sortable_info =
38 sizeof (GtkTreeSortableIface), /* class_size */
39 gtk_tree_sortable_base_init, /* base_init */
40 NULL, /* base_finalize */
42 NULL, /* class_finalize */
43 NULL, /* class_data */
50 g_type_register_static (G_TYPE_INTERFACE, I_("GtkTreeSortable"),
51 &tree_sortable_info, 0);
53 g_type_interface_add_prerequisite (tree_sortable_type, GTK_TYPE_TREE_MODEL);
56 return tree_sortable_type;
60 gtk_tree_sortable_base_init (gpointer g_class)
62 static gboolean initialized = FALSE;
67 * GtkTreeSortable::sort-column-changed:
68 * @sortable: the object on which the signal is emitted
70 * The ::sort-column-changed signal is emitted when the sort column
71 * or sort order of @sortable is changed. The signal is emitted before
72 * the contents of @sortable are resorted.
74 g_signal_new (I_("sort-column-changed"),
75 GTK_TYPE_TREE_SORTABLE,
77 G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
79 _gtk_marshal_VOID__VOID,
86 * gtk_tree_sortable_sort_column_changed:
87 * @sortable: A #GtkTreeSortable
89 * Emits a #GtkTreeSortable::sort-column-changed signal on @sortable.
92 gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable)
94 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
96 g_signal_emit_by_name (sortable, "sort-column-changed");
100 * gtk_tree_sortable_get_sort_column_id:
101 * @sortable: A #GtkTreeSortable
102 * @sort_column_id: The sort column id to be filled in
103 * @order: The #GtkSortType to be filled in
105 * Fills in @sort_column_id and @order with the current sort column and the
106 * order. It returns %TRUE unless the @sort_column_id is
107 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID or
108 * %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID.
110 * Return value: %TRUE if the sort column is not one of the special sort
114 gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
115 gint *sort_column_id,
118 GtkTreeSortableIface *iface;
120 g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
122 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
124 g_return_val_if_fail (iface != NULL, FALSE);
125 g_return_val_if_fail (iface->get_sort_column_id != NULL, FALSE);
127 return (* iface->get_sort_column_id) (sortable, sort_column_id, order);
131 * gtk_tree_sortable_set_sort_column_id:
132 * @sortable: A #GtkTreeSortable
133 * @sort_column_id: the sort column id to set
134 * @order: The sort order of the column
136 * Sets the current sort column to be @sort_column_id. The @sortable will
137 * resort itself to reflect this change, after emitting a
138 * #GtkTreeSortable::sort-column-changed signal. @sort_column_id may either be
139 * a regular column id, or one of the following special values:
142 * <term>%GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID</term>
143 * <listitem>the default sort function will be used, if it is set</listitem>
146 * <term>%GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID</term>
147 * <listitem>no sorting will occur</listitem>
152 gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
156 GtkTreeSortableIface *iface;
158 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
160 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
162 g_return_if_fail (iface != NULL);
163 g_return_if_fail (iface->set_sort_column_id != NULL);
165 (* iface->set_sort_column_id) (sortable, sort_column_id, order);
169 * gtk_tree_sortable_set_sort_func:
170 * @sortable: A #GtkTreeSortable
171 * @sort_column_id: the sort column id to set the function for
172 * @sort_func: The comparison function
173 * @user_data: (allow-none): User data to pass to @sort_func, or %NULL
174 * @destroy: (allow-none): Destroy notifier of @user_data, or %NULL
176 * Sets the comparison function used when sorting to be @sort_func. If the
177 * current sort column id of @sortable is the same as @sort_column_id, then
178 * the model will sort using this function.
181 gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
183 GtkTreeIterCompareFunc sort_func,
185 GDestroyNotify destroy)
187 GtkTreeSortableIface *iface;
189 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
190 g_return_if_fail (sort_func != NULL);
192 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
194 g_return_if_fail (iface != NULL);
195 g_return_if_fail (iface->set_sort_func != NULL);
196 g_return_if_fail (sort_column_id >= 0);
198 (* iface->set_sort_func) (sortable, sort_column_id, sort_func, user_data, destroy);
202 * gtk_tree_sortable_set_default_sort_func:
203 * @sortable: A #GtkTreeSortable
204 * @sort_func: The comparison function
205 * @user_data: (allow-none): User data to pass to @sort_func, or %NULL
206 * @destroy: (allow-none): Destroy notifier of @user_data, or %NULL
208 * Sets the default comparison function used when sorting to be @sort_func.
209 * If the current sort column id of @sortable is
210 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using
213 * If @sort_func is %NULL, then there will be no default comparison function.
214 * This means that once the model has been sorted, it can't go back to the
215 * default state. In this case, when the current sort column id of @sortable
216 * is %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted.
219 gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable,
220 GtkTreeIterCompareFunc sort_func,
222 GDestroyNotify destroy)
224 GtkTreeSortableIface *iface;
226 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
228 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
230 g_return_if_fail (iface != NULL);
231 g_return_if_fail (iface->set_default_sort_func != NULL);
233 (* iface->set_default_sort_func) (sortable, sort_func, user_data, destroy);
237 * gtk_tree_sortable_has_default_sort_func:
238 * @sortable: A #GtkTreeSortable
240 * Returns %TRUE if the model has a default sort function. This is used
241 * primarily by GtkTreeViewColumns in order to determine if a model can
242 * go back to the default state, or not.
244 * Return value: %TRUE, if the model has a default sort function
247 gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
249 GtkTreeSortableIface *iface;
251 g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
253 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
255 g_return_val_if_fail (iface != NULL, FALSE);
256 g_return_val_if_fail (iface->has_default_sort_func != NULL, FALSE);
258 return (* iface->has_default_sort_func) (sortable);