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