1/* gtktreemodel.h
2 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <[email protected]>
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, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __GTK_TREE_MODEL_H__
19#define __GTK_TREE_MODEL_H__
20
21#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
22#error "Only <gtk/gtk.h> can be included directly."
23#endif
24
25#include <glib-object.h>
26#include <gdk/gdk.h>
27
28G_BEGIN_DECLS
29
30#define GTK_TYPE_TREE_MODEL (gtk_tree_model_get_type ())
31#define GTK_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TREE_MODEL, GtkTreeModel))
32#define GTK_IS_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TREE_MODEL))
33#define GTK_TREE_MODEL_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_TREE_MODEL, GtkTreeModelIface))
34
35#define GTK_TYPE_TREE_ITER (gtk_tree_iter_get_type ())
36#define GTK_TYPE_TREE_PATH (gtk_tree_path_get_type ())
37#define GTK_TYPE_TREE_ROW_REFERENCE (gtk_tree_row_reference_get_type ())
38
39typedef struct _GtkTreeIter GtkTreeIter;
40typedef struct _GtkTreePath GtkTreePath;
41typedef struct _GtkTreeRowReference GtkTreeRowReference;
42typedef struct _GtkTreeModel GtkTreeModel; /* Dummy typedef */
43typedef struct _GtkTreeModelIface GtkTreeModelIface;
44
45/**
46 * GtkTreeModelForeachFunc:
47 * @model: the #GtkTreeModel being iterated
48 * @path: the current #GtkTreePath
49 * @iter: the current #GtkTreeIter
50 * @data: (closure): The user data passed to gtk_tree_model_foreach()
51 *
52 * Type of the callback passed to gtk_tree_model_foreach() to
53 * iterate over the rows in a tree model.
54 *
55 * Returns: %TRUE to stop iterating, %FALSE to continue
56 *
57 */
58typedef gboolean (* GtkTreeModelForeachFunc) (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
59
60/**
61 * GtkTreeModelFlags:
62 * @GTK_TREE_MODEL_ITERS_PERSIST: iterators survive all signals
63 * emitted by the tree
64 * @GTK_TREE_MODEL_LIST_ONLY: the model is a list only, and never
65 * has children
66 *
67 * These flags indicate various properties of a #GtkTreeModel.
68 *
69 * They are returned by gtk_tree_model_get_flags(), and must be
70 * static for the lifetime of the object. A more complete description
71 * of #GTK_TREE_MODEL_ITERS_PERSIST can be found in the overview of
72 * this section.
73 */
74typedef enum
75{
76 GTK_TREE_MODEL_ITERS_PERSIST = 1 << 0,
77 GTK_TREE_MODEL_LIST_ONLY = 1 << 1
78} GtkTreeModelFlags;
79
80/**
81 * GtkTreeIter:
82 * @stamp: a unique stamp to catch invalid iterators
83 * @user_data: model-specific data
84 * @user_data2: model-specific data
85 * @user_data3: model-specific data
86 *
87 * The #GtkTreeIter is the primary structure
88 * for accessing a #GtkTreeModel. Models are expected to put a unique
89 * integer in the @stamp member, and put
90 * model-specific data in the three @user_data
91 * members.
92 */
93struct _GtkTreeIter
94{
95 gint stamp;
96 gpointer user_data;
97 gpointer user_data2;
98 gpointer user_data3;
99};
100
101/**
102 * GtkTreeModelIface:
103 * @row_changed: Signal emitted when a row in the model has changed.
104 * @row_inserted: Signal emitted when a new row has been inserted in
105 * the model.
106 * @row_has_child_toggled: Signal emitted when a row has gotten the
107 * first child row or lost its last child row.
108 * @row_deleted: Signal emitted when a row has been deleted.
109 * @rows_reordered: Signal emitted when the children of a node in the
110 * GtkTreeModel have been reordered.
111 * @get_flags: Get #GtkTreeModelFlags supported by this interface.
112 * @get_n_columns: Get the number of columns supported by the model.
113 * @get_column_type: Get the type of the column.
114 * @get_iter: Sets iter to a valid iterator pointing to path.
115 * @get_path: Gets a newly-created #GtkTreePath referenced by iter.
116 * @get_value: Initializes and sets value to that at column.
117 * @iter_next: Sets iter to point to the node following it at the
118 * current level.
119 * @iter_previous: Sets iter to point to the previous node at the
120 * current level.
121 * @iter_children: Sets iter to point to the first child of parent.
122 * @iter_has_child: %TRUE if iter has children, %FALSE otherwise.
123 * @iter_n_children: Gets the number of children that iter has.
124 * @iter_nth_child: Sets iter to be the child of parent, using the
125 * given index.
126 * @iter_parent: Sets iter to be the parent of child.
127 * @ref_node: Lets the tree ref the node.
128 * @unref_node: Lets the tree unref the node.
129 */
130struct _GtkTreeModelIface
131{
132 /*< private >*/
133 GTypeInterface g_iface;
134
135 /*< public >*/
136
137 /* Signals */
138 void (* row_changed) (GtkTreeModel *tree_model,
139 GtkTreePath *path,
140 GtkTreeIter *iter);
141 void (* row_inserted) (GtkTreeModel *tree_model,
142 GtkTreePath *path,
143 GtkTreeIter *iter);
144 void (* row_has_child_toggled) (GtkTreeModel *tree_model,
145 GtkTreePath *path,
146 GtkTreeIter *iter);
147 void (* row_deleted) (GtkTreeModel *tree_model,
148 GtkTreePath *path);
149 void (* rows_reordered) (GtkTreeModel *tree_model,
150 GtkTreePath *path,
151 GtkTreeIter *iter,
152 gint *new_order);
153
154 /* Virtual Table */
155 GtkTreeModelFlags (* get_flags) (GtkTreeModel *tree_model);
156
157 gint (* get_n_columns) (GtkTreeModel *tree_model);
158 GType (* get_column_type) (GtkTreeModel *tree_model,
159 gint index_);
160 gboolean (* get_iter) (GtkTreeModel *tree_model,
161 GtkTreeIter *iter,
162 GtkTreePath *path);
163 GtkTreePath *(* get_path) (GtkTreeModel *tree_model,
164 GtkTreeIter *iter);
165 void (* get_value) (GtkTreeModel *tree_model,
166 GtkTreeIter *iter,
167 gint column,
168 GValue *value);
169 gboolean (* iter_next) (GtkTreeModel *tree_model,
170 GtkTreeIter *iter);
171 gboolean (* iter_previous) (GtkTreeModel *tree_model,
172 GtkTreeIter *iter);
173 gboolean (* iter_children) (GtkTreeModel *tree_model,
174 GtkTreeIter *iter,
175 GtkTreeIter *parent);
176 gboolean (* iter_has_child) (GtkTreeModel *tree_model,
177 GtkTreeIter *iter);
178 gint (* iter_n_children) (GtkTreeModel *tree_model,
179 GtkTreeIter *iter);
180 gboolean (* iter_nth_child) (GtkTreeModel *tree_model,
181 GtkTreeIter *iter,
182 GtkTreeIter *parent,
183 gint n);
184 gboolean (* iter_parent) (GtkTreeModel *tree_model,
185 GtkTreeIter *iter,
186 GtkTreeIter *child);
187 void (* ref_node) (GtkTreeModel *tree_model,
188 GtkTreeIter *iter);
189 void (* unref_node) (GtkTreeModel *tree_model,
190 GtkTreeIter *iter);
191};
192
193
194/* GtkTreePath operations */
195GDK_AVAILABLE_IN_ALL
196GtkTreePath *gtk_tree_path_new (void);
197GDK_AVAILABLE_IN_ALL
198GtkTreePath *gtk_tree_path_new_from_string (const gchar *path);
199GDK_AVAILABLE_IN_ALL
200GtkTreePath *gtk_tree_path_new_from_indices (gint first_index,
201 ...);
202GDK_AVAILABLE_IN_3_12
203GtkTreePath *gtk_tree_path_new_from_indicesv (gint *indices,
204 gsize length);
205GDK_AVAILABLE_IN_ALL
206gchar *gtk_tree_path_to_string (GtkTreePath *path);
207GDK_AVAILABLE_IN_ALL
208GtkTreePath *gtk_tree_path_new_first (void);
209GDK_AVAILABLE_IN_ALL
210void gtk_tree_path_append_index (GtkTreePath *path,
211 gint index_);
212GDK_AVAILABLE_IN_ALL
213void gtk_tree_path_prepend_index (GtkTreePath *path,
214 gint index_);
215GDK_AVAILABLE_IN_ALL
216gint gtk_tree_path_get_depth (GtkTreePath *path);
217GDK_AVAILABLE_IN_ALL
218gint *gtk_tree_path_get_indices (GtkTreePath *path);
219
220GDK_AVAILABLE_IN_ALL
221gint *gtk_tree_path_get_indices_with_depth (GtkTreePath *path,
222 gint *depth);
223
224GDK_AVAILABLE_IN_ALL
225void gtk_tree_path_free (GtkTreePath *path);
226GDK_AVAILABLE_IN_ALL
227GtkTreePath *gtk_tree_path_copy (const GtkTreePath *path);
228GDK_AVAILABLE_IN_ALL
229GType gtk_tree_path_get_type (void) G_GNUC_CONST;
230GDK_AVAILABLE_IN_ALL
231gint gtk_tree_path_compare (const GtkTreePath *a,
232 const GtkTreePath *b);
233GDK_AVAILABLE_IN_ALL
234void gtk_tree_path_next (GtkTreePath *path);
235GDK_AVAILABLE_IN_ALL
236gboolean gtk_tree_path_prev (GtkTreePath *path);
237GDK_AVAILABLE_IN_ALL
238gboolean gtk_tree_path_up (GtkTreePath *path);
239GDK_AVAILABLE_IN_ALL
240void gtk_tree_path_down (GtkTreePath *path);
241
242GDK_AVAILABLE_IN_ALL
243gboolean gtk_tree_path_is_ancestor (GtkTreePath *path,
244 GtkTreePath *descendant);
245GDK_AVAILABLE_IN_ALL
246gboolean gtk_tree_path_is_descendant (GtkTreePath *path,
247 GtkTreePath *ancestor);
248
249/**
250 * GtkTreeRowReference:
251 *
252 * A GtkTreeRowReference tracks model changes so that it always refers to the
253 * same row (a #GtkTreePath refers to a position, not a fixed row). Create a
254 * new GtkTreeRowReference with gtk_tree_row_reference_new().
255 */
256
257GDK_AVAILABLE_IN_ALL
258GType gtk_tree_row_reference_get_type (void) G_GNUC_CONST;
259GDK_AVAILABLE_IN_ALL
260GtkTreeRowReference *gtk_tree_row_reference_new (GtkTreeModel *model,
261 GtkTreePath *path);
262GDK_AVAILABLE_IN_ALL
263GtkTreeRowReference *gtk_tree_row_reference_new_proxy (GObject *proxy,
264 GtkTreeModel *model,
265 GtkTreePath *path);
266GDK_AVAILABLE_IN_ALL
267GtkTreePath *gtk_tree_row_reference_get_path (GtkTreeRowReference *reference);
268GDK_AVAILABLE_IN_ALL
269GtkTreeModel *gtk_tree_row_reference_get_model (GtkTreeRowReference *reference);
270GDK_AVAILABLE_IN_ALL
271gboolean gtk_tree_row_reference_valid (GtkTreeRowReference *reference);
272GDK_AVAILABLE_IN_ALL
273GtkTreeRowReference *gtk_tree_row_reference_copy (GtkTreeRowReference *reference);
274GDK_AVAILABLE_IN_ALL
275void gtk_tree_row_reference_free (GtkTreeRowReference *reference);
276/* These two functions are only needed if you created the row reference with a
277 * proxy object */
278GDK_AVAILABLE_IN_ALL
279void gtk_tree_row_reference_inserted (GObject *proxy,
280 GtkTreePath *path);
281GDK_AVAILABLE_IN_ALL
282void gtk_tree_row_reference_deleted (GObject *proxy,
283 GtkTreePath *path);
284GDK_AVAILABLE_IN_ALL
285void gtk_tree_row_reference_reordered (GObject *proxy,
286 GtkTreePath *path,
287 GtkTreeIter *iter,
288 gint *new_order);
289
290/* GtkTreeIter operations */
291GDK_AVAILABLE_IN_ALL
292GtkTreeIter * gtk_tree_iter_copy (GtkTreeIter *iter);
293GDK_AVAILABLE_IN_ALL
294void gtk_tree_iter_free (GtkTreeIter *iter);
295GDK_AVAILABLE_IN_ALL
296GType gtk_tree_iter_get_type (void) G_GNUC_CONST;
297
298GDK_AVAILABLE_IN_ALL
299GType gtk_tree_model_get_type (void) G_GNUC_CONST;
300GDK_AVAILABLE_IN_ALL
301GtkTreeModelFlags gtk_tree_model_get_flags (GtkTreeModel *tree_model);
302GDK_AVAILABLE_IN_ALL
303gint gtk_tree_model_get_n_columns (GtkTreeModel *tree_model);
304GDK_AVAILABLE_IN_ALL
305GType gtk_tree_model_get_column_type (GtkTreeModel *tree_model,
306 gint index_);
307
308
309/* Iterator movement */
310GDK_AVAILABLE_IN_ALL
311gboolean gtk_tree_model_get_iter (GtkTreeModel *tree_model,
312 GtkTreeIter *iter,
313 GtkTreePath *path);
314GDK_AVAILABLE_IN_ALL
315gboolean gtk_tree_model_get_iter_from_string (GtkTreeModel *tree_model,
316 GtkTreeIter *iter,
317 const gchar *path_string);
318GDK_AVAILABLE_IN_ALL
319gchar * gtk_tree_model_get_string_from_iter (GtkTreeModel *tree_model,
320 GtkTreeIter *iter);
321GDK_AVAILABLE_IN_ALL
322gboolean gtk_tree_model_get_iter_first (GtkTreeModel *tree_model,
323 GtkTreeIter *iter);
324GDK_AVAILABLE_IN_ALL
325GtkTreePath * gtk_tree_model_get_path (GtkTreeModel *tree_model,
326 GtkTreeIter *iter);
327GDK_AVAILABLE_IN_ALL
328void gtk_tree_model_get_value (GtkTreeModel *tree_model,
329 GtkTreeIter *iter,
330 gint column,
331 GValue *value);
332GDK_AVAILABLE_IN_ALL
333gboolean gtk_tree_model_iter_previous (GtkTreeModel *tree_model,
334 GtkTreeIter *iter);
335GDK_AVAILABLE_IN_ALL
336gboolean gtk_tree_model_iter_next (GtkTreeModel *tree_model,
337 GtkTreeIter *iter);
338GDK_AVAILABLE_IN_ALL
339gboolean gtk_tree_model_iter_children (GtkTreeModel *tree_model,
340 GtkTreeIter *iter,
341 GtkTreeIter *parent);
342GDK_AVAILABLE_IN_ALL
343gboolean gtk_tree_model_iter_has_child (GtkTreeModel *tree_model,
344 GtkTreeIter *iter);
345GDK_AVAILABLE_IN_ALL
346gint gtk_tree_model_iter_n_children (GtkTreeModel *tree_model,
347 GtkTreeIter *iter);
348GDK_AVAILABLE_IN_ALL
349gboolean gtk_tree_model_iter_nth_child (GtkTreeModel *tree_model,
350 GtkTreeIter *iter,
351 GtkTreeIter *parent,
352 gint n);
353GDK_AVAILABLE_IN_ALL
354gboolean gtk_tree_model_iter_parent (GtkTreeModel *tree_model,
355 GtkTreeIter *iter,
356 GtkTreeIter *child);
357GDK_AVAILABLE_IN_ALL
358void gtk_tree_model_ref_node (GtkTreeModel *tree_model,
359 GtkTreeIter *iter);
360GDK_AVAILABLE_IN_ALL
361void gtk_tree_model_unref_node (GtkTreeModel *tree_model,
362 GtkTreeIter *iter);
363GDK_AVAILABLE_IN_ALL
364void gtk_tree_model_get (GtkTreeModel *tree_model,
365 GtkTreeIter *iter,
366 ...);
367GDK_AVAILABLE_IN_ALL
368void gtk_tree_model_get_valist (GtkTreeModel *tree_model,
369 GtkTreeIter *iter,
370 va_list var_args);
371
372
373GDK_AVAILABLE_IN_ALL
374void gtk_tree_model_foreach (GtkTreeModel *model,
375 GtkTreeModelForeachFunc func,
376 gpointer user_data);
377
378/* Signals */
379GDK_AVAILABLE_IN_ALL
380void gtk_tree_model_row_changed (GtkTreeModel *tree_model,
381 GtkTreePath *path,
382 GtkTreeIter *iter);
383GDK_AVAILABLE_IN_ALL
384void gtk_tree_model_row_inserted (GtkTreeModel *tree_model,
385 GtkTreePath *path,
386 GtkTreeIter *iter);
387GDK_AVAILABLE_IN_ALL
388void gtk_tree_model_row_has_child_toggled (GtkTreeModel *tree_model,
389 GtkTreePath *path,
390 GtkTreeIter *iter);
391GDK_AVAILABLE_IN_ALL
392void gtk_tree_model_row_deleted (GtkTreeModel *tree_model,
393 GtkTreePath *path);
394GDK_AVAILABLE_IN_ALL
395void gtk_tree_model_rows_reordered (GtkTreeModel *tree_model,
396 GtkTreePath *path,
397 GtkTreeIter *iter,
398 gint *new_order);
399GDK_AVAILABLE_IN_3_10
400void gtk_tree_model_rows_reordered_with_length (GtkTreeModel *tree_model,
401 GtkTreePath *path,
402 GtkTreeIter *iter,
403 gint *new_order,
404 gint length);
405
406G_END_DECLS
407
408#endif /* __GTK_TREE_MODEL_H__ */
409