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  * Conversion parameters:
26  * inFile  = GtkListStore.html
27  * outPack = gtk
28  * outFile = ListStore
29  * strct   = GtkListStore
30  * realStrct=
31  * ctorStrct=
32  * clss    = ListStore
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * 	- BuildableIF
40  * 	- TreeModelIF
41  * 	- TreeDragSourceIF
42  * 	- TreeDragDestIF
43  * 	- TreeSortableIF
44  * prefixes:
45  * 	- gtk_list_store_
46  * omit structs:
47  * omit prefixes:
48  * omit code:
49  * omit signals:
50  * imports:
51  * 	- glib.Str
52  * 	- gobject.Value
53  * 	- gtk.TreeIter
54  * 	- gtk.TreeModel
55  * 	- gtk.BuildableIF
56  * 	- gtk.BuildableT
57  * 	- gtk.TreeModelT
58  * 	- gtk.TreeModelIF
59  * 	- gtk.TreeDragSourceT
60  * 	- gtk.TreeDragSourceIF
61  * 	- gtk.TreeDragDestT
62  * 	- gtk.TreeDragDestIF
63  * 	- gtk.TreeSortableT
64  * 	- gtk.TreeSortableIF
65  * structWrap:
66  * 	- GValue* -> Value
67  * 	- GtkTreeIter* -> TreeIter
68  * module aliases:
69  * local aliases:
70  * overrides:
71  */
72 
73 module gtk.ListStore;
74 
75 public  import gtkc.gtktypes;
76 
77 private import gtkc.gtk;
78 private import glib.ConstructionException;
79 private import gobject.ObjectG;
80 
81 private import glib.Str;
82 private import gobject.Value;
83 private import gtk.TreeIter;
84 private import gtk.TreeModel;
85 private import gtk.BuildableIF;
86 private import gtk.BuildableT;
87 private import gtk.TreeModelT;
88 private import gtk.TreeModelIF;
89 private import gtk.TreeDragSourceT;
90 private import gtk.TreeDragSourceIF;
91 private import gtk.TreeDragDestT;
92 private import gtk.TreeDragDestIF;
93 private import gtk.TreeSortableT;
94 private import gtk.TreeSortableIF;
95 
96 
97 private import gobject.ObjectG;
98 
99 /**
100  * The GtkListStore object is a list model for use with a GtkTreeView
101  * widget. It implements the GtkTreeModel interface, and consequentialy,
102  * can use all of the methods available there. It also implements the
103  * GtkTreeSortable interface so it can be sorted by the view.
104  * Finally, it also implements the tree
105  * drag and drop
106  * interfaces.
107  *
108  * The GtkListStore can accept most GObject types as a column type, though
109  * it can't accept all custom types. Internally, it will keep a copy of
110  * data passed in (such as a string or a boxed pointer). Columns that
111  * accept GObjects are handled a little differently. The
112  * GtkListStore will keep a reference to the object instead of copying the
113  * value. As a result, if the object is modified, it is up to the
114  * application writer to call gtk_tree_model_row_changed() to emit the
115  * "row_changed" signal. This most commonly affects lists with
116  * GdkPixbufs stored.
117  *
118  * $(DDOC_COMMENT example)
119  *
120  * Performance Considerations
121  *
122  * Internally, the GtkListStore was implemented with a linked list with a
123  * tail pointer prior to GTK+ 2.6. As a result, it was fast at data
124  * insertion and deletion, and not fast at random data access. The
125  * GtkListStore sets the GTK_TREE_MODEL_ITERS_PERSIST flag, which means
126  * that GtkTreeIters can be cached while the row exists. Thus, if
127  * access to a particular row is needed often and your code is expected to
128  * run on older versions of GTK+, it is worth keeping the iter around.
129  *
130  * <hr>
131  *
132  * Atomic Operations
133  *
134  * It is important to note that only the methods
135  * gtk_list_store_insert_with_values() and gtk_list_store_insert_with_valuesv()
136  * are atomic, in the sense that the row is being appended to the store and the
137  * values filled in in a single operation with regard to GtkTreeModel signaling.
138  * In contrast, using e.g. gtk_list_store_append() and then gtk_list_store_set()
139  * will first create a row, which triggers the "row-inserted" signal
140  * on GtkListStore. The row, however, is still empty, and any signal handler
141  * connecting to "row-inserted" on this particular store should be prepared
142  * for the situation that the row might be empty. This is especially important
143  * if you are wrapping the GtkListStore inside a GtkTreeModelFilter and are
144  * using a GtkTreeModelFilterVisibleFunc. Using any of the non-atomic operations
145  * to append rows to the GtkListStore will cause the
146  * GtkTreeModelFilterVisibleFunc to be visited with an empty row first; the
147  * function must be prepared for that.
148  *
149  * <hr>
150  *
151  * GtkListStore as GtkBuildable
152  *
153  * The GtkListStore implementation of the GtkBuildable interface allows
154  * to specify the model columns with a &lt;columns&gt; element that may
155  * contain multiple &lt;column&gt; elements, each specifying one model
156  * column. The "type" attribute specifies the data type for the column.
157  *
158  * Additionally, it is possible to specify content for the list store
159  * in the UI definition, with the &lt;data&gt; element. It can contain
160  * multiple &lt;row&gt; elements, each specifying to content for one
161  * row of the list model. Inside a &lt;row&gt;, the &lt;col&gt; elements
162  * specify the content for individual cells.
163  *
164  * Note that it is probably more common to define your models
165  * in the code, and one might consider it a layering violation
166  * to specify the content of a list store in a UI definition,
167  * data, not presentation,
168  * and common wisdom is to separate the two, as far as possible.
169  *
170  * $(DDOC_COMMENT example)
171  */
172 public class ListStore : ObjectG, BuildableIF, TreeModelIF, TreeDragSourceIF, TreeDragDestIF, TreeSortableIF
173 {
174 	
175 	/** the main Gtk struct */
176 	protected GtkListStore* gtkListStore;
177 	
178 	
179 	/** Get the main Gtk struct */
180 	public GtkListStore* getListStoreStruct()
181 	{
182 		return gtkListStore;
183 	}
184 	
185 	
186 	/** the main Gtk struct as a void* */
187 	protected override void* getStruct()
188 	{
189 		return cast(void*)gtkListStore;
190 	}
191 	
192 	/**
193 	 * Sets our main struct and passes it to the parent class
194 	 */
195 	public this (GtkListStore* gtkListStore)
196 	{
197 		super(cast(GObject*)gtkListStore);
198 		this.gtkListStore = gtkListStore;
199 	}
200 	
201 	protected override void setStruct(GObject* obj)
202 	{
203 		super.setStruct(obj);
204 		gtkListStore = cast(GtkListStore*)obj;
205 	}
206 	
207 	// add the Buildable capabilities
208 	mixin BuildableT!(GtkListStore);
209 	
210 	// add the TreeModel capabilities
211 	mixin TreeModelT!(GtkListStore);
212 	
213 	// add the TreeDragSource capabilities
214 	mixin TreeDragSourceT!(GtkListStore);
215 	
216 	// add the TreeDragDest capabilities
217 	mixin TreeDragDestT!(GtkListStore);
218 	
219 	// add the TreeSortable capabilities
220 	mixin TreeSortableT!(GtkListStore);
221 	
222 	/**
223 	 * Creates a top level iteractor.
224 	 * I don't think lists have but the top level iteractor
225 	 */
226 	TreeIter createIter()
227 	{
228 		GtkTreeIter* iter = new GtkTreeIter;
229 		gtk_list_store_append(getListStoreStruct(), iter);
230 		return new TreeIter(iter);
231 	}
232 	
233 	/**
234 	 * sets the values for one row
235 	 * Params:
236 	 *  iter = the row iteractor
237 	 *  columns = an arrays with the columns to set
238 	 *  values = an arrays with the values
239 	 */
240 	void set(TreeIter iter, int[] columns, char*[] values)
241 	{
242 		for ( int i=0 ; i<columns.length && i<values.length; i++ )
243 		{
244 			gtk_list_store_set(
245 			gtkListStore,
246 			iter.getTreeIterStruct(),
247 			columns[i],
248 			values[i],-1);
249 		}
250 	}
251 	
252 	/** ditto */
253 	void set(TreeIter iter, int[] columns, string[] values)
254 	{
255 		for ( int i=0 ; i<columns.length && i<values.length; i++ )
256 		{
257 			gtk_list_store_set(
258 			gtkListStore,
259 			iter.getTreeIterStruct(),
260 			columns[i],
261 			Str.toStringz(values[i]),-1);
262 		}
263 	}
264 	
265 	/** */
266 	void setValue(TreeIter iter, int column, string value)
267 	{
268 		Value v = new Value(value);
269 		gtk_list_store_set_value(gtkListStore, iter.getTreeIterStruct(), column, v.getValueStruct());
270 		//gtk_list_store_set_value(obj(), iter.getIter(), column, (GValue*)cChar(value));
271 	}
272 	
273 	/** */
274 	void setValue(TreeIter iter, int column, int value)
275 	{
276 		Value v = new Value(value);
277 		gtk_list_store_set_value(gtkListStore, iter.getTreeIterStruct(), column, v.getValueStruct());
278 	}
279 	
280 	/**
281 	 */
282 	
283 	/**
284 	 * Non-vararg creation function. Used primarily by language bindings.
285 	 * Params:
286 	 * types = an array of GType types for the columns, from first to last. [array length=n_columns]
287 	 * Throws: ConstructionException GTK+ fails to create the object.
288 	 */
289 	public this (GType[] types)
290 	{
291 		// GtkListStore * gtk_list_store_newv (gint n_columns,  GType *types);
292 		auto p = gtk_list_store_newv(cast(int) types.length, types.ptr);
293 		if(p is null)
294 		{
295 			throw new ConstructionException("null returned by gtk_list_store_newv(cast(int) types.length, types.ptr)");
296 		}
297 		this(cast(GtkListStore*) p);
298 	}
299 	
300 	/**
301 	 * This function is meant primarily for GObjects that inherit from GtkListStore,
302 	 * and should only be used when constructing a new GtkListStore. It will not
303 	 * function after a row has been added, or a method on the GtkTreeModel
304 	 * interface is called.
305 	 * Params:
306 	 * types = An array length n of GTypes. [array length=n_columns]
307 	 */
308 	public void setColumnTypes(GType[] types)
309 	{
310 		// void gtk_list_store_set_column_types (GtkListStore *list_store,  gint n_columns,  GType *types);
311 		gtk_list_store_set_column_types(gtkListStore, cast(int) types.length, types.ptr);
312 	}
313 	
314 	/**
315 	 * See gtk_list_store_set(); this version takes a va_list for use by language
316 	 * bindings.
317 	 * Params:
318 	 * iter = A valid GtkTreeIter for the row being modified
319 	 * varArgs = va_list of column/value pairs
320 	 */
321 	public void setValist(TreeIter iter, void* varArgs)
322 	{
323 		// void gtk_list_store_set_valist (GtkListStore *list_store,  GtkTreeIter *iter,  va_list var_args);
324 		gtk_list_store_set_valist(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), varArgs);
325 	}
326 	
327 	/**
328 	 * Sets the data in the cell specified by iter and column.
329 	 * The type of value must be convertible to the type of the
330 	 * column.
331 	 * Params:
332 	 * iter = A valid GtkTreeIter for the row being modified
333 	 * column = column number to modify
334 	 * value = new value for the cell
335 	 */
336 	public void setValue(TreeIter iter, int column, Value value)
337 	{
338 		// void gtk_list_store_set_value (GtkListStore *list_store,  GtkTreeIter *iter,  gint column,  GValue *value);
339 		gtk_list_store_set_value(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), column, (value is null) ? null : value.getValueStruct());
340 	}
341 	
342 	/**
343 	 * A variant of gtk_list_store_set_valist() which
344 	 * takes the columns and values as two arrays, instead of
345 	 * varargs. This function is mainly intended for
346 	 * language-bindings and in case the number of columns to
347 	 * change is not known until run-time.
348 	 * Since 2.12
349 	 * Params:
350 	 * iter = A valid GtkTreeIter for the row being modified
351 	 * columns = an array of column numbers. [array length=n_values]
352 	 * values = an array of GValues. [array length=n_values]
353 	 */
354 	public void setValuesv(TreeIter iter, int[] columns, GValue[] values)
355 	{
356 		// void gtk_list_store_set_valuesv (GtkListStore *list_store,  GtkTreeIter *iter,  gint *columns,  GValue *values,  gint n_values);
357 		gtk_list_store_set_valuesv(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), columns.ptr, values.ptr, cast(int) columns.length);
358 	}
359 	
360 	/**
361 	 * Removes the given row from the list store. After being removed,
362 	 * iter is set to be the next valid row, or invalidated if it pointed
363 	 * to the last row in list_store.
364 	 * Params:
365 	 * iter = A valid GtkTreeIter
366 	 * Returns: TRUE if iter is valid, FALSE if not.
367 	 */
368 	public int remove(TreeIter iter)
369 	{
370 		// gboolean gtk_list_store_remove (GtkListStore *list_store,  GtkTreeIter *iter);
371 		return gtk_list_store_remove(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
372 	}
373 	
374 	/**
375 	 * Creates a new row at position. iter will be changed to point to this new
376 	 * row. If position is -1 or is larger than the number of rows on the list,
377 	 * then the new row will be appended to the list. The row will be empty after
378 	 * this function is called. To fill in values, you need to call
379 	 * gtk_list_store_set() or gtk_list_store_set_value().
380 	 * Params:
381 	 * iter = An unset GtkTreeIter to set to the new row. [out]
382 	 * position = position to insert the new row, or -1 for last
383 	 */
384 	public void insert(TreeIter iter, int position)
385 	{
386 		// void gtk_list_store_insert (GtkListStore *list_store,  GtkTreeIter *iter,  gint position);
387 		gtk_list_store_insert(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), position);
388 	}
389 	
390 	/**
391 	 * Inserts a new row before sibling. If sibling is NULL, then the row will
392 	 * be appended to the end of the list. iter will be changed to point to this
393 	 * new row. The row will be empty after this function is called. To fill in
394 	 * values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
395 	 * Params:
396 	 * iter = An unset GtkTreeIter to set to the new row. [out]
397 	 * sibling = A valid GtkTreeIter, or NULL. [allow-none]
398 	 */
399 	public void insertBefore(TreeIter iter, TreeIter sibling)
400 	{
401 		// void gtk_list_store_insert_before (GtkListStore *list_store,  GtkTreeIter *iter,  GtkTreeIter *sibling);
402 		gtk_list_store_insert_before(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (sibling is null) ? null : sibling.getTreeIterStruct());
403 	}
404 	
405 	/**
406 	 * Inserts a new row after sibling. If sibling is NULL, then the row will be
407 	 * prepended to the beginning of the list. iter will be changed to point to
408 	 * this new row. The row will be empty after this function is called. To fill
409 	 * in values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
410 	 * Params:
411 	 * iter = An unset GtkTreeIter to set to the new row. [out]
412 	 * sibling = A valid GtkTreeIter, or NULL. [allow-none]
413 	 */
414 	public void insertAfter(TreeIter iter, TreeIter sibling)
415 	{
416 		// void gtk_list_store_insert_after (GtkListStore *list_store,  GtkTreeIter *iter,  GtkTreeIter *sibling);
417 		gtk_list_store_insert_after(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (sibling is null) ? null : sibling.getTreeIterStruct());
418 	}
419 	
420 	/**
421 	 * A variant of gtk_list_store_insert_with_values() which
422 	 * takes the columns and values as two arrays, instead of
423 	 * varargs. This function is mainly intended for
424 	 * language-bindings.
425 	 * Since 2.6
426 	 * Params:
427 	 * iter = An unset GtkTreeIter to set to the new row, or NULL. [out][allow-none]
428 	 * position = position to insert the new row, or -1 for last
429 	 * columns = an array of column numbers. [array length=n_values]
430 	 * values = an array of GValues. [array length=n_values]
431 	 */
432 	public void insertWithValuesv(TreeIter iter, int position, int[] columns, GValue[] values)
433 	{
434 		// void gtk_list_store_insert_with_valuesv (GtkListStore *list_store,  GtkTreeIter *iter,  gint position,  gint *columns,  GValue *values,  gint n_values);
435 		gtk_list_store_insert_with_valuesv(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), position, columns.ptr, values.ptr, cast(int) columns.length);
436 	}
437 	
438 	/**
439 	 * Prepends a new row to list_store. iter will be changed to point to this new
440 	 * row. The row will be empty after this function is called. To fill in
441 	 * values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
442 	 * Params:
443 	 * iter = An unset GtkTreeIter to set to the prepend row. [out]
444 	 */
445 	public void prepend(TreeIter iter)
446 	{
447 		// void gtk_list_store_prepend (GtkListStore *list_store,  GtkTreeIter *iter);
448 		gtk_list_store_prepend(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
449 	}
450 	
451 	/**
452 	 * Appends a new row to list_store. iter will be changed to point to this new
453 	 * row. The row will be empty after this function is called. To fill in
454 	 * values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
455 	 * Params:
456 	 * iter = An unset GtkTreeIter to set to the appended row. [out]
457 	 */
458 	public void append(TreeIter iter)
459 	{
460 		// void gtk_list_store_append (GtkListStore *list_store,  GtkTreeIter *iter);
461 		gtk_list_store_append(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
462 	}
463 	
464 	/**
465 	 * Removes all rows from the list store.
466 	 */
467 	public void clear()
468 	{
469 		// void gtk_list_store_clear (GtkListStore *list_store);
470 		gtk_list_store_clear(gtkListStore);
471 	}
472 	
473 	/**
474 	 * Warning
475 	 * This function is slow. Only use it for debugging and/or testing
476 	 * purposes.
477 	 * Checks if the given iter is a valid iter for this GtkListStore.
478 	 * Since 2.2
479 	 * Params:
480 	 * iter = A GtkTreeIter.
481 	 * Returns: TRUE if the iter is valid, FALSE if the iter is invalid.
482 	 */
483 	public int iterIsValid(TreeIter iter)
484 	{
485 		// gboolean gtk_list_store_iter_is_valid (GtkListStore *list_store,  GtkTreeIter *iter);
486 		return gtk_list_store_iter_is_valid(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
487 	}
488 	
489 	/**
490 	 * Reorders store to follow the order indicated by new_order. Note that
491 	 * this function only works with unsorted stores.
492 	 * Since 2.2
493 	 * Params:
494 	 * newOrder = an array of integers mapping the new
495 	 * position of each child to its old position before the re-ordering,
496 	 * i.e. new_order[newpos] = oldpos. It must have
497 	 * exactly as many items as the list store's length. [array zero-terminated=1]
498 	 */
499 	public void reorder(int[] newOrder)
500 	{
501 		// void gtk_list_store_reorder (GtkListStore *store,  gint *new_order);
502 		gtk_list_store_reorder(gtkListStore, newOrder.ptr);
503 	}
504 	
505 	/**
506 	 * Swaps a and b in store. Note that this function only works with
507 	 * unsorted stores.
508 	 * Since 2.2
509 	 * Params:
510 	 * a = A GtkTreeIter.
511 	 * b = Another GtkTreeIter.
512 	 */
513 	public void swap(TreeIter a, TreeIter b)
514 	{
515 		// void gtk_list_store_swap (GtkListStore *store,  GtkTreeIter *a,  GtkTreeIter *b);
516 		gtk_list_store_swap(gtkListStore, (a is null) ? null : a.getTreeIterStruct(), (b is null) ? null : b.getTreeIterStruct());
517 	}
518 	
519 	/**
520 	 * Moves iter in store to the position before position. Note that this
521 	 * function only works with unsorted stores. If position is NULL, iter
522 	 * will be moved to the end of the list.
523 	 * Since 2.2
524 	 * Params:
525 	 * iter = A GtkTreeIter.
526 	 * position = A GtkTreeIter, or NULL. [allow-none]
527 	 */
528 	public void moveBefore(TreeIter iter, TreeIter position)
529 	{
530 		// void gtk_list_store_move_before (GtkListStore *store,  GtkTreeIter *iter,  GtkTreeIter *position);
531 		gtk_list_store_move_before(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct());
532 	}
533 	
534 	/**
535 	 * Moves iter in store to the position after position. Note that this
536 	 * function only works with unsorted stores. If position is NULL, iter
537 	 * will be moved to the start of the list.
538 	 * Since 2.2
539 	 * Params:
540 	 * iter = A GtkTreeIter.
541 	 * position = A GtkTreeIter or NULL. [allow-none]
542 	 */
543 	public void moveAfter(TreeIter iter, TreeIter position)
544 	{
545 		// void gtk_list_store_move_after (GtkListStore *store,  GtkTreeIter *iter,  GtkTreeIter *position);
546 		gtk_list_store_move_after(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct());
547 	}
548 }