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.
21 #include "gtktreesortable.h"
22 #include "gtksignal.h"
24 static void gtk_tree_sortable_base_init (gpointer g_class);
27 gtk_tree_sortable_get_type (void)
29 static GtkType tree_sortable_type = 0;
31 if (! tree_sortable_type)
33 static const GTypeInfo tree_sortable_info =
35 sizeof (GtkTreeSortableIface), /* class_size */
36 gtk_tree_sortable_base_init, /* base_init */
37 NULL, /* base_finalize */
39 NULL, /* class_finalize */
40 NULL, /* class_data */
45 tree_sortable_type = g_type_register_static (G_TYPE_INTERFACE, "GtkTreeSortable", &tree_sortable_info, 0);
46 g_type_interface_add_prerequisite (tree_sortable_type, G_TYPE_OBJECT);
49 return tree_sortable_type;
53 gtk_tree_sortable_base_init (gpointer g_class)
55 static gboolean initialized = FALSE;
59 g_signal_new ("sort_column_changed",
60 GTK_TYPE_TREE_SORTABLE,
62 G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
64 gtk_marshal_VOID__VOID,
71 * gtk_tree_sortable_sort_column_changed:
72 * @sortable: A #GtkTreeSortable
74 * Emits a GtkTreeSortable::sort_column_changed signal on
77 gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable)
79 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
81 g_signal_emit_by_name (G_OBJECT (sortable),
82 "sort_column_changed");
86 * gtk_tree_sortable_get_sort_column_id:
87 * @sortable: A #GtkTreeSortable
88 * @sort_column_id: The sort column id to be filled in
89 * @order: The #GtkSortType to be filled in
91 * Fills in @sort_column_id and @order with the current sort column and the
92 * order, if applicable. If the sort column is not set, then FALSE is returned,
93 * and the values in @sort_column_id and @order are unchanged.
95 * Return value: %TRUE, if the sort column has been set
98 gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
102 GtkTreeSortableIface *iface;
104 g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
106 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
108 g_return_val_if_fail (iface != NULL, FALSE);
109 g_return_val_if_fail (iface->get_sort_column_id != NULL, FALSE);
111 return (* iface->get_sort_column_id) (sortable, sort_column_id, order);
115 * gtk_tree_sortable_set_sort_column_id:
116 * @sortable: A #GtkTreeSortable
117 * @sort_column_id: the sort column id to set
118 * @order: The sort order of the column
120 * Sets the current sort column to be @sort_column_id. The @sortable will
121 * resort itself to reflect this change, after emitting a
122 * GtkTreeSortable::sort_column_changed signal. If @sort_column_id is -1, then
123 * the default sort function will be used, if it is set.
126 gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
130 GtkTreeSortableIface *iface;
132 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
134 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
136 g_return_if_fail (iface != NULL);
137 g_return_if_fail (iface->set_sort_column_id != NULL);
139 (* iface->set_sort_column_id) (sortable, sort_column_id, order);
144 * gtk_tree_sortable_set_sort_func:
145 * @sortable: A #GtkTreeSortable
146 * @sort_column_id: the sort column id to set the function for
147 * @sort_func: The sorting function
148 * @user_data: User data to pass to the sort func, or %NULL
149 * @destroy: Destroy notifier of @user_data, or %NULL
151 * Sets the comparison function used when sorting to be @sort_func. If the
152 * current sort column id of @sortable is the same as @sort_column_id, then the
156 gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
158 GtkTreeIterCompareFunc sort_func,
160 GtkDestroyNotify destroy)
162 GtkTreeSortableIface *iface;
164 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
166 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
168 g_return_if_fail (iface != NULL);
169 g_return_if_fail (iface->set_sort_func != NULL);
171 (* iface->set_sort_func) (sortable, sort_column_id, sort_func, user_data, destroy);
175 * gtk_tree_sortable_set_default_sort_func:
176 * @sortable: A #GtkTreeSortable
177 * @sort_func: The sorting function
178 * @user_data: User data to pass to the sort func, or %NULL
179 * @destroy: Destroy notifier of @user_data, or %NULL
181 * Sets the default comparison function used when sorting to be @sort_func. If
182 * the current sort column id of @sortable is the same as @sort_column_id, then
183 * the model will sort.
186 gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable,
187 GtkTreeIterCompareFunc sort_func,
189 GtkDestroyNotify destroy)
191 GtkTreeSortableIface *iface;
193 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
195 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
197 g_return_if_fail (iface != NULL);
198 g_return_if_fail (iface->set_default_sort_func != NULL);
200 (* iface->set_default_sort_func) (sortable, sort_func, user_data, destroy);
204 * gtk_tree_sortable_has_default_sort_func:
205 * @sortable: A #GtkTreeSortable
207 * Returns %TRUE if the model has a default sort function. This is used
208 * primarily by GtkTreeViewColumns in order to determine if a model can go back
209 * to the default state, or not.
211 * Return value: %TRUE, if the model has a default sort function
214 gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
216 GtkTreeSortableIface *iface;
218 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
220 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
222 g_return_if_fail (iface != NULL);
223 g_return_if_fail (iface->has_default_sort_func != NULL);
225 (* iface->has_default_sort_func) (sortable);