]> Pileus Git - ~andy/gtk/blob - gtk/gtktreesortable.c
Make PLT-reduction work with gcc4, and don't include everything in
[~andy/gtk] / gtk / gtktreesortable.c
1 /* gtktreesortable.c
2  * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20
21 #include <config.h>
22 #include "gtktreesortable.h"
23 #include "gtkmarshalers.h"
24 #include "gtkalias.h"
25
26 static void gtk_tree_sortable_base_init (gpointer g_class);
27
28 GType
29 gtk_tree_sortable_get_type (void)
30 {
31   static GType tree_sortable_type = 0;
32
33   if (! tree_sortable_type)
34     {
35       static const GTypeInfo tree_sortable_info =
36       {
37         sizeof (GtkTreeSortableIface), /* class_size */
38         gtk_tree_sortable_base_init,   /* base_init */
39         NULL,           /* base_finalize */
40         NULL,
41         NULL,           /* class_finalize */
42         NULL,           /* class_data */
43         0,
44         0,
45         NULL
46       };
47
48       tree_sortable_type =
49         g_type_register_static (G_TYPE_INTERFACE, "GtkTreeSortable",
50                                 &tree_sortable_info, 0);
51
52       g_type_interface_add_prerequisite (tree_sortable_type, GTK_TYPE_TREE_MODEL);
53     }
54
55   return tree_sortable_type;
56 }
57
58 static void
59 gtk_tree_sortable_base_init (gpointer g_class)
60 {
61   static gboolean initialized = FALSE;
62
63   if (! initialized)
64     {
65       g_signal_new ("sort_column_changed",
66                     GTK_TYPE_TREE_SORTABLE,
67                     G_SIGNAL_RUN_LAST,
68                     G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
69                     NULL, NULL,
70                     _gtk_marshal_VOID__VOID,
71                     G_TYPE_NONE, 0);
72       initialized = TRUE;
73     }
74 }
75
76 /**
77  * gtk_tree_sortable_sort_column_changed:
78  * @sortable: A #GtkTreeSortable
79  * 
80  * Emits a GtkTreeSortable::sort_column_changed signal on 
81  **/
82 void
83 gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable)
84 {
85   g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
86
87   g_signal_emit_by_name (sortable, "sort_column_changed");
88 }
89
90 /**
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
95  * 
96  * Fills in @sort_column_id and @order with the current sort column and the
97  * order.  It returns %TRUE unless the @sort_column_id is 
98  * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID or 
99  * %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID.
100  * 
101  * Return value: %TRUE if the sort column is not one of the special sort
102  *   column ids.
103  **/
104 gboolean
105 gtk_tree_sortable_get_sort_column_id (GtkTreeSortable  *sortable,
106                                       gint             *sort_column_id,
107                                       GtkSortType      *order)
108 {
109   GtkTreeSortableIface *iface;
110
111   g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
112
113   iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
114
115   g_return_val_if_fail (iface != NULL, FALSE);
116   g_return_val_if_fail (iface->get_sort_column_id != NULL, FALSE);
117
118   return (* iface->get_sort_column_id) (sortable, sort_column_id, order);
119 }
120
121 /**
122  * gtk_tree_sortable_set_sort_column_id:
123  * @sortable: A #GtkTreeSortable
124  * @sort_column_id: the sort column id to set
125  * @order: The sort order of the column
126  * 
127  * Sets the current sort column to be @sort_column_id.  The @sortable will
128  * resort itself to reflect this change, after emitting a
129  * GtkTreeSortable::sort_column_changed signal.  If @sort_column_id is
130  * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the default sort function
131  * will be used, if it is set.
132  **/
133 void
134 gtk_tree_sortable_set_sort_column_id (GtkTreeSortable  *sortable,
135                                       gint              sort_column_id,
136                                       GtkSortType       order)
137 {
138   GtkTreeSortableIface *iface;
139
140   g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
141
142   iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
143
144   g_return_if_fail (iface != NULL);
145   g_return_if_fail (iface->set_sort_column_id != NULL);
146   
147   (* iface->set_sort_column_id) (sortable, sort_column_id, order);
148 }
149
150 /**
151  * gtk_tree_sortable_set_sort_func:
152  * @sortable: A #GtkTreeSortable
153  * @sort_column_id: the sort column id to set the function for
154  * @sort_func: The sorting function
155  * @user_data: User data to pass to the sort func, or %NULL
156  * @destroy: Destroy notifier of @user_data, or %NULL
157  * 
158  * Sets the comparison function used when sorting to be @sort_func.  If the
159  * current sort column id of @sortable is the same as @sort_column_id, then the
160  * model will sort using this function.
161  **/
162 void
163 gtk_tree_sortable_set_sort_func (GtkTreeSortable        *sortable,
164                                  gint                    sort_column_id,
165                                  GtkTreeIterCompareFunc  sort_func,
166                                  gpointer                user_data,
167                                  GtkDestroyNotify        destroy)
168 {
169   GtkTreeSortableIface *iface;
170
171   g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
172
173   iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
174
175   g_return_if_fail (iface != NULL);
176   g_return_if_fail (iface->set_sort_func != NULL);
177   g_return_if_fail (sort_column_id >= 0);
178
179   (* iface->set_sort_func) (sortable, sort_column_id, sort_func, user_data, destroy);
180 }
181
182 /**
183  * gtk_tree_sortable_set_default_sort_func:
184  * @sortable: A #GtkTreeSortable
185  * @sort_func: The sorting function
186  * @user_data: User data to pass to the sort func, or %NULL
187  * @destroy: Destroy notifier of @user_data, or %NULL
188  * 
189  * Sets the default comparison function used when sorting to be @sort_func.  If
190  * the current sort column id of @sortable is
191  * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using this function.
192  *
193  * If @sort_func is %NULL, then there will be no default comparison function.
194  * This means that once the model  has been sorted, it can't go back to the
195  * default state. In this case, when the current sort column id of @sortable is
196  * GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted.
197  **/
198 void
199 gtk_tree_sortable_set_default_sort_func (GtkTreeSortable        *sortable,
200                                          GtkTreeIterCompareFunc  sort_func,
201                                          gpointer                user_data,
202                                          GtkDestroyNotify        destroy)
203 {
204   GtkTreeSortableIface *iface;
205
206   g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
207
208   iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
209
210   g_return_if_fail (iface != NULL);
211   g_return_if_fail (iface->set_default_sort_func != NULL);
212   
213   (* iface->set_default_sort_func) (sortable, sort_func, user_data, destroy);
214 }
215
216 /**
217  * gtk_tree_sortable_has_default_sort_func:
218  * @sortable: A #GtkTreeSortable
219  * 
220  * Returns %TRUE if the model has a default sort function.  This is used
221  * primarily by GtkTreeViewColumns in order to determine if a model can go back
222  * to the default state, or not.
223  * 
224  * Return value: %TRUE, if the model has a default sort function
225  **/
226 gboolean
227 gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
228 {
229   GtkTreeSortableIface *iface;
230
231   g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
232
233   iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
234
235   g_return_val_if_fail (iface != NULL, FALSE);
236   g_return_val_if_fail (iface->has_default_sort_func != NULL, FALSE);
237   
238   return (* iface->has_default_sort_func) (sortable);
239 }
240
241 #define __GTK_TREE_SORTABLE_C__
242 #include "gtkaliasdef.c"