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