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 /** */
35 public class TreePath
36 {
37 	/** the main Gtk struct */
38 	protected GtkTreePath* gtkTreePath;
39 	protected bool ownedRef;
40 
41 	/** Get the main Gtk struct */
42 	public GtkTreePath* getTreePathStruct()
43 	{
44 		return gtkTreePath;
45 	}
46 
47 	/** the main Gtk struct as a void* */
48 	protected void* getStruct()
49 	{
50 		return cast(void*)gtkTreePath;
51 	}
52 
53 	/**
54 	 * Sets our main struct and passes it to the parent class.
55 	 */
56 	public this (GtkTreePath* gtkTreePath, bool ownedRef = false)
57 	{
58 		this.gtkTreePath = gtkTreePath;
59 		this.ownedRef = ownedRef;
60 	}
61 
62 	/**
63 	 * Creates a new GtkTreePath. This structure refers to a row.
64 	 * Params:
65 	 * firstRow = if true this is the string representation of this path is "0"
66 	 * Throws: ConstructionException GTK+ fails to create the object.
67 	 */
68 	public this (bool firstRow=false)
69 	{
70 		GtkTreePath* p;
71 		
72 		if ( firstRow )
73 		{
74 			// GtkTreePath* gtk_tree_path_new_first (void);
75 			p = cast(GtkTreePath*)gtk_tree_path_new_first();
76 		}
77 		else
78 		{
79 			// GtkTreePath* gtk_tree_path_new (void);
80 			p = cast(GtkTreePath*)gtk_tree_path_new();
81 		}
82 		
83 		if(p is null)
84 		{
85 			throw new ConstructionException("null returned by gtk_tree_path_new()");
86 		}
87 		
88 		this(p);
89 	}
90 	
91 	/**
92 	 * Creates a new path with "indices" as indices.
93 	 */
94 	this (int[] indices ... )
95 	{
96 		this(false);
97 		
98 		foreach( index; indices )
99 		appendIndex(index);
100 	}
101 
102 	/**
103 	 */
104 
105 	/** */
106 	public static GType getType()
107 	{
108 		return gtk_tree_path_get_type();
109 	}
110 
111 	/**
112 	 * Creates a new #GtkTreePath-struct initialized to @path.
113 	 *
114 	 * @path is expected to be a colon separated list of numbers.
115 	 * For example, the string “10:4:0” would create a path of depth
116 	 * 3 pointing to the 11th child of the root node, the 5th
117 	 * child of that 11th child, and the 1st child of that 5th child.
118 	 * If an invalid path string is passed in, %NULL is returned.
119 	 *
120 	 * Params:
121 	 *     path = The string representation of a path
122 	 *
123 	 * Return: A newly-created #GtkTreePath-struct, or %NULL
124 	 *
125 	 * Throws: ConstructionException GTK+ fails to create the object.
126 	 */
127 	public this(string path)
128 	{
129 		auto p = gtk_tree_path_new_from_string(Str.toStringz(path));
130 		
131 		if(p is null)
132 		{
133 			throw new ConstructionException("null returned by new_from_string");
134 		}
135 		
136 		this(cast(GtkTreePath*) p);
137 	}
138 
139 	/**
140 	 * Appends a new index to a path.
141 	 *
142 	 * As a result, the depth of the path is increased.
143 	 *
144 	 * Params:
145 	 *     index = the index
146 	 */
147 	public void appendIndex(int index)
148 	{
149 		gtk_tree_path_append_index(gtkTreePath, index);
150 	}
151 
152 	/**
153 	 * Compares two paths.
154 	 *
155 	 * If @a appears before @b in a tree, then -1 is returned.
156 	 * If @b appears before @a, then 1 is returned.
157 	 * If the two nodes are equal, then 0 is returned.
158 	 *
159 	 * Params:
160 	 *     b = a #GtkTreePath-struct to compare with
161 	 *
162 	 * Return: the relative positions of @a and @b
163 	 */
164 	public int compare(TreePath b)
165 	{
166 		return gtk_tree_path_compare(gtkTreePath, (b is null) ? null : b.getTreePathStruct());
167 	}
168 
169 	/**
170 	 * Creates a new #GtkTreePath-struct as a copy of @path.
171 	 *
172 	 * Return: a new #GtkTreePath-struct
173 	 */
174 	public TreePath copy()
175 	{
176 		auto p = gtk_tree_path_copy(gtkTreePath);
177 		
178 		if(p is null)
179 		{
180 			return null;
181 		}
182 		
183 		return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) p, true);
184 	}
185 
186 	/**
187 	 * Moves @path to point to the first child of the current path.
188 	 */
189 	public void down()
190 	{
191 		gtk_tree_path_down(gtkTreePath);
192 	}
193 
194 	/**
195 	 * Frees @path. If @path is %NULL, it simply returns.
196 	 */
197 	public void free()
198 	{
199 		gtk_tree_path_free(gtkTreePath);
200 	}
201 
202 	/**
203 	 * Returns the current depth of @path.
204 	 *
205 	 * Return: The depth of @path
206 	 */
207 	public int getDepth()
208 	{
209 		return gtk_tree_path_get_depth(gtkTreePath);
210 	}
211 
212 	/**
213 	 * Returns the current indices of @path.
214 	 *
215 	 * This is an array of integers, each representing a node in a tree.
216 	 * It also returns the number of elements in the array.
217 	 * The array should not be freed.
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 		auto retStr = gtk_tree_path_to_string(gtkTreePath);
305 		
306 		scope(exit) Str.freeString(retStr);
307 		return Str.toString(retStr);
308 	}
309 
310 	/**
311 	 * Moves the @path to point to its parent node, if it has a parent.
312 	 *
313 	 * Return: %TRUE if @path has a parent, and the move was made
314 	 */
315 	public bool up()
316 	{
317 		return gtk_tree_path_up(gtkTreePath) != 0;
318 	}
319 }