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 module gtk.TreePath;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gtkc.gtk;
31 public  import gtkc.gtktypes;
32 
33 
34 public class TreePath
35 {
36 	/** the main Gtk struct */
37 	protected GtkTreePath* gtkTreePath;
38 
39 	/** Get the main Gtk struct */
40 	public GtkTreePath* getTreePathStruct()
41 	{
42 		return gtkTreePath;
43 	}
44 
45 	/** the main Gtk struct as a void* */
46 	protected void* getStruct()
47 	{
48 		return cast(void*)gtkTreePath;
49 	}
50 
51 	/**
52 	 * Sets our main struct and passes it to the parent class.
53 	 */
54 	public this (GtkTreePath* gtkTreePath)
55 	{
56 		this.gtkTreePath = gtkTreePath;
57 	}
58 
59 	/**
60 	 * Creates a new GtkTreePath. This structure refers to a row.
61 	 * Params:
62 	 * firstRow = if true this is the string representation of this path is "0"
63 	 * Throws: ConstructionException GTK+ fails to create the object.
64 	 */
65 	public this (bool firstRow=false)
66 	{
67 		GtkTreePath* p;
68 		
69 		if ( firstRow )
70 		{
71 			// GtkTreePath* gtk_tree_path_new_first (void);
72 			p = cast(GtkTreePath*)gtk_tree_path_new_first();
73 		}
74 		else
75 		{
76 			// GtkTreePath* gtk_tree_path_new (void);
77 			p = cast(GtkTreePath*)gtk_tree_path_new();
78 		}
79 		
80 		if(p is null)
81 		{
82 			throw new ConstructionException("null returned by gtk_tree_path_new()");
83 		}
84 		
85 		this(p);
86 	}
87 	
88 	/**
89 	 * Creates a new path with "indices" as indices.
90 	 */
91 	this (int[] indices ... )
92 	{
93 		this(false);
94 		
95 		foreach( index; indices )
96 		appendIndex(index);
97 	}
98 
99 	/**
100 	 */
101 
102 	public static GType getType()
103 	{
104 		return gtk_tree_path_get_type();
105 	}
106 
107 	/**
108 	 * Creates a new #GtkTreePath-struct initialized to @path.
109 	 *
110 	 * @path is expected to be a colon separated list of numbers.
111 	 * For example, the string “10:4:0” would create a path of depth
112 	 * 3 pointing to the 11th child of the root node, the 5th
113 	 * child of that 11th child, and the 1st child of that 5th child.
114 	 * If an invalid path string is passed in, %NULL is returned.
115 	 *
116 	 * Params:
117 	 *     path = The string representation of a path
118 	 *
119 	 * Return: A newly-created #GtkTreePath-struct, or %NULL
120 	 *
121 	 * Throws: ConstructionException GTK+ fails to create the object.
122 	 */
123 	public this(string path)
124 	{
125 		auto p = gtk_tree_path_new_from_string(Str.toStringz(path));
126 		
127 		if(p is null)
128 		{
129 			throw new ConstructionException("null returned by new_from_string");
130 		}
131 		
132 		this(cast(GtkTreePath*) p);
133 	}
134 
135 	/**
136 	 * Appends a new index to a path.
137 	 *
138 	 * As a result, the depth of the path is increased.
139 	 *
140 	 * Params:
141 	 *     index = the index
142 	 */
143 	public void appendIndex(int index)
144 	{
145 		gtk_tree_path_append_index(gtkTreePath, index);
146 	}
147 
148 	/**
149 	 * Compares two paths.
150 	 *
151 	 * If @a appears before @b in a tree, then -1 is returned.
152 	 * If @b appears before @a, then 1 is returned.
153 	 * If the two nodes are equal, then 0 is returned.
154 	 *
155 	 * Params:
156 	 *     b = a #GtkTreePath-struct to compare with
157 	 *
158 	 * Return: the relative positions of @a and @b
159 	 */
160 	public int compare(TreePath b)
161 	{
162 		return gtk_tree_path_compare(gtkTreePath, (b is null) ? null : b.getTreePathStruct());
163 	}
164 
165 	/**
166 	 * Creates a new #GtkTreePath-struct as a copy of @path.
167 	 *
168 	 * Return: a new #GtkTreePath-struct
169 	 */
170 	public TreePath copy()
171 	{
172 		auto p = gtk_tree_path_copy(gtkTreePath);
173 		
174 		if(p is null)
175 		{
176 			return null;
177 		}
178 		
179 		return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) p);
180 	}
181 
182 	/**
183 	 * Moves @path to point to the first child of the current path.
184 	 */
185 	public void down()
186 	{
187 		gtk_tree_path_down(gtkTreePath);
188 	}
189 
190 	/**
191 	 * Frees @path. If @path is %NULL, it simply returns.
192 	 */
193 	public void free()
194 	{
195 		gtk_tree_path_free(gtkTreePath);
196 	}
197 
198 	/**
199 	 * Returns the current depth of @path.
200 	 *
201 	 * Return: The depth of @path
202 	 */
203 	public int getDepth()
204 	{
205 		return gtk_tree_path_get_depth(gtkTreePath);
206 	}
207 
208 	/**
209 	 * Returns the current indices of @path.
210 	 *
211 	 * This is an array of integers, each representing a node in a tree.
212 	 * It also returns the number of elements in the array.
213 	 * The array should not be freed.
214 	 *
215 	 * Params:
216 	 *     depth = return location for number of elements
217 	 *         returned in the integer array, or %NULL
218 	 *
219 	 * Return: The current
220 	 *     indices, or %NULL
221 	 *
222 	 * Since: 3.0
223 	 */
224 	public int[] getIndices()
225 	{
226 		int depth;
227 		
228 		auto p = gtk_tree_path_get_indices_with_depth(gtkTreePath, &depth);
229 		
230 		return p[0 .. depth];
231 	}
232 
233 	/**
234 	 * Returns %TRUE if @descendant is a descendant of @path.
235 	 *
236 	 * Params:
237 	 *     descendant = another #GtkTreePath-struct
238 	 *
239 	 * Return: %TRUE if @descendant is contained inside @path
240 	 */
241 	public bool isAncestor(TreePath descendant)
242 	{
243 		return gtk_tree_path_is_ancestor(gtkTreePath, (descendant is null) ? null : descendant.getTreePathStruct()) != 0;
244 	}
245 
246 	/**
247 	 * Returns %TRUE if @path is a descendant of @ancestor.
248 	 *
249 	 * Params:
250 	 *     ancestor = another #GtkTreePath-struct
251 	 *
252 	 * Return: %TRUE if @ancestor contains @path somewhere below it
253 	 */
254 	public bool isDescendant(TreePath ancestor)
255 	{
256 		return gtk_tree_path_is_descendant(gtkTreePath, (ancestor is null) ? null : ancestor.getTreePathStruct()) != 0;
257 	}
258 
259 	/**
260 	 * Moves the @path to point to the next node at the current depth.
261 	 */
262 	public void next()
263 	{
264 		gtk_tree_path_next(gtkTreePath);
265 	}
266 
267 	/**
268 	 * Prepends a new index to a path.
269 	 *
270 	 * As a result, the depth of the path is increased.
271 	 *
272 	 * Params:
273 	 *     index = the index
274 	 */
275 	public void prependIndex(int index)
276 	{
277 		gtk_tree_path_prepend_index(gtkTreePath, index);
278 	}
279 
280 	/**
281 	 * Moves the @path to point to the previous node at the
282 	 * current depth, if it exists.
283 	 *
284 	 * Return: %TRUE if @path has a previous node, and
285 	 *     the move was made
286 	 */
287 	public bool prev()
288 	{
289 		return gtk_tree_path_prev(gtkTreePath) != 0;
290 	}
291 
292 	/**
293 	 * Generates a string representation of the path.
294 	 *
295 	 * This string is a “:” separated list of numbers.
296 	 * For example, “4:10:0:3” would be an acceptable
297 	 * return value for this string.
298 	 *
299 	 * Return: A newly-allocated string.
300 	 *     Must be freed with g_free().
301 	 */
302 	public override string toString()
303 	{
304 		return Str.toString(gtk_tree_path_to_string(gtkTreePath));
305 	}
306 
307 	/**
308 	 * Moves the @path to point to its parent node, if it has a parent.
309 	 *
310 	 * Return: %TRUE if @path has a parent, and the move was made
311 	 */
312 	public bool up()
313 	{
314 		return gtk_tree_path_up(gtkTreePath) != 0;
315 	}
316 }