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;
66 g_signal_new (I_("sort_column_changed"),
67 GTK_TYPE_TREE_SORTABLE,
69 G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
71 _gtk_marshal_VOID__VOID,
78 * gtk_tree_sortable_sort_column_changed:
79 * @sortable: A #GtkTreeSortable
81 * Emits a GtkTreeSortable::sort_column_changed signal on
84 gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable)
86 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
88 g_signal_emit_by_name (sortable, "sort_column_changed");
92 * gtk_tree_sortable_get_sort_column_id:
93 * @sortable: A #GtkTreeSortable
94 * @sort_column_id: The sort column id to be filled in
95 * @order: The #GtkSortType to be filled in
97 * Fills in @sort_column_id and @order with the current sort column and the
98 * order. It returns %TRUE unless the @sort_column_id is
99 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID or
100 * %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID.
102 * Return value: %TRUE if the sort column is not one of the special sort
106 gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
107 gint *sort_column_id,
110 GtkTreeSortableIface *iface;
112 g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
114 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
116 g_return_val_if_fail (iface != NULL, FALSE);
117 g_return_val_if_fail (iface->get_sort_column_id != NULL, FALSE);
119 return (* iface->get_sort_column_id) (sortable, sort_column_id, order);
123 * gtk_tree_sortable_set_sort_column_id:
124 * @sortable: A #GtkTreeSortable
125 * @sort_column_id: the sort column id to set
126 * @order: The sort order of the column
128 * Sets the current sort column to be @sort_column_id. The @sortable will
129 * resort itself to reflect this change, after emitting a
130 * GtkTreeSortable::sort_column_changed signal. If @sort_column_id is
131 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the default sort function
132 * will be used, if it is set.
135 gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
139 GtkTreeSortableIface *iface;
141 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
143 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
145 g_return_if_fail (iface != NULL);
146 g_return_if_fail (iface->set_sort_column_id != NULL);
148 (* iface->set_sort_column_id) (sortable, sort_column_id, order);
152 * gtk_tree_sortable_set_sort_func:
153 * @sortable: A #GtkTreeSortable
154 * @sort_column_id: the sort column id to set the function for
155 * @sort_func: The comparison function
156 * @user_data: User data to pass to @sort_func, or %NULL
157 * @destroy: Destroy notifier of @user_data, or %NULL
159 * Sets the comparison function used when sorting to be @sort_func. If the
160 * current sort column id of @sortable is the same as @sort_column_id, then the
161 * model will sort using this function.
164 gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
166 GtkTreeIterCompareFunc sort_func,
168 GDestroyNotify destroy)
170 GtkTreeSortableIface *iface;
172 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
173 g_return_if_fail (sort_func != NULL);
175 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
177 g_return_if_fail (iface != NULL);
178 g_return_if_fail (iface->set_sort_func != NULL);
179 g_return_if_fail (sort_column_id >= 0);
181 (* iface->set_sort_func) (sortable, sort_column_id, sort_func, user_data, destroy);
185 * gtk_tree_sortable_set_default_sort_func:
186 * @sortable: A #GtkTreeSortable
187 * @sort_func: The comparison function
188 * @user_data: User data to pass to @sort_func, or %NULL
189 * @destroy: Destroy notifier of @user_data, or %NULL
191 * Sets the default comparison function used when sorting to be @sort_func.
192 * If the current sort column id of @sortable is
193 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using
196 * If @sort_func is %NULL, then there will be no default comparison function.
197 * This means that once the model has been sorted, it can't go back to the
198 * default state. In this case, when the current sort column id of @sortable is
199 * GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted.
202 gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable,
203 GtkTreeIterCompareFunc sort_func,
205 GDestroyNotify destroy)
207 GtkTreeSortableIface *iface;
209 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
211 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
213 g_return_if_fail (iface != NULL);
214 g_return_if_fail (iface->set_default_sort_func != NULL);
216 (* iface->set_default_sort_func) (sortable, sort_func, user_data, destroy);
220 * gtk_tree_sortable_has_default_sort_func:
221 * @sortable: A #GtkTreeSortable
223 * Returns %TRUE if the model has a default sort function. This is used
224 * primarily by GtkTreeViewColumns in order to determine if a model can go back
225 * to the default state, or not.
227 * Return value: %TRUE, if the model has a default sort function
230 gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
232 GtkTreeSortableIface *iface;
234 g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
236 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
238 g_return_val_if_fail (iface != NULL, FALSE);
239 g_return_val_if_fail (iface->has_default_sort_func != NULL, FALSE);
241 return (* iface->has_default_sort_func) (sortable);
244 #define __GTK_TREE_SORTABLE_C__
245 #include "gtkaliasdef.c"