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