gtktreesortable.h 6.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* gtktreesortable.h
 * Copyright (C) 2001  Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20
 */

#ifndef __GTK_TREE_SORTABLE_H__
#define __GTK_TREE_SORTABLE_H__

21

22 23 24 25
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif

26
#include <gtk/gtkenums.h>
27 28
#include <gtk/gtktreemodel.h>

29

30
G_BEGIN_DECLS
31 32 33

#define GTK_TYPE_TREE_SORTABLE            (gtk_tree_sortable_get_type ())
#define GTK_TREE_SORTABLE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TREE_SORTABLE, GtkTreeSortable))
34
#define GTK_TREE_SORTABLE_CLASS(obj)      (G_TYPE_CHECK_CLASS_CAST ((obj), GTK_TYPE_TREE_SORTABLE, GtkTreeSortableIface))
35
#define GTK_IS_TREE_SORTABLE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TREE_SORTABLE))
36
#define GTK_TREE_SORTABLE_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_TREE_SORTABLE, GtkTreeSortableIface))
37

38 39 40 41 42 43 44 45
/**
 * GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID:
 *
 * The GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID can be used to make a
 * #GtkTreeSortable use the default sort function.
 *
 * See also gtk_tree_sortable_set_sort_column_id()
 */
46
#define GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID (-1)
47 48 49 50 51 52 53 54 55

/**
 * GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID:
 *
 * The GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID can be used to make a
 * #GtkTreeSortable use no sorting.
 *
 * See also gtk_tree_sortable_set_sort_column_id()
 */
56
#define GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID (-2)
57

58 59 60
typedef struct _GtkTreeSortable      GtkTreeSortable; /* Dummy typedef */
typedef struct _GtkTreeSortableIface GtkTreeSortableIface;

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
/**
 * GtkTreeIterCompareFunc:
 * @model: The #GtkTreeModel the comparison is within
 * @a: A #GtkTreeIter in @model
 * @b: Another #GtkTreeIter in @model
 * @user_data: Data passed when the compare func is assigned e.g. by
 *  gtk_tree_sortable_set_sort_func()
 *
 * A GtkTreeIterCompareFunc should return a negative integer, zero, or a positive
 * integer if @a sorts before @b, @a sorts with @b, or @a sorts after @b
 * respectively. If two iters compare as equal, their order in the sorted model
 * is undefined. In order to ensure that the #GtkTreeSortable behaves as
 * expected, the GtkTreeIterCompareFunc must define a partial order on
 * the model, i.e. it must be reflexive, antisymmetric and transitive.
 *
 * For example, if @model is a product catalogue, then a compare function
77
 * for the “price” column could be one which returns
78
 * `price_of(@a) - price_of(@b)`.
79 80 81 82
 *
 * Returns: a negative integer, zero or a positive integer depending on whether
 *   @a sorts before, with or after @b
 */
83 84 85 86 87 88
typedef gint (* GtkTreeIterCompareFunc) (GtkTreeModel *model,
					 GtkTreeIter  *a,
					 GtkTreeIter  *b,
					 gpointer      user_data);


89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
/**
 * GtkTreeSortableIface:
 * @sort_column_changed: Signal emitted when the sort column or sort
 *    order of sortable is changed.
 * @get_sort_column_id: Fills in sort_column_id and order with the
 *    current sort column and the order.
 * @set_sort_column_id: Sets the current sort column to be
 *    sort_column_id.
 * @set_sort_func: Sets the comparison function used when sorting to
 *    be sort_func.
 * @set_default_sort_func: Sets the default comparison function used
 *    when sorting to be sort_func.
 * @has_default_sort_func: %TRUE if the model has a default sort
 * function.
 */
104 105
struct _GtkTreeSortableIface
{
106
  /*< private >*/
107 108
  GTypeInterface g_iface;

109 110
  /*< public >*/

111
  /* signals */
112
  void     (* sort_column_changed)   (GtkTreeSortable        *sortable);
113 114

  /* virtual table */
115 116 117 118 119 120 121 122
  gboolean (* get_sort_column_id)    (GtkTreeSortable        *sortable,
				      gint                   *sort_column_id,
				      GtkSortType            *order);
  void     (* set_sort_column_id)    (GtkTreeSortable        *sortable,
				      gint                    sort_column_id,
				      GtkSortType             order);
  void     (* set_sort_func)         (GtkTreeSortable        *sortable,
				      gint                    sort_column_id,
123 124
				      GtkTreeIterCompareFunc  sort_func,
				      gpointer                user_data,
125
				      GDestroyNotify          destroy);
126
  void     (* set_default_sort_func) (GtkTreeSortable        *sortable,
127 128
				      GtkTreeIterCompareFunc  sort_func,
				      gpointer                user_data,
129
				      GDestroyNotify          destroy);
130
  gboolean (* has_default_sort_func) (GtkTreeSortable        *sortable);
131 132 133
};


134
GDK_AVAILABLE_IN_ALL
135 136
GType    gtk_tree_sortable_get_type              (void) G_GNUC_CONST;

137
GDK_AVAILABLE_IN_ALL
138
void     gtk_tree_sortable_sort_column_changed   (GtkTreeSortable        *sortable);
139
GDK_AVAILABLE_IN_ALL
140 141 142
gboolean gtk_tree_sortable_get_sort_column_id    (GtkTreeSortable        *sortable,
						  gint                   *sort_column_id,
						  GtkSortType            *order);
143
GDK_AVAILABLE_IN_ALL
144 145 146
void     gtk_tree_sortable_set_sort_column_id    (GtkTreeSortable        *sortable,
						  gint                    sort_column_id,
						  GtkSortType             order);
147
GDK_AVAILABLE_IN_ALL
148 149
void     gtk_tree_sortable_set_sort_func         (GtkTreeSortable        *sortable,
						  gint                    sort_column_id,
150 151
						  GtkTreeIterCompareFunc  sort_func,
						  gpointer                user_data,
152
						  GDestroyNotify          destroy);
153
GDK_AVAILABLE_IN_ALL
154
void     gtk_tree_sortable_set_default_sort_func (GtkTreeSortable        *sortable,
155 156
						  GtkTreeIterCompareFunc  sort_func,
						  gpointer                user_data,
157
						  GDestroyNotify          destroy);
158
GDK_AVAILABLE_IN_ALL
159
gboolean gtk_tree_sortable_has_default_sort_func (GtkTreeSortable        *sortable);
160

161
G_END_DECLS
162 163

#endif /* __GTK_TREE_SORTABLE_H__ */