alternative to assert
[gtkD.git] / gtkD / src / gtk / ListStore.d
blob226b44f14bc0426d5c3f47b8952f75a588fd5f31
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkListStore.html
26 * outPack = gtk
27 * outFile = ListStore
28 * strct = GtkListStore
29 * realStrct=
30 * ctorStrct=
31 * clss = ListStore
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend = GtkTreeModel
37 * implements:
38 * prefixes:
39 * - gtk_list_store_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * - gtk_list_store_set
45 * imports:
46 * - gtk.TreeModel
47 * - glib.Str
48 * - gtk.TreeIter
49 * - gobject.Value
50 * - glib.Str
51 * structWrap:
52 * - GValue* -> Value
53 * - GtkTreeIter* -> TreeIter
54 * module aliases:
55 * local aliases:
58 module gtk.ListStore;
60 version(noAssert)
62 version(Tango)
64 import tango.io.Stdout; // use the tango loging?
68 private import gtkc.gtktypes;
70 private import gtkc.gtk;
73 private import gtk.TreeModel;
74 private import glib.Str;
75 private import gtk.TreeIter;
76 private import gobject.Value;
77 private import glib.Str;
82 /**
83 * Description
84 * The GtkListStore object is a list model for use with a GtkTreeView
85 * widget. It implements the GtkTreeModel interface, and consequentialy,
86 * can use all of the methods available there. It also implements the
87 * GtkTreeSortable interface so it can be sorted by the view.
88 * Finally, it also implements the tree drag and
89 * drop interfaces.
90 * The GtkListStore can accept most GObject types as a column type, though
91 * it can't accept all custom types. Internally, it will keep a copy of
92 * data passed in (such as a string or a boxed pointer). Columns that
93 * accept GObjects are handled a little differently. The
94 * GtkListStore will keep a reference to the object instead of copying the
95 * value. As a result, if the object is modified, it is up to the
96 * application writer to call gtk_tree_model_row_changed to emit the
97 * "row_changed" signal. This most commonly affects lists with
98 * GdkPixbufs stored.
99 * Example5.Creating a simple list store.
100 * enum {
101 * COLUMN_STRING,
102 * COLUMN_INT,
103 * COLUMN_BOOLEAN,
104 * N_COLUMNS
105 * };
107 * GtkListStore *list_store;
108 * GtkTreePath *path;
109 * GtkTreeIter iter;
110 * gint i;
111 * list_store = gtk_list_store_new (N_COLUMNS,
112 * G_TYPE_STRING,
113 * G_TYPE_INT,
114 * G_TYPE_BOOLEAN);
115 * for (i = 0; i < 10; i++)
117 * gchar *some_data;
118 * some_data = get_some_data (i);
119 * /+* Add a new row to the model +/
120 * gtk_list_store_append (list_store, iter);
121 * gtk_list_store_set (list_store, iter,
122 * COLUMN_STRING, some_data,
123 * COLUMN_INT, i,
124 * COLUMN_BOOLEAN, FALSE,
125 * -1);
126 * /+* As the store will keep a copy of the string internally, we
127 * * free some_data.
128 * +/
129 * g_free (some_data);
131 * /+* Modify a particular row +/
132 * path = gtk_tree_path_new_from_string ("4");
133 * gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store),
134 * iter,
135 * path);
136 * gtk_tree_path_free (path);
137 * gtk_list_store_set (list_store, iter,
138 * COLUMN_BOOLEAN, TRUE,
139 * -1);
141 * Performance Considerations
142 * Internally, the GtkListStore was implemented with a linked list with a
143 * tail pointer prior to GTK+ 2.6. As a result, it was fast at data
144 * insertion and deletion, and not fast at random data access. The
145 * GtkListStore sets the GTK_TREE_MODEL_ITERS_PERSIST flag, which means
146 * that GtkTreeIters can be cached while the row exists. Thus, if
147 * access to a particular row is needed often and your code is expected to
148 * run on older versions of GTK+, it is worth keeping the iter around.
149 * Atomic Operations
150 * It is important to note that only the methods gtk_list_store_insert_with_values and
151 * gtk_list_store_insert_with_valuesv are atomic, in the sense that the row is being appended
152 * to the store and the values filled in in a single operation with regard to GtkTreeModel signaling.
153 * In contrast, using e.g. gtk_list_store_append and then gtk_list_store_set will first create a row,
154 * which triggers the "row_inserted" GtkTreeModel signal on GtkListStore. The row, however, is still
155 * empty, and any signal handler connecting to "row_inserted" on this particular store should be prepared
156 * for the situation that the row might be empty.
157 * This is especially important if you are wrapping the GtkListStore inside a GtkTreeModelFilter and are
158 * using a GtkTreeModelFilterVisibleFunc. Using any of the non-atomic operations to append rows to the GtkListStore
159 * will cause the GtkTreeModelFilterVisibleFunc to be visited with an empty row first; the function must be prepared for that.
161 private import gtk.TreeModel;
162 public class ListStore : TreeModel
165 /** the main Gtk struct */
166 protected GtkListStore* gtkListStore;
169 public GtkListStore* getListStoreStruct()
171 return gtkListStore;
175 /** the main Gtk struct as a void* */
176 protected void* getStruct()
178 return cast(void*)gtkListStore;
182 * Sets our main struct and passes it to the parent class
184 public this (GtkListStore* gtkListStore)
186 version(noAssert)
188 if ( gtkListStore is null )
190 int zero = 0;
191 version(Tango)
193 Stdout("struct gtkListStore is null on constructor").newline;
195 else
197 printf("struct gtkListStore is null on constructor");
199 zero = zero / zero;
202 else
204 assert(gtkListStore !is null, "struct gtkListStore is null on constructor");
206 super(cast(GtkTreeModel*)gtkListStore);
207 this.gtkListStore = gtkListStore;
211 * Non-vararg creation function. Used primarily by language bindings.
212 * n_columns:
213 * number of columns in the list store
214 * types:
215 * an array of GType types for the columns, from first to last
216 * Returns:
217 * a new GtkListStore
219 public this (GType[] types)
221 // GtkListStore* gtk_list_store_newv (gint n_columns, GType *types);
222 this(cast(GtkListStore*)gtk_list_store_newv(types.length, cast(GType*)(types.ptr)) );
226 * Creates a top level iteractor.
227 * I don't think lists have but the top level iteractor
229 TreeIter createIter()
231 GtkTreeIter* iter = new GtkTreeIter;
232 gtk_list_store_append(getListStoreStruct(), iter);
233 return new TreeIter(iter);
237 * sets the values for one row
238 * @param iter the row iteractor
239 * @param columns an arrays with the columns to set
240 * @param values an arrays with the values
242 void set(TreeIter iter, int [] columns, char*[] values)
244 for ( int i=0 ; i<columns.length && i<values.length; i++ )
246 //Value v = new Value(values[i]);
247 //gtk_list_store_set(obj(), iter.getIter(), columns[i], v.getV(),-1);
248 gtk_list_store_set(
249 gtkListStore,
250 iter.getTreeIterStruct(),
251 columns[i],
252 values[i],-1);
256 void set(TreeIter iter, int [] columns, char[][] values)
258 for ( int i=0 ; i<columns.length && i<values.length; i++ )
260 //Value v = new Value(values[i]);
261 //gtk_list_store_set(obj(), iter.getIter(), columns[i], v.getV(),-1);
262 gtk_list_store_set(
263 gtkListStore,
264 iter.getTreeIterStruct(),
265 columns[i],
266 Str.toStringz(values[i]),-1);
270 void setValue(TreeIter iter, int column, char[] value)
272 Value v = new Value(value);
273 gtk_list_store_set_value(gtkListStore, iter.getTreeIterStruct(), column, v.getValueStruct());
274 //gtk_list_store_set_value(obj(), iter.getIter(), column, (GValue*)cChar(value));
277 void setValue(TreeIter iter, int column, int value)
279 Value v = new Value(value);
280 gtk_list_store_set_value(gtkListStore, iter.getTreeIterStruct(), column, v.getValueStruct());
288 * Creates a new list store as with n_columns columns each of the types passed
289 * in. Note that only types derived from standard GObject fundamental types
290 * are supported.
291 * As an example, gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING,
292 * GDK_TYPE_PIXBUF); will create a new GtkListStore with three columns, of type
293 * int, string and GdkPixbuf respectively.
294 * n_columns:
295 * number of columns in the list store
296 * ...:
297 * all GType types for the columns, from first to last
298 * Returns:
299 * a new GtkListStore
301 public this (int nColumns, ... )
303 // GtkListStore* gtk_list_store_new (gint n_columns, ...);
304 this(cast(GtkListStore*)gtk_list_store_new(nColumns) );
308 * Non-vararg creation function. Used primarily by language bindings.
309 * n_columns:
310 * number of columns in the list store
311 * types:
312 * an array of GType types for the columns, from first to last
313 * Returns:
314 * a new GtkListStore
316 public this (int nColumns, GType* types)
318 // GtkListStore* gtk_list_store_newv (gint n_columns, GType *types);
319 this(cast(GtkListStore*)gtk_list_store_newv(nColumns, types) );
323 * This function is meant primarily for GObjects that inherit from GtkListStore,
324 * and should only be used when constructing a new GtkListStore. It will not
325 * function after a row has been added, or a method on the GtkTreeModel
326 * interface is called.
327 * list_store:
328 * A GtkListStore
329 * n_columns:
330 * Number of columns for the list store
331 * types:
332 * An array length n of GTypes
334 public void setColumnTypes(int nColumns, GType* types)
336 // void gtk_list_store_set_column_types (GtkListStore *list_store, gint n_columns, GType *types);
337 gtk_list_store_set_column_types(gtkListStore, nColumns, types);
342 * See gtk_list_store_set(); this version takes a va_list for use by language
343 * bindings.
344 * list_store:
345 * A GtkListStore
346 * iter:
347 * A valid GtkTreeIter for the row being modified
348 * var_args:
349 * va_list of column/value pairs
351 public void setValist(TreeIter iter, void* varArgs)
353 // void gtk_list_store_set_valist (GtkListStore *list_store, GtkTreeIter *iter, va_list var_args);
354 gtk_list_store_set_valist(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), varArgs);
358 * Sets the data in the cell specified by iter and column.
359 * The type of value must be convertible to the type of the
360 * column.
361 * list_store:
362 * A GtkListStore
363 * iter:
364 * A valid GtkTreeIter for the row being modified
365 * column:
366 * column number to modify
367 * value:
368 * new value for the cell
370 public void setValue(TreeIter iter, int column, Value value)
372 // void gtk_list_store_set_value (GtkListStore *list_store, GtkTreeIter *iter, gint column, GValue *value);
373 gtk_list_store_set_value(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), column, (value is null) ? null : value.getValueStruct());
377 * Removes the given row from the list store. After being removed,
378 * iter is set to be the next valid row, or invalidated if it pointed
379 * to the last row in list_store.
380 * list_store:
381 * A GtkListStore
382 * iter:
383 * A valid GtkTreeIter
384 * Returns:
385 * TRUE if iter is valid, FALSE if not.
387 public int remove(TreeIter iter)
389 // gboolean gtk_list_store_remove (GtkListStore *list_store, GtkTreeIter *iter);
390 return gtk_list_store_remove(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
394 * Creates a new row at position. iter will be changed to point to this new
395 * row. If position is larger than the number of rows on the list, then the
396 * new row will be appended to the list. The row will be empty after this
397 * function is called. To fill in values, you need to call
398 * gtk_list_store_set() or gtk_list_store_set_value().
399 * list_store:
400 * A GtkListStore
401 * iter:
402 * An unset GtkTreeIter to set to the new row
403 * position:
404 * position to insert the new row
406 public void insert(TreeIter iter, int position)
408 // void gtk_list_store_insert (GtkListStore *list_store, GtkTreeIter *iter, gint position);
409 gtk_list_store_insert(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), position);
413 * Inserts a new row before sibling. If sibling is NULL, then the row will
414 * be appended to the end of the list. iter will be changed to point to this
415 * new row. The row will be empty after this function is called. To fill in
416 * values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
417 * list_store:
418 * A GtkListStore
419 * iter:
420 * An unset GtkTreeIter to set to the new row
421 * sibling:
422 * A valid GtkTreeIter, or NULL
424 public void insertBefore(TreeIter iter, TreeIter sibling)
426 // void gtk_list_store_insert_before (GtkListStore *list_store, GtkTreeIter *iter, GtkTreeIter *sibling);
427 gtk_list_store_insert_before(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (sibling is null) ? null : sibling.getTreeIterStruct());
431 * Inserts a new row after sibling. If sibling is NULL, then the row will be
432 * prepended to the beginning of the list. iter will be changed to point to
433 * this new row. The row will be empty after this function is called. To fill
434 * in values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
435 * list_store:
436 * A GtkListStore
437 * iter:
438 * An unset GtkTreeIter to set to the new row
439 * sibling:
440 * A valid GtkTreeIter, or NULL
442 public void insertAfter(TreeIter iter, TreeIter sibling)
444 // void gtk_list_store_insert_after (GtkListStore *list_store, GtkTreeIter *iter, GtkTreeIter *sibling);
445 gtk_list_store_insert_after(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (sibling is null) ? null : sibling.getTreeIterStruct());
449 * Creates a new row at position. iter will be changed to point to this new
450 * row. If position is larger than the number of rows on the list, then the
451 * new row will be appended to the list. The row will be filled with the
452 * values given to this function.
453 * Calling
454 * gtk_list_store_insert_with_values(list_store, iter, position...)
455 * has the same effect as calling
456 * gtk_list_store_insert (list_store, iter, position);
457 * gtk_list_store_set (list_store, iter, ...);
458 * with the difference that the former will only emit a row_inserted signal,
459 * while the latter will emit row_inserted, row_changed and, if the list store
460 * is sorted, rows_reordered. Since emitting the rows_reordered signal
461 * repeatedly can affect the performance of the program,
462 * gtk_list_store_insert_with_values() should generally be preferred when
463 * inserting rows in a sorted list store.
464 * list_store:
465 * A GtkListStore
466 * iter:
467 * An unset GtkTreeIter to set to the new row, or NULL.
468 * position:
469 * position to insert the new row
470 * ...:
471 * pairs of column number and value, terminated with -1
472 * Since 2.6
474 public void insertWithValues(TreeIter iter, int position, ... )
476 // void gtk_list_store_insert_with_values (GtkListStore *list_store, GtkTreeIter *iter, gint position, ...);
477 gtk_list_store_insert_with_values(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), position);
481 * A variant of gtk_list_store_insert_with_values() which
482 * takes the columns and values as two arrays, instead of
483 * varargs. This function is mainly intended for
484 * language-bindings.
485 * list_store:
486 * A GtkListStore
487 * iter:
488 * An unset GtkTreeIter to set to the new row, or NULL.
489 * position:
490 * position to insert the new row
491 * columns:
492 * an array of column numbers
493 * values:
494 * an array of GValues
495 * n_values:
496 * the length of the columns and values arrays
497 * Since 2.6
499 public void insertWithValuesv(TreeIter iter, int position, int* columns, Value values, int nValues)
501 // void gtk_list_store_insert_with_valuesv (GtkListStore *list_store, GtkTreeIter *iter, gint position, gint *columns, GValue *values, gint n_values);
502 gtk_list_store_insert_with_valuesv(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), position, columns, (values is null) ? null : values.getValueStruct(), nValues);
506 * Prepends a new row to list_store. iter will be changed to point to this new
507 * row. The row will be empty after this function is called. To fill in
508 * values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
509 * list_store:
510 * A GtkListStore
511 * iter:
512 * An unset GtkTreeIter to set to the prepend row
514 public void prepend(TreeIter iter)
516 // void gtk_list_store_prepend (GtkListStore *list_store, GtkTreeIter *iter);
517 gtk_list_store_prepend(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
521 * Appends a new row to list_store. iter will be changed to point to this new
522 * row. The row will be empty after this function is called. To fill in
523 * values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
524 * list_store:
525 * A GtkListStore
526 * iter:
527 * An unset GtkTreeIter to set to the appended row
529 public void append(TreeIter iter)
531 // void gtk_list_store_append (GtkListStore *list_store, GtkTreeIter *iter);
532 gtk_list_store_append(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
536 * Removes all rows from the list store.
537 * list_store:
538 * a GtkListStore.
540 public void clear()
542 // void gtk_list_store_clear (GtkListStore *list_store);
543 gtk_list_store_clear(gtkListStore);
547 * Warning
548 * This function is slow. Only use it for debugging and/or testing
549 * purposes.
550 * Checks if the given iter is a valid iter for this GtkListStore.
551 * list_store:
552 * A GtkListStore.
553 * iter:
554 * A GtkTreeIter.
555 * Returns:
556 * TRUE if the iter is valid, FALSE if the iter is invalid.
557 * Since 2.2
559 public int iterIsValid(TreeIter iter)
561 // gboolean gtk_list_store_iter_is_valid (GtkListStore *list_store, GtkTreeIter *iter);
562 return gtk_list_store_iter_is_valid(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
566 * Reorders store to follow the order indicated by new_order. Note that
567 * this function only works with unsorted stores.
568 * store:
569 * A GtkListStore.
570 * new_order:
571 * an array of integers mapping the new position of each child
572 * to its old position before the re-ordering,
573 * i.e. new_order[newpos] = oldpos.
574 * Since 2.2
576 public void reorder(int* newOrder)
578 // void gtk_list_store_reorder (GtkListStore *store, gint *new_order);
579 gtk_list_store_reorder(gtkListStore, newOrder);
583 * Swaps a and b in store. Note that this function only works with
584 * unsorted stores.
585 * store:
586 * A GtkListStore.
587 * a:
588 * A GtkTreeIter.
589 * b:
590 * Another GtkTreeIter.
591 * Since 2.2
593 public void swap(TreeIter a, TreeIter b)
595 // void gtk_list_store_swap (GtkListStore *store, GtkTreeIter *a, GtkTreeIter *b);
596 gtk_list_store_swap(gtkListStore, (a is null) ? null : a.getTreeIterStruct(), (b is null) ? null : b.getTreeIterStruct());
600 * Moves iter in store to the position before position. Note that this
601 * function only works with unsorted stores. If position is NULL, iter
602 * will be moved to the end of the list.
603 * store:
604 * A GtkListStore.
605 * iter:
606 * A GtkTreeIter.
607 * position:
608 * A GtkTreeIter, or NULL.
609 * Since 2.2
611 public void moveBefore(TreeIter iter, TreeIter position)
613 // void gtk_list_store_move_before (GtkListStore *store, GtkTreeIter *iter, GtkTreeIter *position);
614 gtk_list_store_move_before(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct());
618 * Moves iter in store to the position after position. Note that this
619 * function only works with unsorted stores. If position is NULL, iter
620 * will be moved to the start of the list.
621 * store:
622 * A GtkListStore.
623 * iter:
624 * A GtkTreeIter.
625 * position:
626 * A GtkTreeIter or NULL.
627 * Since 2.2
628 * See Also
629 * GtkTreeModel, GtkTreeStore
631 public void moveAfter(TreeIter iter, TreeIter position)
633 // void gtk_list_store_move_after (GtkListStore *store, GtkTreeIter *iter, GtkTreeIter *position);
634 gtk_list_store_move_after(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct());