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.
23 #include "gtktreesortable.h"
24 #include "gtkmarshalers.h"
26 static void gtk_tree_sortable_base_init (gpointer g_class);
29 gtk_tree_sortable_get_type (void)
31 static GType tree_sortable_type = 0;
33 if (! tree_sortable_type)
35 static const GTypeInfo tree_sortable_info =
37 sizeof (GtkTreeSortableIface), /* class_size */
38 gtk_tree_sortable_base_init, /* base_init */
39 NULL, /* base_finalize */
41 NULL, /* class_finalize */
42 NULL, /* class_data */
49 g_type_register_static (G_TYPE_INTERFACE, "GtkTreeSortable",
50 &tree_sortable_info, 0);
52 g_type_interface_add_prerequisite (tree_sortable_type, GTK_TYPE_TREE_MODEL);
55 return tree_sortable_type;
59 gtk_tree_sortable_base_init (gpointer g_class)
61 static gboolean initialized = FALSE;
65 g_signal_new ("sort_column_changed",
66 GTK_TYPE_TREE_SORTABLE,
68 G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
70 _gtk_marshal_VOID__VOID,
77 * gtk_tree_sortable_sort_column_changed:
78 * @sortable: A #GtkTreeSortable
80 * Emits a GtkTreeSortable::sort_column_changed signal on
83 gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable)
85 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
87 g_signal_emit_by_name (sortable, "sort_column_changed");
91 * gtk_tree_sortable_get_sort_column_id:
92 * @sortable: A #GtkTreeSortable
93 * @sort_column_id: The sort column id to be filled in
94 * @order: The #GtkSortType to be filled in
96 * Fills in @sort_column_id and @order with the current sort column and the
97 * order, if applicable. If the sort column is not set, then FALSE is returned,
98 * and the values in @sort_column_id and @order are unchanged.
100 * Return value: %TRUE, if the sort column has been set
103 gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
104 gint *sort_column_id,
107 GtkTreeSortableIface *iface;
109 g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
111 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
113 g_return_val_if_fail (iface != NULL, FALSE);
114 g_return_val_if_fail (iface->get_sort_column_id != NULL, FALSE);
116 return (* iface->get_sort_column_id) (sortable, sort_column_id, order);
120 * gtk_tree_sortable_set_sort_column_id:
121 * @sortable: A #GtkTreeSortable
122 * @sort_column_id: the sort column id to set
123 * @order: The sort order of the column
125 * Sets the current sort column to be @sort_column_id. The @sortable will
126 * resort itself to reflect this change, after emitting a
127 * GtkTreeSortable::sort_column_changed signal. If @sort_column_id is
128 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the default sort function
129 * will be used, if it is set.
132 gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
136 GtkTreeSortableIface *iface;
138 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
140 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
142 g_return_if_fail (iface != NULL);
143 g_return_if_fail (iface->set_sort_column_id != NULL);
145 (* iface->set_sort_column_id) (sortable, sort_column_id, order);
149 * gtk_tree_sortable_set_sort_func:
150 * @sortable: A #GtkTreeSortable
151 * @sort_column_id: the sort column id to set the function for
152 * @sort_func: The sorting function
153 * @user_data: User data to pass to the sort func, or %NULL
154 * @destroy: Destroy notifier of @user_data, or %NULL
156 * Sets the comparison function used when sorting to be @sort_func. If the
157 * current sort column id of @sortable is the same as @sort_column_id, then the
158 * model will sort using this function.
161 gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
163 GtkTreeIterCompareFunc sort_func,
165 GtkDestroyNotify destroy)
167 GtkTreeSortableIface *iface;
169 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
171 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
173 g_return_if_fail (iface != NULL);
174 g_return_if_fail (iface->set_sort_func != NULL);
175 g_return_if_fail (sort_column_id >= 0);
177 (* iface->set_sort_func) (sortable, sort_column_id, sort_func, user_data, destroy);
181 * gtk_tree_sortable_set_default_sort_func:
182 * @sortable: A #GtkTreeSortable
183 * @sort_func: The sorting function
184 * @user_data: User data to pass to the sort func, or %NULL
185 * @destroy: Destroy notifier of @user_data, or %NULL
187 * Sets the default comparison function used when sorting to be @sort_func. If
188 * the current sort column id of @sortable is
189 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using this function.
191 * If @sort_func is %NULL, then there will be no default comparison function.
192 * This means that once the model has been sorted, it can't go back to the
193 * default state. In this case, when the current sort column id of @sortable is
194 * GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted.
197 gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable,
198 GtkTreeIterCompareFunc sort_func,
200 GtkDestroyNotify destroy)
202 GtkTreeSortableIface *iface;
204 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
206 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
208 g_return_if_fail (iface != NULL);
209 g_return_if_fail (iface->set_default_sort_func != NULL);
211 (* iface->set_default_sort_func) (sortable, sort_func, user_data, destroy);
215 * gtk_tree_sortable_has_default_sort_func:
216 * @sortable: A #GtkTreeSortable
218 * Returns %TRUE if the model has a default sort function. This is used
219 * primarily by GtkTreeViewColumns in order to determine if a model can go back
220 * to the default state, or not.
222 * Return value: %TRUE, if the model has a default sort function
225 gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
227 GtkTreeSortableIface *iface;
229 g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
231 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
233 g_return_val_if_fail (iface != NULL, FALSE);
234 g_return_val_if_fail (iface->has_default_sort_func != NULL, FALSE);
236 return (* iface->has_default_sort_func) (sortable);