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