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 "gtkmarshalers.h"
23 #include "gtksignal.h"
25 static void gtk_tree_sortable_base_init (gpointer g_class);
28 gtk_tree_sortable_get_type (void)
30 static GtkType tree_sortable_type = 0;
32 if (! tree_sortable_type)
34 static const GTypeInfo tree_sortable_info =
36 sizeof (GtkTreeSortableIface), /* class_size */
37 gtk_tree_sortable_base_init, /* base_init */
38 NULL, /* base_finalize */
40 NULL, /* class_finalize */
41 NULL, /* class_data */
46 tree_sortable_type = g_type_register_static (G_TYPE_INTERFACE, "GtkTreeSortable", &tree_sortable_info, 0);
47 g_type_interface_add_prerequisite (tree_sortable_type, GTK_TYPE_TREE_MODEL);
50 return tree_sortable_type;
54 gtk_tree_sortable_base_init (gpointer g_class)
56 static gboolean initialized = FALSE;
60 g_signal_new ("sort_column_changed",
61 GTK_TYPE_TREE_SORTABLE,
63 G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
65 _gtk_marshal_VOID__VOID,
72 * gtk_tree_sortable_sort_column_changed:
73 * @sortable: A #GtkTreeSortable
75 * Emits a GtkTreeSortable::sort_column_changed signal on
78 gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable)
80 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
82 g_signal_emit_by_name (G_OBJECT (sortable),
83 "sort_column_changed");
87 * gtk_tree_sortable_get_sort_column_id:
88 * @sortable: A #GtkTreeSortable
89 * @sort_column_id: The sort column id to be filled in
90 * @order: The #GtkSortType to be filled in
92 * Fills in @sort_column_id and @order with the current sort column and the
93 * order, if applicable. If the sort column is not set, then FALSE is returned,
94 * and the values in @sort_column_id and @order are unchanged.
96 * Return value: %TRUE, if the sort column has been set
99 gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
100 gint *sort_column_id,
103 GtkTreeSortableIface *iface;
105 g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
107 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
109 g_return_val_if_fail (iface != NULL, FALSE);
110 g_return_val_if_fail (iface->get_sort_column_id != NULL, FALSE);
112 return (* iface->get_sort_column_id) (sortable, sort_column_id, order);
116 * gtk_tree_sortable_set_sort_column_id:
117 * @sortable: A #GtkTreeSortable
118 * @sort_column_id: the sort column id to set
119 * @order: The sort order of the column
121 * Sets the current sort column to be @sort_column_id. The @sortable will
122 * resort itself to reflect this change, after emitting a
123 * GtkTreeSortable::sort_column_changed signal. If @sort_column_id is
124 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the default sort function
125 * will be used, if it is set.
128 gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
132 GtkTreeSortableIface *iface;
134 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
136 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
138 g_return_if_fail (iface != NULL);
139 g_return_if_fail (iface->set_sort_column_id != NULL);
141 (* iface->set_sort_column_id) (sortable, sort_column_id, order);
145 * gtk_tree_sortable_set_sort_func:
146 * @sortable: A #GtkTreeSortable
147 * @sort_column_id: the sort column id to set the function for
148 * @sort_func: The sorting function
149 * @user_data: User data to pass to the sort func, or %NULL
150 * @destroy: Destroy notifier of @user_data, or %NULL
152 * Sets the comparison function used when sorting to be @sort_func. If the
153 * current sort column id of @sortable is the same as @sort_column_id, then the
157 gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
159 GtkTreeIterCompareFunc sort_func,
161 GtkDestroyNotify destroy)
163 GtkTreeSortableIface *iface;
165 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
167 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
169 g_return_if_fail (iface != NULL);
170 g_return_if_fail (iface->set_sort_func != NULL);
171 g_return_if_fail (sort_column_id > 0);
173 (* iface->set_sort_func) (sortable, sort_column_id, sort_func, user_data, destroy);
177 * gtk_tree_sortable_set_default_sort_func:
178 * @sortable: A #GtkTreeSortable
179 * @sort_func: The sorting function
180 * @user_data: User data to pass to the sort func, or %NULL
181 * @destroy: Destroy notifier of @user_data, or %NULL
183 * Sets the default comparison function used when sorting to be @sort_func. If
184 * the current sort column id of @sortable is
185 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort. If
186 * @sort_func is %NULL, then the default sort_func, and there will be no default
187 * sort_func. In this case, the model is unsorted.
190 gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable,
191 GtkTreeIterCompareFunc sort_func,
193 GtkDestroyNotify destroy)
195 GtkTreeSortableIface *iface;
197 g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
199 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
201 g_return_if_fail (iface != NULL);
202 g_return_if_fail (iface->set_default_sort_func != NULL);
204 (* iface->set_default_sort_func) (sortable, sort_func, user_data, destroy);
208 * gtk_tree_sortable_has_default_sort_func:
209 * @sortable: A #GtkTreeSortable
211 * Returns %TRUE if the model has a default sort function. This is used
212 * primarily by GtkTreeViewColumns in order to determine if a model can go back
213 * to the default state, or not.
215 * Return value: %TRUE, if the model has a default sort function
218 gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
220 GtkTreeSortableIface *iface;
222 g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
224 iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
226 g_return_val_if_fail (iface != NULL, FALSE);
227 g_return_val_if_fail (iface->has_default_sort_func != NULL, FALSE);
229 return (* iface->has_default_sort_func) (sortable);