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
28 * strct = GtkListStore
36 * extend = GtkTreeModel
44 * - gtk_list_store_set
53 * - GtkTreeIter* -> TreeIter
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
;
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
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
99 * Example5.Creating a simple list store.
107 * GtkListStore *list_store;
111 * list_store = gtk_list_store_new (N_COLUMNS,
115 * for (i = 0; i < 10; i++)
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,
124 * COLUMN_BOOLEAN, FALSE,
126 * /+* As the store will keep a copy of the string internally, we
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),
136 * gtk_tree_path_free (path);
137 * gtk_list_store_set (list_store, iter,
138 * COLUMN_BOOLEAN, TRUE,
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.
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()
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
)
188 if ( gtkListStore
is null )
193 Stdout("struct gtkListStore is null on constructor").newline
;
197 printf("struct gtkListStore is null on constructor");
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.
213 * number of columns in the list store
215 * an array of GType types for the columns, from first to last
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);
250 iter
.getTreeIterStruct(),
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);
264 iter
.getTreeIterStruct(),
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
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.
295 * number of columns in the list store
297 * all GType types for the columns, from first to last
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.
310 * number of columns in the list store
312 * an array of GType types for the columns, from first to last
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.
330 * Number of columns for the list store
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
347 * A valid GtkTreeIter for the row being modified
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
364 * A valid GtkTreeIter for the row being modified
366 * column number to modify
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.
383 * A valid GtkTreeIter
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().
402 * An unset GtkTreeIter to set to the new row
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().
420 * An unset GtkTreeIter to set to the new row
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().
438 * An unset GtkTreeIter to set to the new row
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.
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.
467 * An unset GtkTreeIter to set to the new row, or NULL.
469 * position to insert the new row
471 * pairs of column number and value, terminated with -1
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
488 * An unset GtkTreeIter to set to the new row, or NULL.
490 * position to insert the new row
492 * an array of column numbers
494 * an array of GValues
496 * the length of the columns and values arrays
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().
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().
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.
542 // void gtk_list_store_clear (GtkListStore *list_store);
543 gtk_list_store_clear(gtkListStore
);
548 * This function is slow. Only use it for debugging and/or testing
550 * Checks if the given iter is a valid iter for this GtkListStore.
556 * TRUE if the iter is valid, FALSE if the iter is invalid.
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.
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.
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
590 * Another GtkTreeIter.
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.
608 * A GtkTreeIter, or NULL.
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.
626 * A GtkTreeIter or NULL.
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());