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  = GtkTreeModel.html
27  * outPack = gtk
28  * outFile = TreePath
29  * strct   = GtkTreePath
30  * realStrct=
31  * ctorStrct=
32  * clss    = TreePath
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_tree_path_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- gtk_tree_path_new
45  * 	- gtk_tree_path_new_first
46  * omit signals:
47  * 	- row-changed
48  * 	- row-deleted
49  * 	- row-has-child-toggled
50  * 	- row-inserted
51  * 	- rows-reordered
52  * imports:
53  * 	- glib.Str
54  * 	- gtkc.Loader
55  * 	- gtkc.paths
56  * structWrap:
57  * 	- GtkTreePath* -> TreePath
58  * module aliases:
59  * local aliases:
60  * overrides:
61  * 	- toString
62  */
63 
64 module gtk.TreePath;
65 
66 public  import gtkc.gtktypes;
67 
68 private import gtkc.gtk;
69 private import glib.ConstructionException;
70 private import gobject.ObjectG;
71 
72 private import gobject.Signals;
73 public  import gtkc.gdktypes;
74 private import glib.Str;
75 private import gtkc.Loader;
76 private import gtkc.paths;
77 
78 
79 
80 /**
81  * The GtkTreeModel interface defines a generic tree interface for
82  * use by the GtkTreeView widget. It is an abstract interface, and
83  * is designed to be usable with any appropriate data structure. The
84  * programmer just has to implement this interface on their own data
85  * type for it to be viewable by a GtkTreeView widget.
86  *
87  * The model is represented as a hierarchical tree of strongly-typed,
88  * columned data. In other words, the model can be seen as a tree where
89  * every node has different values depending on which column is being
90  * queried. The type of data found in a column is determined by using
91  * the GType system (ie. G_TYPE_INT, GTK_TYPE_BUTTON, G_TYPE_POINTER,
92  * etc). The types are homogeneous per column across all nodes. It is
93  * important to note that this interface only provides a way of examining
94  * a model and observing changes. The implementation of each individual
95  * model decides how and if changes are made.
96  *
97  * In order to make life simpler for programmers who do not need to
98  * write their own specialized model, two generic models are provided
99  * — the GtkTreeStore and the GtkListStore. To use these, the
100  * developer simply pushes data into these models as necessary. These
101  * models provide the data structure as well as all appropriate tree
102  * interfaces. As a result, implementing drag and drop, sorting, and
103  * storing data is trivial. For the vast majority of trees and lists,
104  * these two models are sufficient.
105  *
106  * Models are accessed on a node/column level of granularity. One can
107  * query for the value of a model at a certain node and a certain
108  * column on that node. There are two structures used to reference
109  * a particular node in a model. They are the GtkTreePath and the
110  * GtkTreeIter[4]. Most of the interface
111  * consists of operations on a GtkTreeIter.
112  *
113  * A path is essentially a potential node. It is a location on a model
114  * that may or may not actually correspond to a node on a specific
115  * model. The GtkTreePath struct can be converted into either an
116  * array of unsigned integers or a string. The string form is a list
117  * of numbers separated by a colon. Each number refers to the offset
118  * at that level. Thus, the path “0” refers to the root
119  * node and the path “2:4” refers to the fifth child of
120  * the third node.
121  *
122  * By contrast, a GtkTreeIter is a reference to a specific node on
123  * a specific model. It is a generic struct with an integer and three
124  * generic pointers. These are filled in by the model in a model-specific
125  * way. One can convert a path to an iterator by calling
126  * gtk_tree_model_get_iter(). These iterators are the primary way
127  * of accessing a model and are similar to the iterators used by
128  * GtkTextBuffer. They are generally statically allocated on the
129  * stack and only used for a short time. The model interface defines
130  * a set of operations using them for navigating the model.
131  *
132  * It is expected that models fill in the iterator with private data.
133  * For example, the GtkListStore model, which is internally a simple
134  * linked list, stores a list node in one of the pointers. The
135  * GtkTreeModelSort stores an array and an offset in two of the
136  * pointers. Additionally, there is an integer field. This field is
137  * generally filled with a unique stamp per model. This stamp is for
138  * catching errors resulting from using invalid iterators with a model.
139  *
140  * The lifecycle of an iterator can be a little confusing at first.
141  * Iterators are expected to always be valid for as long as the model
142  * is unchanged (and doesn't emit a signal). The model is considered
143  * to own all outstanding iterators and nothing needs to be done to
144  * free them from the user's point of view. Additionally, some models
145  * guarantee that an iterator is valid for as long as the node it refers
146  * to is valid (most notably the GtkTreeStore and GtkListStore).
147  * Although generally uninteresting, as one always has to allow for
148  * the case where iterators do not persist beyond a signal, some very
149  * important performance enhancements were made in the sort model.
150  * As a result, the GTK_TREE_MODEL_ITERS_PERSIST flag was added to
151  * indicate this behavior.
152  *
153  * To help show some common operation of a model, some examples are
154  * provided. The first example shows three ways of getting the iter at
155  * the location “3:2:5”. While the first method shown is
156  * easier, the second is much more common, as you often get paths from
157  * callbacks.
158  *
159  * $(DDOC_COMMENT example)
160  *
161  * This second example shows a quick way of iterating through a list
162  * and getting a string and an integer from each row. The
163  * populate_model function used below is not
164  * shown, as it is specific to the GtkListStore. For information on
165  * how to write such a function, see the GtkListStore documentation.
166  *
167  * $(DDOC_COMMENT example)
168  *
169  * The GtkTreeModel interface contains two methods for reference
170  * counting: gtk_tree_model_ref_node() and gtk_tree_model_unref_node().
171  * These two methods are optional to implement. The reference counting
172  * is meant as a way for views to let models know when nodes are being
173  * displayed. GtkTreeView will take a reference on a node when it is
174  * visible, which means the node is either in the toplevel or expanded.
175  * Being displayed does not mean that the node is currently directly
176  * visible to the user in the viewport. Based on this reference counting
177  * scheme a caching model, for example, can decide whether or not to cache
178  * a node based on the reference count. A file-system based model would
179  * not want to keep the entire file hierarchy in memory, but just the
180  * folders that are currently expanded in every current view.
181  *
182  * When working with reference counting, the following rules must be taken
183  * into account:
184  *
185  * Never take a reference on a node without owning a
186  * reference on its parent. This means that all parent nodes of a referenced
187  * node must be referenced as well.
188  *
189  * Outstanding references on a deleted node are not released.
190  * This is not possible because the node has already been deleted by the
191  * time the row-deleted signal is received.
192  *
193  * Models are not obligated to emit a signal on rows of
194  * which none of its siblings are referenced. To phrase this differently,
195  * signals are only required for levels in which nodes are referenced. For
196  * the root level however, signals must be emitted at all times (however the
197  * root level is always referenced when any view is attached).
198  */
199 public class TreePath
200 {
201 	
202 	/** the main Gtk struct */
203 	protected GtkTreePath* gtkTreePath;
204 	
205 	
206 	/** Get the main Gtk struct */
207 	public GtkTreePath* getTreePathStruct()
208 	{
209 		return gtkTreePath;
210 	}
211 	
212 	
213 	/** the main Gtk struct as a void* */
214 	protected void* getStruct()
215 	{
216 		return cast(void*)gtkTreePath;
217 	}
218 	
219 	/**
220 	 * Sets our main struct and passes it to the parent class
221 	 */
222 	public this (GtkTreePath* gtkTreePath)
223 	{
224 		this.gtkTreePath = gtkTreePath;
225 	}
226 	
227 	/**
228 	 * Creates a new GtkTreePath. This structure refers to a row.
229 	 * Params:
230 	 * firstRow = if true this is the string representation of this path is "0"
231 	 * Throws: ConstructionException GTK+ fails to create the object.
232 	 */
233 	public this (bool firstRow=false)
234 	{
235 		GtkTreePath* p;
236 		
237 		if ( firstRow )
238 		{
239 			// GtkTreePath* gtk_tree_path_new_first (void);
240 			p = cast(GtkTreePath*)gtk_tree_path_new_first();
241 		}
242 		else
243 		{
244 			// GtkTreePath* gtk_tree_path_new (void);
245 			p = cast(GtkTreePath*)gtk_tree_path_new();
246 		}
247 		
248 		if(p is null)
249 		{
250 			throw new ConstructionException("null returned by gtk_tree_path_new()");
251 		}
252 		
253 		this(p);
254 	}
255 	
256 	/**
257 	 * Creates a new path with "indices" as indices.
258 	 */
259 	this (int[] indices ... )
260 	{
261 		this(false);
262 		
263 		foreach( index; indices )
264 		appendIndex(index);
265 	}
266 	
267 	/**
268 	 */
269 	
270 	/**
271 	 * Creates a new GtkTreePath initialized to path.
272 	 * path is expected to be a colon separated list of numbers.
273 	 * For example, the string "10:4:0" would create a path of depth
274 	 * 3 pointing to the 11th child of the root node, the 5th
275 	 * child of that 11th child, and the 1st child of that 5th child.
276 	 * If an invalid path string is passed in, NULL is returned.
277 	 * Params:
278 	 * path = The string representation of a path
279 	 * Throws: ConstructionException GTK+ fails to create the object.
280 	 */
281 	public this (string path)
282 	{
283 		// GtkTreePath * gtk_tree_path_new_from_string (const gchar *path);
284 		auto p = gtk_tree_path_new_from_string(Str.toStringz(path));
285 		if(p is null)
286 		{
287 			throw new ConstructionException("null returned by gtk_tree_path_new_from_string(Str.toStringz(path))");
288 		}
289 		this(cast(GtkTreePath*) p);
290 	}
291 	
292 	/**
293 	 * Generates a string representation of the path.
294 	 * This string is a ':' separated list of numbers.
295 	 * For example, "4:10:0:3" would be an acceptable
296 	 * return value for this string.
297 	 * Returns: A newly-allocated string. Must be freed with g_free().
298 	 */
299 	public override string toString()
300 	{
301 		// gchar * gtk_tree_path_to_string (GtkTreePath *path);
302 		return Str.toString(gtk_tree_path_to_string(gtkTreePath));
303 	}
304 	
305 	/**
306 	 * Appends a new index to a path.
307 	 * As a result, the depth of the path is increased.
308 	 * Params:
309 	 * index = the index
310 	 */
311 	public void appendIndex(int index)
312 	{
313 		// void gtk_tree_path_append_index (GtkTreePath *path,  gint index_);
314 		gtk_tree_path_append_index(gtkTreePath, index);
315 	}
316 	
317 	/**
318 	 * Prepends a new index to a path.
319 	 * As a result, the depth of the path is increased.
320 	 * Params:
321 	 * index = the index
322 	 */
323 	public void prependIndex(int index)
324 	{
325 		// void gtk_tree_path_prepend_index (GtkTreePath *path,  gint index_);
326 		gtk_tree_path_prepend_index(gtkTreePath, index);
327 	}
328 	
329 	/**
330 	 * Returns the current depth of path.
331 	 * Returns: The depth of path
332 	 */
333 	public int getDepth()
334 	{
335 		// gint gtk_tree_path_get_depth (GtkTreePath *path);
336 		return gtk_tree_path_get_depth(gtkTreePath);
337 	}
338 	
339 	/**
340 	 * Returns the current indices of path.
341 	 * This is an array of integers, each representing a node in a tree.
342 	 * This value should not be freed.
343 	 * The length of the array can be obtained with gtk_tree_path_get_depth().
344 	 * Returns: The current indices, or NULL
345 	 */
346 	public int[] getIndices()
347 	{
348 		// gint * gtk_tree_path_get_indices (GtkTreePath *path);
349 		auto p = gtk_tree_path_get_indices(gtkTreePath);
350 		
351 		if(p is null)
352 		{
353 			return null;
354 		}
355 		
356 		return p[0 .. getDepth()];
357 	}
358 	
359 	/**
360 	 * Returns the current indices of path.
361 	 * This is an array of integers, each representing a node in a tree.
362 	 * It also returns the number of elements in the array.
363 	 * The array should not be freed.
364 	 * Returns: The current indices, or NULL. [array length=depth][transfer none] Since 3.0
365 	 */
366 	public int[] getIndicesWithDepth()
367 	{
368 		// gint * gtk_tree_path_get_indices_with_depth  (GtkTreePath *path,  gint *depth);
369 		int depth;
370 		auto p = gtk_tree_path_get_indices_with_depth(gtkTreePath, &depth);
371 		
372 		if(p is null)
373 		{
374 			return null;
375 		}
376 		
377 		return p[0 .. depth];
378 	}
379 	
380 	/**
381 	 * Frees path. If path is NULL, it simply returns.
382 	 */
383 	public void free()
384 	{
385 		// void gtk_tree_path_free (GtkTreePath *path);
386 		gtk_tree_path_free(gtkTreePath);
387 	}
388 	
389 	/**
390 	 * Creates a new GtkTreePath as a copy of path.
391 	 * Returns: a new GtkTreePath
392 	 */
393 	public TreePath copy()
394 	{
395 		// GtkTreePath * gtk_tree_path_copy (const GtkTreePath *path);
396 		auto p = gtk_tree_path_copy(gtkTreePath);
397 		
398 		if(p is null)
399 		{
400 			return null;
401 		}
402 		
403 		return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) p);
404 	}
405 	
406 	/**
407 	 * Compares two paths.
408 	 * If a appears before b in a tree, then -1 is returned.
409 	 * If b appears before a, then 1 is returned.
410 	 * If the two nodes are equal, then 0 is returned.
411 	 * Params:
412 	 * a = a GtkTreePath
413 	 * b = a GtkTreePath to compare with
414 	 * Returns: the relative positions of a and b
415 	 */
416 	public int compare(TreePath b)
417 	{
418 		// gint gtk_tree_path_compare (const GtkTreePath *a,  const GtkTreePath *b);
419 		return gtk_tree_path_compare(gtkTreePath, (b is null) ? null : b.getTreePathStruct());
420 	}
421 	
422 	/**
423 	 * Moves the path to point to the next node at the current depth.
424 	 */
425 	public void next()
426 	{
427 		// void gtk_tree_path_next (GtkTreePath *path);
428 		gtk_tree_path_next(gtkTreePath);
429 	}
430 	
431 	/**
432 	 * Moves the path to point to the previous node at the
433 	 * current depth, if it exists.
434 	 * Returns: TRUE if path has a previous node, and the move was made
435 	 */
436 	public int prev()
437 	{
438 		// gboolean gtk_tree_path_prev (GtkTreePath *path);
439 		return gtk_tree_path_prev(gtkTreePath);
440 	}
441 	
442 	/**
443 	 * Moves the path to point to its parent node, if it has a parent.
444 	 * Returns: TRUE if path has a parent, and the move was made
445 	 */
446 	public int up()
447 	{
448 		// gboolean gtk_tree_path_up (GtkTreePath *path);
449 		return gtk_tree_path_up(gtkTreePath);
450 	}
451 	
452 	/**
453 	 * Moves path to point to the first child of the current path.
454 	 */
455 	public void down()
456 	{
457 		// void gtk_tree_path_down (GtkTreePath *path);
458 		gtk_tree_path_down(gtkTreePath);
459 	}
460 	
461 	/**
462 	 * Returns TRUE if descendant is a descendant of path.
463 	 * Params:
464 	 * descendant = another GtkTreePath
465 	 * Returns: TRUE if descendant is contained inside path
466 	 */
467 	public int isAncestor(TreePath descendant)
468 	{
469 		// gboolean gtk_tree_path_is_ancestor (GtkTreePath *path,  GtkTreePath *descendant);
470 		return gtk_tree_path_is_ancestor(gtkTreePath, (descendant is null) ? null : descendant.getTreePathStruct());
471 	}
472 	
473 	/**
474 	 * Returns TRUE if path is a descendant of ancestor.
475 	 * Params:
476 	 * ancestor = another GtkTreePath
477 	 * Returns: TRUE if ancestor contains path somewhere below it
478 	 */
479 	public int isDescendant(TreePath ancestor)
480 	{
481 		// gboolean gtk_tree_path_is_descendant (GtkTreePath *path,  GtkTreePath *ancestor);
482 		return gtk_tree_path_is_descendant(gtkTreePath, (ancestor is null) ? null : ancestor.getTreePathStruct());
483 	}
484 }