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