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.TreeStore;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 private import gobject.Value;
31 private import gtk.BuildableIF;
32 private import gtk.BuildableT;
33 private import gtk.TreeDragDestIF;
34 private import gtk.TreeDragDestT;
35 private import gtk.TreeDragSourceIF;
36 private import gtk.TreeDragSourceT;
37 private import gtk.TreeIter;
38 private import gtk.TreeModelIF;
39 private import gtk.TreeModelT;
40 private import gtk.TreeSortableIF;
41 private import gtk.TreeSortableT;
42 private import gtk.c.functions;
43 public  import gtk.c.types;
44 
45 
46 /**
47  * A tree-like data structure that can be used with the GtkTreeView
48  * 
49  * The #GtkTreeStore object is a list model for use with a #GtkTreeView
50  * widget.  It implements the #GtkTreeModel interface, and consequently,
51  * can use all of the methods available there.  It also implements the
52  * #GtkTreeSortable interface so it can be sorted by the view.  Finally,
53  * it also implements the tree
54  * [drag and drop][gtk3-GtkTreeView-drag-and-drop]
55  * interfaces.
56  * 
57  * # GtkTreeStore as GtkBuildable
58  * 
59  * The GtkTreeStore implementation of the #GtkBuildable interface allows
60  * to specify the model columns with a <columns> element that may contain
61  * multiple <column> elements, each specifying one model column. The “type”
62  * attribute specifies the data type for the column.
63  * 
64  * An example of a UI Definition fragment for a tree store:
65  * |[
66  * <object class="GtkTreeStore">
67  * <columns>
68  * <column type="gchararray"/>
69  * <column type="gchararray"/>
70  * <column type="gint"/>
71  * </columns>
72  * </object>
73  * ]|
74  */
75 public class TreeStore : ObjectG, BuildableIF, TreeDragDestIF, TreeDragSourceIF, TreeModelIF, TreeSortableIF
76 {
77 	/** the main Gtk struct */
78 	protected GtkTreeStore* gtkTreeStore;
79 
80 	/** Get the main Gtk struct */
81 	public GtkTreeStore* getTreeStoreStruct(bool transferOwnership = false)
82 	{
83 		if (transferOwnership)
84 			ownedRef = false;
85 		return gtkTreeStore;
86 	}
87 
88 	/** the main Gtk struct as a void* */
89 	protected override void* getStruct()
90 	{
91 		return cast(void*)gtkTreeStore;
92 	}
93 
94 	/**
95 	 * Sets our main struct and passes it to the parent class.
96 	 */
97 	public this (GtkTreeStore* gtkTreeStore, bool ownedRef = false)
98 	{
99 		this.gtkTreeStore = gtkTreeStore;
100 		super(cast(GObject*)gtkTreeStore, ownedRef);
101 	}
102 
103 	// add the Buildable capabilities
104 	mixin BuildableT!(GtkTreeStore);
105 
106 	// add the TreeDragDest capabilities
107 	mixin TreeDragDestT!(GtkTreeStore);
108 
109 	// add the TreeDragSource capabilities
110 	mixin TreeDragSourceT!(GtkTreeStore);
111 
112 	// add the TreeModel capabilities
113 	mixin TreeModelT!(GtkTreeStore);
114 
115 	// add the TreeSortable capabilities
116 	mixin TreeSortableT!(GtkTreeStore);
117 
118 
119 	/** */
120 	public static GType getType()
121 	{
122 		return gtk_tree_store_get_type();
123 	}
124 
125 	/**
126 	 * Non vararg creation function.  Used primarily by language bindings.
127 	 *
128 	 * Params:
129 	 *     types = an array of #GType types for the columns, from first to last
130 	 *
131 	 * Returns: a new #GtkTreeStore
132 	 *
133 	 * Throws: ConstructionException GTK+ fails to create the object.
134 	 */
135 	public this(GType[] types)
136 	{
137 		auto __p = gtk_tree_store_newv(cast(int)types.length, types.ptr);
138 
139 		if(__p is null)
140 		{
141 			throw new ConstructionException("null returned by newv");
142 		}
143 
144 		this(cast(GtkTreeStore*) __p, true);
145 	}
146 
147 	/**
148 	 * Appends a new row to @tree_store.  If @parent is non-%NULL, then it will append the
149 	 * new row after the last child of @parent, otherwise it will append a row to
150 	 * the top level.  @iter will be changed to point to this new row.  The row will
151 	 * be empty after this function is called.  To fill in values, you need to call
152 	 * gtk_tree_store_set() or gtk_tree_store_set_value().
153 	 *
154 	 * Params:
155 	 *     iter = An unset #GtkTreeIter to set to the appended row
156 	 *     parent = A valid #GtkTreeIter, or %NULL
157 	 */
158 	public void append(out TreeIter iter, TreeIter parent)
159 	{
160 		GtkTreeIter* outiter = sliceNew!GtkTreeIter();
161 
162 		gtk_tree_store_append(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct());
163 
164 		iter = ObjectG.getDObject!(TreeIter)(outiter, true);
165 	}
166 
167 	/**
168 	 * Removes all rows from @tree_store
169 	 */
170 	public void clear()
171 	{
172 		gtk_tree_store_clear(gtkTreeStore);
173 	}
174 
175 	/**
176 	 * Creates a new row at @position.  If parent is non-%NULL, then the row will be
177 	 * made a child of @parent.  Otherwise, the row will be created at the toplevel.
178 	 * If @position is -1 or is larger than the number of rows at that level, then
179 	 * the new row will be inserted to the end of the list.  @iter will be changed
180 	 * to point to this new row.  The row will be empty after this function is
181 	 * called.  To fill in values, you need to call gtk_tree_store_set() or
182 	 * gtk_tree_store_set_value().
183 	 *
184 	 * Params:
185 	 *     iter = An unset #GtkTreeIter to set to the new row
186 	 *     parent = A valid #GtkTreeIter, or %NULL
187 	 *     position = position to insert the new row, or -1 for last
188 	 */
189 	public void insert(out TreeIter iter, TreeIter parent, int position)
190 	{
191 		GtkTreeIter* outiter = sliceNew!GtkTreeIter();
192 
193 		gtk_tree_store_insert(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct(), position);
194 
195 		iter = ObjectG.getDObject!(TreeIter)(outiter, true);
196 	}
197 
198 	/**
199 	 * Inserts a new row after @sibling.  If @sibling is %NULL, then the row will be
200 	 * prepended to @parent ’s children.  If @parent and @sibling are %NULL, then
201 	 * the row will be prepended to the toplevel.  If both @sibling and @parent are
202 	 * set, then @parent must be the parent of @sibling.  When @sibling is set,
203 	 * @parent is optional.
204 	 *
205 	 * @iter will be changed to point to this new row.  The row will be empty after
206 	 * this function is called.  To fill in values, you need to call
207 	 * gtk_tree_store_set() or gtk_tree_store_set_value().
208 	 *
209 	 * Params:
210 	 *     iter = An unset #GtkTreeIter to set to the new row
211 	 *     parent = A valid #GtkTreeIter, or %NULL
212 	 *     sibling = A valid #GtkTreeIter, or %NULL
213 	 */
214 	public void insertAfter(out TreeIter iter, TreeIter parent, TreeIter sibling)
215 	{
216 		GtkTreeIter* outiter = sliceNew!GtkTreeIter();
217 
218 		gtk_tree_store_insert_after(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct(), (sibling is null) ? null : sibling.getTreeIterStruct());
219 
220 		iter = ObjectG.getDObject!(TreeIter)(outiter, true);
221 	}
222 
223 	/**
224 	 * Inserts a new row before @sibling.  If @sibling is %NULL, then the row will
225 	 * be appended to @parent ’s children.  If @parent and @sibling are %NULL, then
226 	 * the row will be appended to the toplevel.  If both @sibling and @parent are
227 	 * set, then @parent must be the parent of @sibling.  When @sibling is set,
228 	 * @parent is optional.
229 	 *
230 	 * @iter will be changed to point to this new row.  The row will be empty after
231 	 * this function is called.  To fill in values, you need to call
232 	 * gtk_tree_store_set() or gtk_tree_store_set_value().
233 	 *
234 	 * Params:
235 	 *     iter = An unset #GtkTreeIter to set to the new row
236 	 *     parent = A valid #GtkTreeIter, or %NULL
237 	 *     sibling = A valid #GtkTreeIter, or %NULL
238 	 */
239 	public void insertBefore(out TreeIter iter, TreeIter parent, TreeIter sibling)
240 	{
241 		GtkTreeIter* outiter = sliceNew!GtkTreeIter();
242 
243 		gtk_tree_store_insert_before(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct(), (sibling is null) ? null : sibling.getTreeIterStruct());
244 
245 		iter = ObjectG.getDObject!(TreeIter)(outiter, true);
246 	}
247 
248 	/**
249 	 * A variant of gtk_tree_store_insert_with_values() which takes
250 	 * the columns and values as two arrays, instead of varargs.  This
251 	 * function is mainly intended for language bindings.
252 	 *
253 	 * Params:
254 	 *     iter = An unset #GtkTreeIter to set the new row, or %NULL.
255 	 *     parent = A valid #GtkTreeIter, or %NULL
256 	 *     position = position to insert the new row, or -1 for last
257 	 *     columns = an array of column numbers
258 	 *     values = an array of GValues
259 	 */
260 	public void insertWithValuesv(out TreeIter iter, TreeIter parent, int position, int[] columns, Value[] values)
261 	{
262 		GtkTreeIter* outiter = sliceNew!GtkTreeIter();
263 
264 		GValue[] valuesArray = new GValue[values.length];
265 		for ( int i = 0; i < values.length; i++ )
266 		{
267 			valuesArray[i] = *(values[i].getValueStruct());
268 		}
269 
270 		gtk_tree_store_insert_with_valuesv(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct(), position, columns.ptr, valuesArray.ptr, cast(int)values.length);
271 
272 		iter = ObjectG.getDObject!(TreeIter)(outiter, true);
273 	}
274 
275 	/**
276 	 * Returns %TRUE if @iter is an ancestor of @descendant.  That is, @iter is the
277 	 * parent (or grandparent or great-grandparent) of @descendant.
278 	 *
279 	 * Params:
280 	 *     iter = A valid #GtkTreeIter
281 	 *     descendant = A valid #GtkTreeIter
282 	 *
283 	 * Returns: %TRUE, if @iter is an ancestor of @descendant
284 	 */
285 	public bool isAncestor(TreeIter iter, TreeIter descendant)
286 	{
287 		return gtk_tree_store_is_ancestor(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), (descendant is null) ? null : descendant.getTreeIterStruct()) != 0;
288 	}
289 
290 	/**
291 	 * Returns the depth of @iter.  This will be 0 for anything on the root level, 1
292 	 * for anything down a level, etc.
293 	 *
294 	 * Params:
295 	 *     iter = A valid #GtkTreeIter
296 	 *
297 	 * Returns: The depth of @iter
298 	 */
299 	public int iterDepth(TreeIter iter)
300 	{
301 		return gtk_tree_store_iter_depth(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct());
302 	}
303 
304 	/**
305 	 * WARNING: This function is slow. Only use it for debugging and/or testing
306 	 * purposes.
307 	 *
308 	 * Checks if the given iter is a valid iter for this #GtkTreeStore.
309 	 *
310 	 * Params:
311 	 *     iter = A #GtkTreeIter.
312 	 *
313 	 * Returns: %TRUE if the iter is valid, %FALSE if the iter is invalid.
314 	 */
315 	public bool iterIsValid(TreeIter iter)
316 	{
317 		return gtk_tree_store_iter_is_valid(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct()) != 0;
318 	}
319 
320 	/**
321 	 * Moves @iter in @tree_store to the position after @position. @iter and
322 	 * @position should be in the same level. Note that this function only
323 	 * works with unsorted stores. If @position is %NULL, @iter will be moved
324 	 * to the start of the level.
325 	 *
326 	 * Params:
327 	 *     iter = A #GtkTreeIter.
328 	 *     position = A #GtkTreeIter.
329 	 */
330 	public void moveAfter(TreeIter iter, TreeIter position)
331 	{
332 		gtk_tree_store_move_after(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct());
333 	}
334 
335 	/**
336 	 * Moves @iter in @tree_store to the position before @position. @iter and
337 	 * @position should be in the same level. Note that this function only
338 	 * works with unsorted stores. If @position is %NULL, @iter will be
339 	 * moved to the end of the level.
340 	 *
341 	 * Params:
342 	 *     iter = A #GtkTreeIter.
343 	 *     position = A #GtkTreeIter or %NULL.
344 	 */
345 	public void moveBefore(TreeIter iter, TreeIter position)
346 	{
347 		gtk_tree_store_move_before(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct());
348 	}
349 
350 	/**
351 	 * Prepends a new row to @tree_store.  If @parent is non-%NULL, then it will prepend
352 	 * the new row before the first child of @parent, otherwise it will prepend a row
353 	 * to the top level.  @iter will be changed to point to this new row.  The row
354 	 * will be empty after this function is called.  To fill in values, you need to
355 	 * call gtk_tree_store_set() or gtk_tree_store_set_value().
356 	 *
357 	 * Params:
358 	 *     iter = An unset #GtkTreeIter to set to the prepended row
359 	 *     parent = A valid #GtkTreeIter, or %NULL
360 	 */
361 	public void prepend(out TreeIter iter, TreeIter parent)
362 	{
363 		GtkTreeIter* outiter = sliceNew!GtkTreeIter();
364 
365 		gtk_tree_store_prepend(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct());
366 
367 		iter = ObjectG.getDObject!(TreeIter)(outiter, true);
368 	}
369 
370 	/**
371 	 * Removes @iter from @tree_store.  After being removed, @iter is set to the
372 	 * next valid row at that level, or invalidated if it previously pointed to the
373 	 * last one.
374 	 *
375 	 * Params:
376 	 *     iter = A valid #GtkTreeIter
377 	 *
378 	 * Returns: %TRUE if @iter is still valid, %FALSE if not.
379 	 */
380 	public bool remove(TreeIter iter)
381 	{
382 		return gtk_tree_store_remove(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct()) != 0;
383 	}
384 
385 	/**
386 	 * Reorders the children of @parent in @tree_store to follow the order
387 	 * indicated by @new_order. Note that this function only works with
388 	 * unsorted stores.
389 	 *
390 	 * Params:
391 	 *     parent = A #GtkTreeIter, or %NULL
392 	 *     newOrder = an array of integers mapping the new position of each child
393 	 *         to its old position before the re-ordering,
394 	 *         i.e. @new_order`[newpos] = oldpos`.
395 	 */
396 	public void reorder(TreeIter parent, int[] newOrder)
397 	{
398 		gtk_tree_store_reorder(gtkTreeStore, (parent is null) ? null : parent.getTreeIterStruct(), newOrder.ptr);
399 	}
400 
401 	/**
402 	 * This function is meant primarily for #GObjects that inherit from
403 	 * #GtkTreeStore, and should only be used when constructing a new
404 	 * #GtkTreeStore.  It will not function after a row has been added,
405 	 * or a method on the #GtkTreeModel interface is called.
406 	 *
407 	 * Params:
408 	 *     types = An array of #GType types, one for each column
409 	 */
410 	public void setColumnTypes(GType[] types)
411 	{
412 		gtk_tree_store_set_column_types(gtkTreeStore, cast(int)types.length, types.ptr);
413 	}
414 
415 	/**
416 	 * See gtk_tree_store_set(); this version takes a va_list for
417 	 * use by language bindings.
418 	 *
419 	 * Params:
420 	 *     iter = A valid #GtkTreeIter for the row being modified
421 	 *     varArgs = va_list of column/value pairs
422 	 */
423 	public void setValist(TreeIter iter, void* varArgs)
424 	{
425 		gtk_tree_store_set_valist(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), varArgs);
426 	}
427 
428 	/**
429 	 * Sets the data in the cell specified by @iter and @column.
430 	 * The type of @value must be convertible to the type of the
431 	 * column.
432 	 *
433 	 * Params:
434 	 *     iter = A valid #GtkTreeIter for the row being modified
435 	 *     column = column number to modify
436 	 *     value = new value for the cell
437 	 */
438 	public void setValue(TreeIter iter, int column, Value value)
439 	{
440 		gtk_tree_store_set_value(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), column, (value is null) ? null : value.getValueStruct());
441 	}
442 
443 	/**
444 	 * A variant of gtk_tree_store_set_valist() which takes
445 	 * the columns and values as two arrays, instead of varargs.  This
446 	 * function is mainly intended for language bindings or in case
447 	 * the number of columns to change is not known until run-time.
448 	 *
449 	 * Params:
450 	 *     iter = A valid #GtkTreeIter for the row being modified
451 	 *     columns = an array of column numbers
452 	 *     values = an array of GValues
453 	 */
454 	public void setValuesv(TreeIter iter, int[] columns, Value[] values)
455 	{
456 		GValue[] valuesArray = new GValue[values.length];
457 		for ( int i = 0; i < values.length; i++ )
458 		{
459 			valuesArray[i] = *(values[i].getValueStruct());
460 		}
461 
462 		gtk_tree_store_set_valuesv(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), columns.ptr, valuesArray.ptr, cast(int)values.length);
463 	}
464 
465 	/**
466 	 * Swaps @a and @b in the same level of @tree_store. Note that this function
467 	 * only works with unsorted stores.
468 	 *
469 	 * Params:
470 	 *     a = A #GtkTreeIter.
471 	 *     b = Another #GtkTreeIter.
472 	 */
473 	public void swap(TreeIter a, TreeIter b)
474 	{
475 		gtk_tree_store_swap(gtkTreeStore, (a is null) ? null : a.getTreeIterStruct(), (b is null) ? null : b.getTreeIterStruct());
476 	}
477 }