1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = 
27  * outPack = gtk
28  * outFile = TreeModelIF
29  * strct   = GtkTreeModel
30  * realStrct=
31  * ctorStrct=
32  * clss    = TreeModelT
33  * interf  = TreeModelIF
34  * class Code: Yes
35  * interface Code: Yes
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_tree_model_
41  * omit structs:
42  * 	- GtkTreeIter
43  * omit prefixes:
44  * 	- gtk_tree_row_reference_
45  * 	- gtk_tree_path_
46  * 	- gtk_tree_iter_
47  * omit code:
48  * 	- gtk_tree_model_get_value
49  * 	- gtk_tree_model_get_iter
50  * omit signals:
51  * imports:
52  * 	- glib.Str
53  * 	- gobject.Value
54  * 	- gtk.TreeIter
55  * 	- gtk.TreePath
56  * structWrap:
57  * 	- GValue* -> Value
58  * 	- GtkTreeIter* -> TreeIter
59  * 	- GtkTreePath* -> TreePath
60  * module aliases:
61  * local aliases:
62  * overrides:
63  */
64 
65 module gtk.TreeModelIF;
66 
67 public  import gtkc.gtktypes;
68 
69 private import gtkc.gtk;
70 private import glib.ConstructionException;
71 private import gobject.ObjectG;
72 
73 private import gobject.Signals;
74 public  import gtkc.gdktypes;
75 private import glib.Str;
76 private import gobject.Value;
77 private import gtk.TreeIter;
78 private import gtk.TreePath;
79 
80 
81 
82 /**
83  * The GtkTreeModel interface defines a generic tree interface for
84  * use by the GtkTreeView widget. It is an abstract interface, and
85  * is designed to be usable with any appropriate data structure. The
86  * programmer just has to implement this interface on their own data
87  * type for it to be viewable by a GtkTreeView widget.
88  *
89  * The model is represented as a hierarchical tree of strongly-typed,
90  * columned data. In other words, the model can be seen as a tree where
91  * every node has different values depending on which column is being
92  * queried. The type of data found in a column is determined by using
93  * the GType system (ie. G_TYPE_INT, GTK_TYPE_BUTTON, G_TYPE_POINTER,
94  * etc). The types are homogeneous per column across all nodes. It is
95  * important to note that this interface only provides a way of examining
96  * a model and observing changes. The implementation of each individual
97  * model decides how and if changes are made.
98  *
99  * In order to make life simpler for programmers who do not need to
100  * write their own specialized model, two generic models are provided
101  * — the GtkTreeStore and the GtkListStore. To use these, the
102  * developer simply pushes data into these models as necessary. These
103  * models provide the data structure as well as all appropriate tree
104  * interfaces. As a result, implementing drag and drop, sorting, and
105  * storing data is trivial. For the vast majority of trees and lists,
106  * these two models are sufficient.
107  *
108  * Models are accessed on a node/column level of granularity. One can
109  * query for the value of a model at a certain node and a certain
110  * column on that node. There are two structures used to reference
111  * a particular node in a model. They are the GtkTreePath and the
112  * GtkTreeIter[4]. Most of the interface
113  * consists of operations on a GtkTreeIter.
114  *
115  * A path is essentially a potential node. It is a location on a model
116  * that may or may not actually correspond to a node on a specific
117  * model. The GtkTreePath struct can be converted into either an
118  * array of unsigned integers or a string. The string form is a list
119  * of numbers separated by a colon. Each number refers to the offset
120  * at that level. Thus, the path “0” refers to the root
121  * node and the path “2:4” refers to the fifth child of
122  * the third node.
123  *
124  * By contrast, a GtkTreeIter is a reference to a specific node on
125  * a specific model. It is a generic struct with an integer and three
126  * generic pointers. These are filled in by the model in a model-specific
127  * way. One can convert a path to an iterator by calling
128  * gtk_tree_model_get_iter(). These iterators are the primary way
129  * of accessing a model and are similar to the iterators used by
130  * GtkTextBuffer. They are generally statically allocated on the
131  * stack and only used for a short time. The model interface defines
132  * a set of operations using them for navigating the model.
133  *
134  * It is expected that models fill in the iterator with private data.
135  * For example, the GtkListStore model, which is internally a simple
136  * linked list, stores a list node in one of the pointers. The
137  * GtkTreeModelSort stores an array and an offset in two of the
138  * pointers. Additionally, there is an integer field. This field is
139  * generally filled with a unique stamp per model. This stamp is for
140  * catching errors resulting from using invalid iterators with a model.
141  *
142  * The lifecycle of an iterator can be a little confusing at first.
143  * Iterators are expected to always be valid for as long as the model
144  * is unchanged (and doesn't emit a signal). The model is considered
145  * to own all outstanding iterators and nothing needs to be done to
146  * free them from the user's point of view. Additionally, some models
147  * guarantee that an iterator is valid for as long as the node it refers
148  * to is valid (most notably the GtkTreeStore and GtkListStore).
149  * Although generally uninteresting, as one always has to allow for
150  * the case where iterators do not persist beyond a signal, some very
151  * important performance enhancements were made in the sort model.
152  * As a result, the GTK_TREE_MODEL_ITERS_PERSIST flag was added to
153  * indicate this behavior.
154  *
155  * To help show some common operation of a model, some examples are
156  * provided. The first example shows three ways of getting the iter at
157  * the location “3:2:5”. While the first method shown is
158  * easier, the second is much more common, as you often get paths from
159  * callbacks.
160  *
161  * $(DDOC_COMMENT example)
162  *
163  * This second example shows a quick way of iterating through a list
164  * and getting a string and an integer from each row. The
165  * populate_model function used below is not
166  * shown, as it is specific to the GtkListStore. For information on
167  * how to write such a function, see the GtkListStore documentation.
168  *
169  * $(DDOC_COMMENT example)
170  *
171  * The GtkTreeModel interface contains two methods for reference
172  * counting: gtk_tree_model_ref_node() and gtk_tree_model_unref_node().
173  * These two methods are optional to implement. The reference counting
174  * is meant as a way for views to let models know when nodes are being
175  * displayed. GtkTreeView will take a reference on a node when it is
176  * visible, which means the node is either in the toplevel or expanded.
177  * Being displayed does not mean that the node is currently directly
178  * visible to the user in the viewport. Based on this reference counting
179  * scheme a caching model, for example, can decide whether or not to cache
180  * a node based on the reference count. A file-system based model would
181  * not want to keep the entire file hierarchy in memory, but just the
182  * folders that are currently expanded in every current view.
183  *
184  * When working with reference counting, the following rules must be taken
185  * into account:
186  *
187  * Never take a reference on a node without owning a
188  * reference on its parent. This means that all parent nodes of a referenced
189  * node must be referenced as well.
190  *
191  * Outstanding references on a deleted node are not released.
192  * This is not possible because the node has already been deleted by the
193  * time the row-deleted signal is received.
194  *
195  * Models are not obligated to emit a signal on rows of
196  * which none of its siblings are referenced. To phrase this differently,
197  * signals are only required for levels in which nodes are referenced. For
198  * the root level however, signals must be emitted at all times (however the
199  * root level is always referenced when any view is attached).
200  */
201 public interface TreeModelIF
202 {
203 	
204 	
205 	/** Get the main Gtk struct */
206 	public GtkTreeModel* getTreeModelTStruct();
207 	
208 	/** the main Gtk struct as a void* */
209 	protected void* getStruct();
210 	
211 	
212 	/**
213 	 * Get the value of a column as a char array.
214 	 * this is the same calling getValue and get the string from the value object
215 	 */
216 	string getValueString(TreeIter iter, int column);
217 	
218 	/**
219 	 * Get the value of a column as a char array.
220 	 * this is the same calling getValue and get the int from the value object
221 	 */
222 	int getValueInt(TreeIter iter, int column);
223 	
224 	/**
225 	 * Sets iter to a valid iterator pointing to path.
226 	 * Params:
227 	 *  iter = The uninitialized GtkTreeIter.
228 	 *  path = The GtkTreePath.
229 	 * Returns:
230 	 *  TRUE, if iter was set.
231 	 */
232 	public int getIter(TreeIter iter, TreePath path);
233 	
234 	/**
235 	 * Initializes and sets value to that at column.
236 	 * When done with value, g_value_unset() needs to be called
237 	 * to free any allocated memory.
238 	 * Params:
239 	 * iter = The GtkTreeIter.
240 	 * column = The column to lookup the value at.
241 	 * value = (inout) (transfer none) An empty GValue to set.
242 	 */
243 	public Value getValue(TreeIter iter, int column, Value value = null);
244 	
245 	/**
246 	 */
247 	
248 	@property void delegate(TreePath, TreeIter, TreeModelIF)[] onRowChangedListeners();
249 	/**
250 	 * This signal is emitted when a row in the model has changed.
251 	 */
252 	void addOnRowChanged(void delegate(TreePath, TreeIter, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
253 	@property void delegate(TreePath, TreeModelIF)[] onRowDeletedListeners();
254 	/**
255 	 * This signal is emitted when a row has been deleted.
256 	 * Note that no iterator is passed to the signal handler,
257 	 * since the row is already deleted.
258 	 * This should be called by models after a row has been removed.
259 	 * The location pointed to by path should be the location that
260 	 * the row previously was at. It may not be a valid location anymore.
261 	 */
262 	void addOnRowDeleted(void delegate(TreePath, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
263 	@property void delegate(TreePath, TreeIter, TreeModelIF)[] onRowHasChildToggledListeners();
264 	/**
265 	 * This signal is emitted when a row has gotten the first child
266 	 * row or lost its last child row.
267 	 */
268 	void addOnRowHasChildToggled(void delegate(TreePath, TreeIter, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
269 	@property void delegate(TreePath, TreeIter, TreeModelIF)[] onRowInsertedListeners();
270 	/**
271 	 * This signal is emitted when a new row has been inserted in
272 	 * the model.
273 	 * Note that the row may still be empty at this point, since
274 	 * it is a common pattern to first insert an empty row, and
275 	 * then fill it with the desired values.
276 	 */
277 	void addOnRowInserted(void delegate(TreePath, TreeIter, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
278 	@property void delegate(TreePath, TreeIter, void*, TreeModelIF)[] onRowsReorderedListeners();
279 	/**
280 	 * This signal is emitted when the children of a node in the
281 	 * GtkTreeModel have been reordered.
282 	 * Note that this signal is not emitted
283 	 * when rows are reordered by DND, since this is implemented
284 	 * by removing and then reinserting the row.
285 	 * See Also
286 	 * GtkTreeView, GtkTreeStore, GtkListStore,
287 	 *  GtkTreeDnd,
288 	 *  GtkTreeSortable
289 	 * [4] Here, iter is short
290 	 * for “iterator”
291 	 */
292 	void addOnRowsReordered(void delegate(TreePath, TreeIter, void*, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
293 	
294 	/**
295 	 * Returns a set of flags supported by this interface.
296 	 * The flags are a bitwise combination of GtkTreeModelFlags.
297 	 * The flags supported should not change during the lifetime
298 	 * of the tree_model.
299 	 * Returns: the flags supported by this interface
300 	 */
301 	public GtkTreeModelFlags getFlags();
302 	
303 	/**
304 	 * Returns the number of columns supported by tree_model.
305 	 * Returns: the number of columns
306 	 */
307 	public int getNColumns();
308 	
309 	/**
310 	 * Returns the type of the column.
311 	 * Params:
312 	 * index = the column index
313 	 * Returns: the type of the column. [transfer none]
314 	 */
315 	public GType getColumnType(int index);
316 	
317 	/**
318 	 * Sets iter to a valid iterator pointing to path_string, if it
319 	 * exists. Otherwise, iter is left invalid and FALSE is returned.
320 	 * Params:
321 	 * iter = an uninitialized GtkTreeIter. [out]
322 	 * pathString = a string representation of a GtkTreePath
323 	 * Returns: TRUE, if iter was set
324 	 */
325 	public int getIterFromString(TreeIter iter, string pathString);
326 	
327 	/**
328 	 * Initializes iter with the first iterator in the tree
329 	 * (the one at the path "0") and returns TRUE. Returns
330 	 * FALSE if the tree is empty.
331 	 * Params:
332 	 * iter = the uninitialized GtkTreeIter. [out]
333 	 * Returns: TRUE, if iter was set
334 	 */
335 	public int getIterFirst(TreeIter iter);
336 	
337 	/**
338 	 * Returns a newly-created GtkTreePath referenced by iter.
339 	 * This path should be freed with gtk_tree_path_free().
340 	 * Params:
341 	 * iter = the GtkTreeIter
342 	 * Returns: a newly-created GtkTreePath
343 	 */
344 	public TreePath getPath(TreeIter iter);
345 	
346 	/**
347 	 * Sets iter to point to the node following it at the current level.
348 	 * If there is no next iter, FALSE is returned and iter is set
349 	 * to be invalid.
350 	 * Params:
351 	 * iter = the GtkTreeIter. [in]
352 	 * Returns: TRUE if iter has been changed to the next node
353 	 */
354 	public int iterNext(TreeIter iter);
355 	
356 	/**
357 	 * Sets iter to point to the previous node at the current level.
358 	 * If there is no previous iter, FALSE is returned and iter is
359 	 * set to be invalid.
360 	 * Params:
361 	 * iter = the GtkTreeIter. [in]
362 	 * Returns: TRUE if iter has been changed to the previous node Since 3.0
363 	 */
364 	public int iterPrevious(TreeIter iter);
365 	
366 	/**
367 	 * Sets iter to point to the first child of parent.
368 	 * If parent has no children, FALSE is returned and iter is
369 	 * set to be invalid. parent will remain a valid node after this
370 	 * function has been called.
371 	 * If parent is NULL returns the first node, equivalent to
372 	 * gtk_tree_model_get_iter_first (tree_model, iter);
373 	 * Params:
374 	 * iter = the new GtkTreeIter to be set to the child. [out]
375 	 * parent = the GtkTreeIter, or NULL. [allow-none]
376 	 * Returns: TRUE, if child has been set to the first child
377 	 */
378 	public int iterChildren(TreeIter iter, TreeIter parent);
379 	
380 	/**
381 	 * Returns TRUE if iter has children, FALSE otherwise.
382 	 * Params:
383 	 * iter = the GtkTreeIter to test for children
384 	 * Returns: TRUE if iter has children
385 	 */
386 	public int iterHasChild(TreeIter iter);
387 	
388 	/**
389 	 * Returns the number of children that iter has.
390 	 * As a special case, if iter is NULL, then the number
391 	 * of toplevel nodes is returned.
392 	 * Params:
393 	 * iter = the GtkTreeIter, or NULL. [allow-none]
394 	 * Returns: the number of children of iter
395 	 */
396 	public int iterNChildren(TreeIter iter);
397 	
398 	/**
399 	 * Sets iter to be the child of parent, using the given index.
400 	 * The first index is 0. If n is too big, or parent has no children,
401 	 * iter is set to an invalid iterator and FALSE is returned. parent
402 	 * will remain a valid node after this function has been called. As a
403 	 * special case, if parent is NULL, then the nth root node
404 	 * is set.
405 	 * Params:
406 	 * iter = the GtkTreeIter to set to the nth child. [out]
407 	 * parent = the GtkTreeIter to get the child from, or NULL. [allow-none]
408 	 * n = the index of the desired child
409 	 * Returns: TRUE, if parent has an nth child
410 	 */
411 	public int iterNthChild(TreeIter iter, TreeIter parent, int n);
412 	
413 	/**
414 	 * Sets iter to be the parent of child.
415 	 * If child is at the toplevel, and doesn't have a parent, then
416 	 * iter is set to an invalid iterator and FALSE is returned.
417 	 * child will remain a valid node after this function has been
418 	 * called.
419 	 * Params:
420 	 * iter = the new GtkTreeIter to set to the parent. [out]
421 	 * child = the GtkTreeIter
422 	 * Returns: TRUE, if iter is set to the parent of child
423 	 */
424 	public int iterParent(TreeIter iter, TreeIter child);
425 	
426 	/**
427 	 * Generates a string representation of the iter.
428 	 * This string is a ':' separated list of numbers.
429 	 * For example, "4:10:0:3" would be an acceptable
430 	 * return value for this string.
431 	 * Since 2.2
432 	 * Params:
433 	 * iter = a GtkTreeIter
434 	 * Returns: a newly-allocated string. Must be freed with g_free().
435 	 */
436 	public string getStringFromIter(TreeIter iter);
437 	
438 	/**
439 	 * Lets the tree ref the node.
440 	 * This is an optional method for models to implement.
441 	 * To be more specific, models may ignore this call as it exists
442 	 * primarily for performance reasons.
443 	 * This function is primarily meant as a way for views to let
444 	 * caching models know when nodes are being displayed (and hence,
445 	 * whether or not to cache that node). Being displayed means a node
446 	 * is in an expanded branch, regardless of whether the node is currently
447 	 * visible in the viewport. For example, a file-system based model
448 	 * would not want to keep the entire file-hierarchy in memory,
449 	 * just the sections that are currently being displayed by
450 	 * every current view.
451 	 * A model should be expected to be able to get an iter independent
452 	 * of its reffed state.
453 	 * Params:
454 	 * iter = the GtkTreeIter
455 	 */
456 	public void refNode(TreeIter iter);
457 	
458 	/**
459 	 * Lets the tree unref the node.
460 	 * This is an optional method for models to implement.
461 	 * To be more specific, models may ignore this call as it exists
462 	 * primarily for performance reasons. For more information on what
463 	 * this means, see gtk_tree_model_ref_node().
464 	 * Please note that nodes that are deleted are not unreffed.
465 	 * Params:
466 	 * iter = the GtkTreeIter
467 	 */
468 	public void unrefNode(TreeIter iter);
469 	
470 	/**
471 	 * See gtk_tree_model_get(), this version takes a va_list
472 	 * for language bindings to use.
473 	 * Params:
474 	 * iter = a row in tree_model
475 	 * varArgs = va_list of column/return location pairs
476 	 */
477 	public void getValist(TreeIter iter, void* varArgs);
478 	
479 	/**
480 	 * Calls func on each node in model in a depth-first fashion.
481 	 * If func returns TRUE, then the tree ceases to be walked,
482 	 * and gtk_tree_model_foreach() returns.
483 	 * Params:
484 	 * func = a function to be called on each row. [scope call]
485 	 * userData = user data to passed to func
486 	 */
487 	public void foreac(GtkTreeModelForeachFunc func, void* userData);
488 	
489 	/**
490 	 * Emits the "row-changed" signal on tree_model.
491 	 * Params:
492 	 * path = a GtkTreePath pointing to the changed row
493 	 * iter = a valid GtkTreeIter pointing to the changed row
494 	 */
495 	public void rowChanged(TreePath path, TreeIter iter);
496 	
497 	/**
498 	 * Emits the "row-inserted" signal on tree_model.
499 	 * Params:
500 	 * path = a GtkTreePath pointing to the inserted row
501 	 * iter = a valid GtkTreeIter pointing to the inserted row
502 	 */
503 	public void rowInserted(TreePath path, TreeIter iter);
504 	
505 	/**
506 	 * Emits the "row-has-child-toggled" signal on
507 	 * tree_model. This should be called by models after the child
508 	 * state of a node changes.
509 	 * Params:
510 	 * path = a GtkTreePath pointing to the changed row
511 	 * iter = a valid GtkTreeIter pointing to the changed row
512 	 */
513 	public void rowHasChildToggled(TreePath path, TreeIter iter);
514 	
515 	/**
516 	 * Emits the "row-deleted" signal on tree_model.
517 	 * This should be called by models after a row has been removed.
518 	 * The location pointed to by path should be the location that
519 	 * the row previously was at. It may not be a valid location anymore.
520 	 * Nodes that are deleted are not unreffed, this means that any
521 	 * outstanding references on the deleted node should not be released.
522 	 * Params:
523 	 * path = a GtkTreePath pointing to the previous location of
524 	 * the deleted row
525 	 */
526 	public void rowDeleted(TreePath path);
527 	
528 	/**
529 	 * Emits the "rows-reordered" signal on tree_model.
530 	 * This should be called by models when their rows have been
531 	 * reordered.
532 	 * Params:
533 	 * path = a GtkTreePath pointing to the tree node whose children
534 	 * have been reordered
535 	 * iter = a valid GtkTreeIter pointing to the node whose children
536 	 * have been reordered, or NULL if the depth of path is 0
537 	 * newOrder = an array of integers mapping the current position of
538 	 * each child to its old position before the re-ordering,
539 	 * i.e. new_order[newpos] = oldpos
540 	 * Signal Details
541 	 * The "row-changed" signal
542 	 * void user_function (GtkTreeModel *tree_model,
543 	 *  GtkTreePath *path,
544 	 *  GtkTreeIter *iter,
545 	 *  gpointer user_data) : Run Last
546 	 * This signal is emitted when a row in the model has changed.
547 	 * path = a GtkTreePath identifying the changed row
548 	 * iter = a valid GtkTreeIter pointing to the changed row
549 	 */
550 	public void rowsReordered(TreePath path, TreeIter iter, int[] newOrder);
551 }