alternative to assert
[gtkD.git] / src / gtk / ListStore.d
blobe47ac23fb111f22d4eb5d460abaab9341360f9ec
1 /*
2 * This file is part of duit.
4 * duit 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 * duit 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 duit; 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 * local aliases:
57 module gtk.ListStore;
59 private import gtk.gtktypes;
61 private import lib.gtk;
63 private import gtk.TreeModel;
64 private import glib.Str;
65 private import gtk.TreeIter;
66 private import gobject.Value;
67 private import glib.Str;
69 /**
70 * Description
71 * The GtkListStore object is a list model for use with a GtkTreeView
72 * widget. It implements the GtkTreeModel interface, and consequentialy,
73 * can use all of the methods available there. It also implements the
74 * GtkTreeSortable interface so it can be sorted by the view.
75 * Finally, it also implements the tree drag and
76 * drop interfaces.
77 * The GtkListStore can accept most GObject types as a column type, though
78 * it can't accept all custom types. Internally, it will keep a copy of
79 * data passed in (such as a string or a boxed pointer). Columns that
80 * accept GObjects are handled a little differently. The
81 * GtkListStore will keep a reference to the object instead of copying the
82 * value. As a result, if the object is modified, it is up to the
83 * application writer to call gtk_tree_model_row_changed to emit the
84 * "row_changed" signal. This most commonly affects lists with
85 * GdkPixbufs stored.
86 * Example5.Creating a simple list store.
87 * enum {
88 * COLUMN_STRING,
89 * COLUMN_INT,
90 * COLUMN_BOOLEAN,
91 * N_COLUMNS
92 * };
93 * {
94 * GtkListStore *list_store;
95 * GtkTreePath *path;
96 * GtkTreeIter iter;
97 * gint i;
98 * list_store = gtk_list_store_new (N_COLUMNS,
99 * G_TYPE_STRING,
100 * G_TYPE_INT,
101 * G_TYPE_BOOLEAN);
102 * for (i = 0; i < 10; i++)
104 * gchar *some_data;
105 * some_data = get_some_data (i);
106 * /+* Add a new row to the model +/
107 * gtk_list_store_append (list_store, iter);
108 * gtk_list_store_set (list_store, iter,
109 * COLUMN_STRING, some_data,
110 * COLUMN_INT, i,
111 * COLUMN_BOOLEAN, FALSE,
112 * -1);
113 * /+* As the store will keep a copy of the string internally, we
114 * * free some_data.
115 * +/
116 * g_free (some_data);
118 * /+* Modify a particular row +/
119 * path = gtk_tree_path_new_from_string ("4");
120 * gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store),
121 * iter,
122 * path);
123 * gtk_tree_path_free (path);
124 * gtk_list_store_set (list_store, iter,
125 * COLUMN_BOOLEAN, TRUE,
126 * -1);
128 * Performance Considerations
129 * Internally, the GtkListStore was implemented with a linked list with a
130 * tail pointer prior to GTK+ 2.6. As a result, it was fast at data
131 * insertion and deletion, and not fast at random data access. The
132 * GtkListStore sets the GTK_TREE_MODEL_ITERS_PERSIST flag, which means
133 * that GtkTreeIters can be cached while the row exists. Thus, if
134 * access to a particular row is needed often and your code is expected to
135 * run on older versions of GTK+, it is worth keeping the iter around.
136 * Atomic Operations
137 * It is important to note that only the methods gtk_list_store_insert_with_values and
138 * gtk_list_store_insert_with_valuesv are atomic, in the sense that the row is being appended
139 * to the store and the values filled in in a single operation with regard to GtkTreeModel signaling.
140 * In contrast, using e.g. gtk_list_store_append and then gtk_list_store_set will first create a row,
141 * which triggers the "row_inserted" GtkTreeModel signal on GtkListStore. The row, however, is still
142 * empty, and any signal handler connecting to "row_inserted" on this particular store should be prepared
143 * for the situation that the row might be empty.
144 * This is especially important if you are wrapping the GtkListStore inside a GtkTreeModelFilter and are
145 * using a GtkTreeModelFilterVisibleFunc. Using any of the non-atomic operations to append rows to the GtkListStore
146 * will cause the GtkTreeModelFilterVisibleFunc to be visited with an empty row first; the function must be prepared for that.
148 private import gtk.TreeModel;
149 public class ListStore : TreeModel
152 /** the main Gtk struct */
153 protected GtkListStore* gtkListStore;
156 public GtkListStore* getListStoreStruct()
158 return gtkListStore;
162 /** the main Gtk struct as a void* */
163 protected void* getStruct()
165 return cast(void*)gtkListStore;
169 * Sets our main struct and passes it to the parent class
171 public this (GtkListStore* gtkListStore)
173 super(cast(GtkTreeModel*)gtkListStore);
174 this.gtkListStore = gtkListStore;
178 * Non-vararg creation function. Used primarily by language bindings.
179 * n_columns:
180 * number of columns in the list store
181 * types:
182 * an array of GType types for the columns, from first to last
183 * Returns:
184 * a new GtkListStore
186 public this (GType[] types)
188 // GtkListStore* gtk_list_store_newv (gint n_columns, GType *types);
189 this(cast(GtkListStore*)gtk_list_store_newv(types.length, cast(GType*)(types.ptr)) );
193 * Creates a top level iteractor.
194 * I don't think lists have but the top level iteractor
196 TreeIter createIter()
198 GtkTreeIter* iter = new GtkTreeIter;
199 gtk_list_store_append(getListStoreStruct(), iter);
200 return new TreeIter(iter);
204 * sets the values for one row
205 * @param iter the row iteractor
206 * @param columns an arrays with the columns to set
207 * @param values an arrays with the values
209 void set(TreeIter iter, int [] columns, char*[] values)
211 for ( int i=0 ; i<columns.length && i<values.length; i++ )
213 //Value v = new Value(values[i]);
214 //gtk_list_store_set(obj(), iter.getIter(), columns[i], v.getV(),-1);
215 gtk_list_store_set(
216 gtkListStore,
217 iter.getTreeIterStruct(),
218 columns[i],
219 values[i],-1);
223 void set(TreeIter iter, int [] columns, char[][] values)
225 for ( int i=0 ; i<columns.length && i<values.length; i++ )
227 //Value v = new Value(values[i]);
228 //gtk_list_store_set(obj(), iter.getIter(), columns[i], v.getV(),-1);
229 gtk_list_store_set(
230 gtkListStore,
231 iter.getTreeIterStruct(),
232 columns[i],
233 Str.toStringz(values[i]),-1);
237 void setValue(TreeIter iter, int column, char[] value)
239 Value v = new Value(value);
240 gtk_list_store_set_value(gtkListStore, iter.getTreeIterStruct(), column, v.getValueStruct());
241 //gtk_list_store_set_value(obj(), iter.getIter(), column, (GValue*)cChar(value));
244 void setValue(TreeIter iter, int column, int value)
246 Value v = new Value(value);
247 gtk_list_store_set_value(gtkListStore, iter.getTreeIterStruct(), column, v.getValueStruct());
255 * Creates a new list store as with n_columns columns each of the types passed
256 * in. Note that only types derived from standard GObject fundamental types
257 * are supported.
258 * As an example, gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING,
259 * GDK_TYPE_PIXBUF); will create a new GtkListStore with three columns, of type
260 * int, string and GdkPixbuf respectively.
261 * n_columns:
262 * number of columns in the list store
263 * ...:
264 * all GType types for the columns, from first to last
265 * Returns:
266 * a new GtkListStore
268 public this (int nColumns, ... )
270 // GtkListStore* gtk_list_store_new (gint n_columns, ...);
271 this(cast(GtkListStore*)gtk_list_store_new(nColumns) );
275 * Non-vararg creation function. Used primarily by language bindings.
276 * n_columns:
277 * number of columns in the list store
278 * types:
279 * an array of GType types for the columns, from first to last
280 * Returns:
281 * a new GtkListStore
283 public this (int nColumns, GType* types)
285 // GtkListStore* gtk_list_store_newv (gint n_columns, GType *types);
286 this(cast(GtkListStore*)gtk_list_store_newv(nColumns, types) );
290 * This function is meant primarily for GObjects that inherit from GtkListStore,
291 * and should only be used when constructing a new GtkListStore. It will not
292 * function after a row has been added, or a method on the GtkTreeModel
293 * interface is called.
294 * list_store:
295 * A GtkListStore
296 * n_columns:
297 * Number of columns for the list store
298 * types:
299 * An array length n of GTypes
301 public void setColumnTypes(int nColumns, GType* types)
303 // void gtk_list_store_set_column_types (GtkListStore *list_store, gint n_columns, GType *types);
304 gtk_list_store_set_column_types(gtkListStore, nColumns, types);
309 * See gtk_list_store_set(); this version takes a va_list for use by language
310 * bindings.
311 * list_store:
312 * A GtkListStore
313 * iter:
314 * A valid GtkTreeIter for the row being modified
315 * var_args:
316 * va_list of column/value pairs
318 public void setValist(TreeIter iter, void* varArgs)
320 // void gtk_list_store_set_valist (GtkListStore *list_store, GtkTreeIter *iter, va_list var_args);
321 gtk_list_store_set_valist(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), varArgs);
325 * Sets the data in the cell specified by iter and column.
326 * The type of value must be convertible to the type of the
327 * column.
328 * list_store:
329 * A GtkListStore
330 * iter:
331 * A valid GtkTreeIter for the row being modified
332 * column:
333 * column number to modify
334 * value:
335 * new value for the cell
337 public void setValue(TreeIter iter, int column, Value value)
339 // void gtk_list_store_set_value (GtkListStore *list_store, GtkTreeIter *iter, gint column, GValue *value);
340 gtk_list_store_set_value(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), column, (value is null) ? null : value.getValueStruct());
344 * Removes the given row from the list store. After being removed,
345 * iter is set to be the next valid row, or invalidated if it pointed
346 * to the last row in list_store.
347 * list_store:
348 * A GtkListStore
349 * iter:
350 * A valid GtkTreeIter
351 * Returns:
352 * TRUE if iter is valid, FALSE if not.
354 public int remove(TreeIter iter)
356 // gboolean gtk_list_store_remove (GtkListStore *list_store, GtkTreeIter *iter);
357 return gtk_list_store_remove(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
361 * Creates a new row at position. iter will be changed to point to this new
362 * row. If position is larger than the number of rows on the list, then the
363 * new row will be appended to the list. The row will be empty after this
364 * function is called. To fill in values, you need to call
365 * gtk_list_store_set() or gtk_list_store_set_value().
366 * list_store:
367 * A GtkListStore
368 * iter:
369 * An unset GtkTreeIter to set to the new row
370 * position:
371 * position to insert the new row
373 public void insert(TreeIter iter, int position)
375 // void gtk_list_store_insert (GtkListStore *list_store, GtkTreeIter *iter, gint position);
376 gtk_list_store_insert(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), position);
380 * Inserts a new row before sibling. If sibling is NULL, then the row will
381 * be appended to the end of the list. iter will be changed to point to this
382 * new row. The row will be empty after this function is called. To fill in
383 * values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
384 * list_store:
385 * A GtkListStore
386 * iter:
387 * An unset GtkTreeIter to set to the new row
388 * sibling:
389 * A valid GtkTreeIter, or NULL
391 public void insertBefore(TreeIter iter, TreeIter sibling)
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());
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 * list_store:
403 * A GtkListStore
404 * iter:
405 * An unset GtkTreeIter to set to the new row
406 * sibling:
407 * A valid GtkTreeIter, or NULL
409 public void insertAfter(TreeIter iter, TreeIter sibling)
411 // void gtk_list_store_insert_after (GtkListStore *list_store, GtkTreeIter *iter, GtkTreeIter *sibling);
412 gtk_list_store_insert_after(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (sibling is null) ? null : sibling.getTreeIterStruct());
416 * Creates a new row at position. iter will be changed to point to this new
417 * row. If position is larger than the number of rows on the list, then the
418 * new row will be appended to the list. The row will be filled with the
419 * values given to this function.
420 * Calling
421 * gtk_list_store_insert_with_values(list_store, iter, position...)
422 * has the same effect as calling
423 * gtk_list_store_insert (list_store, iter, position);
424 * gtk_list_store_set (list_store, iter, ...);
425 * with the difference that the former will only emit a row_inserted signal,
426 * while the latter will emit row_inserted, row_changed and, if the list store
427 * is sorted, rows_reordered. Since emitting the rows_reordered signal
428 * repeatedly can affect the performance of the program,
429 * gtk_list_store_insert_with_values() should generally be preferred when
430 * inserting rows in a sorted list store.
431 * list_store:
432 * A GtkListStore
433 * iter:
434 * An unset GtkTreeIter to set to the new row, or NULL.
435 * position:
436 * position to insert the new row
437 * ...:
438 * pairs of column number and value, terminated with -1
439 * Since 2.6
441 public void insertWithValues(TreeIter iter, int position, ... )
443 // void gtk_list_store_insert_with_values (GtkListStore *list_store, GtkTreeIter *iter, gint position, ...);
444 gtk_list_store_insert_with_values(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), position);
448 * A variant of gtk_list_store_insert_with_values() which
449 * takes the columns and values as two arrays, instead of
450 * varargs. This function is mainly intended for
451 * language-bindings.
452 * list_store:
453 * A GtkListStore
454 * iter:
455 * An unset GtkTreeIter to set to the new row, or NULL.
456 * position:
457 * position to insert the new row
458 * columns:
459 * an array of column numbers
460 * values:
461 * an array of GValues
462 * n_values:
463 * the length of the columns and values arrays
464 * Since 2.6
466 public void insertWithValuesv(TreeIter iter, int position, int* columns, Value values, int nValues)
468 // void gtk_list_store_insert_with_valuesv (GtkListStore *list_store, GtkTreeIter *iter, gint position, gint *columns, GValue *values, gint n_values);
469 gtk_list_store_insert_with_valuesv(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), position, columns, (values is null) ? null : values.getValueStruct(), nValues);
473 * Prepends a new row to list_store. iter will be changed to point to this new
474 * row. The row will be empty after this function is called. To fill in
475 * values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
476 * list_store:
477 * A GtkListStore
478 * iter:
479 * An unset GtkTreeIter to set to the prepend row
481 public void prepend(TreeIter iter)
483 // void gtk_list_store_prepend (GtkListStore *list_store, GtkTreeIter *iter);
484 gtk_list_store_prepend(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
488 * Appends a new row to list_store. iter will be changed to point to this new
489 * row. The row will be empty after this function is called. To fill in
490 * values, you need to call gtk_list_store_set() or gtk_list_store_set_value().
491 * list_store:
492 * A GtkListStore
493 * iter:
494 * An unset GtkTreeIter to set to the appended row
496 public void append(TreeIter iter)
498 // void gtk_list_store_append (GtkListStore *list_store, GtkTreeIter *iter);
499 gtk_list_store_append(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
503 * Removes all rows from the list store.
504 * list_store:
505 * a GtkListStore.
507 public void clear()
509 // void gtk_list_store_clear (GtkListStore *list_store);
510 gtk_list_store_clear(gtkListStore);
514 * Warning
515 * This function is slow. Only use it for debugging and/or testing
516 * purposes.
517 * Checks if the given iter is a valid iter for this GtkListStore.
518 * list_store:
519 * A GtkListStore.
520 * iter:
521 * A GtkTreeIter.
522 * Returns:
523 * TRUE if the iter is valid, FALSE if the iter is invalid.
524 * Since 2.2
526 public int iterIsValid(TreeIter iter)
528 // gboolean gtk_list_store_iter_is_valid (GtkListStore *list_store, GtkTreeIter *iter);
529 return gtk_list_store_iter_is_valid(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct());
533 * Reorders store to follow the order indicated by new_order. Note that
534 * this function only works with unsorted stores.
535 * store:
536 * A GtkListStore.
537 * new_order:
538 * an array of integers mapping the new position of each child
539 * to its old position before the re-ordering,
540 * i.e. new_order[newpos] = oldpos.
541 * Since 2.2
543 public void reorder(int* newOrder)
545 // void gtk_list_store_reorder (GtkListStore *store, gint *new_order);
546 gtk_list_store_reorder(gtkListStore, newOrder);
550 * Swaps a and b in store. Note that this function only works with
551 * unsorted stores.
552 * store:
553 * A GtkListStore.
554 * a:
555 * A GtkTreeIter.
556 * b:
557 * Another GtkTreeIter.
558 * Since 2.2
560 public void swap(TreeIter a, TreeIter b)
562 // void gtk_list_store_swap (GtkListStore *store, GtkTreeIter *a, GtkTreeIter *b);
563 gtk_list_store_swap(gtkListStore, (a is null) ? null : a.getTreeIterStruct(), (b is null) ? null : b.getTreeIterStruct());
567 * Moves iter in store to the position before position. Note that this
568 * function only works with unsorted stores. If position is NULL, iter
569 * will be moved to the end of the list.
570 * store:
571 * A GtkListStore.
572 * iter:
573 * A GtkTreeIter.
574 * position:
575 * A GtkTreeIter, or NULL.
576 * Since 2.2
578 public void moveBefore(TreeIter iter, TreeIter position)
580 // void gtk_list_store_move_before (GtkListStore *store, GtkTreeIter *iter, GtkTreeIter *position);
581 gtk_list_store_move_before(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct());
585 * Moves iter in store to the position after position. Note that this
586 * function only works with unsorted stores. If position is NULL, iter
587 * will be moved to the start of the list.
588 * store:
589 * A GtkListStore.
590 * iter:
591 * A GtkTreeIter.
592 * position:
593 * A GtkTreeIter or NULL.
594 * Since 2.2
595 * See Also
596 * GtkTreeModel, GtkTreeStore
598 public void moveAfter(TreeIter iter, TreeIter position)
600 // void gtk_list_store_move_after (GtkListStore *store, GtkTreeIter *iter, GtkTreeIter *position);
601 gtk_list_store_move_after(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct());