]> Pileus Git - ~andy/gtk/blob - gtk/gtktreesortable.c
Patch from Matthias Clasen to remove remove all instances of
[~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 "gtktreesortable.h"
22 #include "gtksignal.h"
23
24 static void gtk_tree_sortable_base_init (gpointer g_class);
25
26 GtkType
27 gtk_tree_sortable_get_type (void)
28 {
29   static GtkType tree_sortable_type = 0;
30
31   if (! tree_sortable_type)
32     {
33       static const GTypeInfo tree_sortable_info =
34       {
35         sizeof (GtkTreeSortableIface), /* class_size */
36         gtk_tree_sortable_base_init,   /* base_init */
37         NULL,           /* base_finalize */
38         NULL,
39         NULL,           /* class_finalize */
40         NULL,           /* class_data */
41         0,
42         0,
43         NULL
44       };
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);
47     }
48
49   return tree_sortable_type;
50 }
51
52 static void
53 gtk_tree_sortable_base_init (gpointer g_class)
54 {
55   static gboolean initialized = FALSE;
56
57   if (! initialized)
58     {
59       g_signal_new ("sort_column_changed",
60                     GTK_TYPE_TREE_SORTABLE,
61                     G_SIGNAL_RUN_LAST,
62                     G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
63                     NULL, NULL,
64                     gtk_marshal_VOID__VOID,
65                     G_TYPE_NONE, 0);
66       initialized = TRUE;
67     }
68 }
69
70 void
71 gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable)
72 {
73   g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
74
75   g_signal_emit_by_name (G_OBJECT (sortable),
76                          "sort_column_changed");
77 }
78
79 gboolean
80 gtk_tree_sortable_get_sort_column_id (GtkTreeSortable  *sortable,
81                                       gint             *sort_column_id,
82                                       GtkTreeSortOrder *order)
83 {
84   GtkTreeSortableIface *iface;
85
86   g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
87
88   iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
89
90   g_return_val_if_fail (iface != NULL, FALSE);
91   g_return_val_if_fail (iface->get_sort_column_id != NULL, FALSE);
92
93   return (* iface->get_sort_column_id) (sortable, sort_column_id, order);
94 }
95
96 void
97 gtk_tree_sortable_set_sort_column_id (GtkTreeSortable  *sortable,
98                                       gint              sort_column_id,
99                                       GtkTreeSortOrder  order)
100 {
101   GtkTreeSortableIface *iface;
102
103   g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
104
105   iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
106
107   g_return_if_fail (iface != NULL);
108   g_return_if_fail (iface->set_sort_column_id != NULL);
109   
110   (* iface->set_sort_column_id) (sortable, sort_column_id, order);
111
112 }
113
114 void
115 gtk_tree_sortable_set_sort_func (GtkTreeSortable        *sortable,
116                                  gint                    sort_column_id,
117                                  GtkTreeIterCompareFunc  func,
118                                  gpointer                data,
119                                  GtkDestroyNotify        destroy)
120 {
121   GtkTreeSortableIface *iface;
122
123   g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
124
125   iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
126
127   g_return_if_fail (iface != NULL);
128   g_return_if_fail (iface->set_sort_func != NULL);
129   
130   (* iface->set_sort_func) (sortable, sort_column_id, func, data, destroy);
131 }
132
133