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 module gtk.TreeStore; 26 27 private import gdk.Pixbuf; 28 private import glib.ConstructionException; 29 private import gobject.ObjectG; 30 private import gobject.Value; 31 private import gtk.BuildableIF; 32 private import gtk.BuildableT; 33 private import gtk.TreeDragDestIF; 34 private import gtk.TreeDragDestT; 35 private import gtk.TreeDragSourceIF; 36 private import gtk.TreeDragSourceT; 37 private import gtk.TreeIter; 38 private import gtk.TreeModelIF; 39 private import gtk.TreeModelT; 40 private import gtk.TreeNode; 41 private import gtk.TreeSortableIF; 42 private import gtk.TreeSortableT; 43 private import gtk.c.functions; 44 public import gtk.c.types; 45 public import gtkc.gtktypes; 46 47 48 /** 49 * The #GtkTreeStore object is a list model for use with a #GtkTreeView 50 * widget. It implements the #GtkTreeModel interface, and consequentially, 51 * can use all of the methods available there. It also implements the 52 * #GtkTreeSortable interface so it can be sorted by the view. Finally, 53 * it also implements the tree 54 * [drag and drop][gtk3-GtkTreeView-drag-and-drop] 55 * interfaces. 56 * 57 * # GtkTreeStore as GtkBuildable 58 * 59 * The GtkTreeStore implementation of the #GtkBuildable interface allows 60 * to specify the model columns with a <columns> element that may contain 61 * multiple <column> elements, each specifying one model column. The “type” 62 * attribute specifies the data type for the column. 63 * 64 * An example of a UI Definition fragment for a tree store: 65 * |[ 66 * <object class="GtkTreeStore"> 67 * <columns> 68 * <column type="gchararray"/> 69 * <column type="gchararray"/> 70 * <column type="gint"/> 71 * </columns> 72 * </object> 73 * ]| 74 */ 75 public class TreeStore : ObjectG, BuildableIF, TreeDragDestIF, TreeDragSourceIF, TreeModelIF, TreeSortableIF 76 { 77 /** the main Gtk struct */ 78 protected GtkTreeStore* gtkTreeStore; 79 80 /** Get the main Gtk struct */ 81 public GtkTreeStore* getTreeStoreStruct(bool transferOwnership = false) 82 { 83 if (transferOwnership) 84 ownedRef = false; 85 return gtkTreeStore; 86 } 87 88 /** the main Gtk struct as a void* */ 89 protected override void* getStruct() 90 { 91 return cast(void*)gtkTreeStore; 92 } 93 94 protected override void setStruct(GObject* obj) 95 { 96 gtkTreeStore = cast(GtkTreeStore*)obj; 97 super.setStruct(obj); 98 } 99 100 /** 101 * Sets our main struct and passes it to the parent class. 102 */ 103 public this (GtkTreeStore* gtkTreeStore, bool ownedRef = false) 104 { 105 this.gtkTreeStore = gtkTreeStore; 106 super(cast(GObject*)gtkTreeStore, ownedRef); 107 } 108 109 // add the Buildable capabilities 110 mixin BuildableT!(GtkTreeStore); 111 112 // add the TreeDragDest capabilities 113 mixin TreeDragDestT!(GtkTreeStore); 114 115 // add the TreeDragSource capabilities 116 mixin TreeDragSourceT!(GtkTreeStore); 117 118 // add the TreeModel capabilities 119 mixin TreeModelT!(GtkTreeStore); 120 121 // add the TreeSortable capabilities 122 mixin TreeSortableT!(GtkTreeStore); 123 124 /** 125 * Creates a top level iteractor. 126 * I don't think lists have but the top level iteractor 127 */ 128 TreeIter createIter(TreeIter parent=null) 129 { 130 GtkTreeIter* iter = new GtkTreeIter; 131 gtk_tree_store_append(getTreeStoreStruct(), iter, (parent is null) ? null : parent.getTreeIterStruct()); 132 return new TreeIter(iter); 133 } 134 135 /** 136 * Sets one value into one cells. 137 * \todo confirm we need to destroy the Value instance 138 * Params: 139 * iter = the tree iteractor, effectivly the row 140 * column = to column number to set 141 * value = the value 142 */ 143 void setValue(TYPE)(TreeIter iter, int column, TYPE value) 144 { 145 Value v = new Value(value); 146 gtk_tree_store_set_value(gtkTreeStore, iter.getTreeIterStruct(), column, v.getValueStruct()); 147 } 148 149 /** 150 * sets the values for one row 151 * Params: 152 * iter = the row iteractor 153 * columns = an arrays with the columns to set 154 * values = an arrays with the values 155 */ 156 void set(TreeIter iter, int[] columns, char*[] values) 157 { 158 for ( int i=0 ; i<columns.length && i<values.length; i++ ) 159 { 160 gtk_tree_store_set( 161 gtkTreeStore, 162 iter.getTreeIterStruct(), 163 columns[i], 164 values[i],-1); 165 } 166 } 167 168 /** ditto */ 169 void set(TreeIter iter, int[] columns, string[] values) 170 { 171 for ( int i=0 ; i<columns.length && i<values.length; i++ ) 172 { 173 gtk_tree_store_set( 174 gtkTreeStore, 175 iter.getTreeIterStruct(), 176 columns[i], 177 Str.toStringz(values[i]),-1); 178 } 179 } 180 181 /** 182 * Sets an iteractor values from a tree node. 183 * This is the way to add a new row to the tree, 184 * the iteractor is either a top level iteractor created from createIter() 185 * or a nested iteractor created from append() 186 * Params: 187 * iter = the iteractor to set 188 * treeNode = the tree node 189 * See_Also: createIter(), append() 190 */ 191 void set(TreeIter iter, TreeNode treeNode) 192 { 193 int[] cols; 194 string[] vals; 195 for ( int i=0 ; i<treeNode.columnCount() ; i++ ) 196 { 197 //printf(">>>>>>>>>>>>> requesting value for %d\n",i); 198 cols ~= i; 199 string value = treeNode.getNodeValue(i); 200 if ( value is null ) 201 { 202 vals ~= ""; 203 } 204 else 205 { 206 vals ~= value; 207 } 208 } 209 set(iter, cols, vals); 210 } 211 212 213 /** 214 * Creates and prepends a new row to tree_store. If parent is non-NULL, then it will prepend 215 * the new row before the first child of parent, otherwise it will prepend a row 216 * to the top level. iter will be changed to point to this new row. The row 217 * will be empty after this function is called. To fill in values, you need to 218 * call gtk_tree_store_set() or gtk_tree_store_set_value(). 219 * Params: 220 * parent = A valid GtkTreeIter, or NULL 221 */ 222 public TreeIter prepend(TreeIter parent) 223 { 224 TreeIter iter = new TreeIter(); 225 // void gtk_tree_store_prepend (GtkTreeStore *tree_store, GtkTreeIter *iter, GtkTreeIter *parent); 226 gtk_tree_store_prepend(gtkTreeStore, iter.getTreeIterStruct(), (parent is null) ? null : parent.getTreeIterStruct()); 227 return iter; 228 } 229 230 /** 231 * Creates and appends a new row to tree_store. If parent is non-NULL, then it will append the 232 * new row after the last child of parent, otherwise it will append a row to 233 * the top level. iter will be changed to point to this new row. The row will 234 * be empty after this function is called. To fill in values, you need to call 235 * gtk_tree_store_set() or gtk_tree_store_set_value(). 236 * Params: 237 * parent = A valid GtkTreeIter, or NULL 238 */ 239 public TreeIter append(TreeIter parent) 240 { 241 TreeIter iter = new TreeIter(); 242 // void gtk_tree_store_append (GtkTreeStore *tree_store, GtkTreeIter *iter, GtkTreeIter *parent); 243 gtk_tree_store_append(gtkTreeStore, 244 iter.getTreeIterStruct(), 245 (parent is null) ? null : parent.getTreeIterStruct()); 246 return iter; 247 } 248 249 /** 250 */ 251 252 /** */ 253 public static GType getType() 254 { 255 return gtk_tree_store_get_type(); 256 } 257 258 /** 259 * Non vararg creation function. Used primarily by language bindings. 260 * 261 * Params: 262 * types = an array of #GType types for the columns, from first to last 263 * 264 * Returns: a new #GtkTreeStore 265 * 266 * Throws: ConstructionException GTK+ fails to create the object. 267 */ 268 public this(GType[] types) 269 { 270 auto p = gtk_tree_store_newv(cast(int)types.length, types.ptr); 271 272 if(p is null) 273 { 274 throw new ConstructionException("null returned by newv"); 275 } 276 277 this(cast(GtkTreeStore*) p, true); 278 } 279 280 /** 281 * Appends a new row to @tree_store. If @parent is non-%NULL, then it will append the 282 * new row after the last child of @parent, otherwise it will append a row to 283 * the top level. @iter will be changed to point to this new row. The row will 284 * be empty after this function is called. To fill in values, you need to call 285 * gtk_tree_store_set() or gtk_tree_store_set_value(). 286 * 287 * Params: 288 * iter = An unset #GtkTreeIter to set to the appended row 289 * parent = A valid #GtkTreeIter, or %NULL 290 */ 291 public void append(out TreeIter iter, TreeIter parent) 292 { 293 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 294 295 gtk_tree_store_append(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct()); 296 297 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 298 } 299 300 /** 301 * Removes all rows from @tree_store 302 */ 303 public void clear() 304 { 305 gtk_tree_store_clear(gtkTreeStore); 306 } 307 308 /** 309 * Creates a new row at @position. If parent is non-%NULL, then the row will be 310 * made a child of @parent. Otherwise, the row will be created at the toplevel. 311 * If @position is -1 or is larger than the number of rows at that level, then 312 * the new row will be inserted to the end of the list. @iter will be changed 313 * to point to this new row. The row will be empty after this function is 314 * called. To fill in values, you need to call gtk_tree_store_set() or 315 * gtk_tree_store_set_value(). 316 * 317 * Params: 318 * iter = An unset #GtkTreeIter to set to the new row 319 * parent = A valid #GtkTreeIter, or %NULL 320 * position = position to insert the new row, or -1 for last 321 */ 322 public void insert(out TreeIter iter, TreeIter parent, int position) 323 { 324 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 325 326 gtk_tree_store_insert(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct(), position); 327 328 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 329 } 330 331 /** 332 * Inserts a new row after @sibling. If @sibling is %NULL, then the row will be 333 * prepended to @parent ’s children. If @parent and @sibling are %NULL, then 334 * the row will be prepended to the toplevel. If both @sibling and @parent are 335 * set, then @parent must be the parent of @sibling. When @sibling is set, 336 * @parent is optional. 337 * 338 * @iter will be changed to point to this new row. The row will be empty after 339 * this function is called. To fill in values, you need to call 340 * gtk_tree_store_set() or gtk_tree_store_set_value(). 341 * 342 * Params: 343 * iter = An unset #GtkTreeIter to set to the new row 344 * parent = A valid #GtkTreeIter, or %NULL 345 * sibling = A valid #GtkTreeIter, or %NULL 346 */ 347 public void insertAfter(out TreeIter iter, TreeIter parent, TreeIter sibling) 348 { 349 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 350 351 gtk_tree_store_insert_after(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct(), (sibling is null) ? null : sibling.getTreeIterStruct()); 352 353 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 354 } 355 356 /** 357 * Inserts a new row before @sibling. If @sibling is %NULL, then the row will 358 * be appended to @parent ’s children. If @parent and @sibling are %NULL, then 359 * the row will be appended to the toplevel. If both @sibling and @parent are 360 * set, then @parent must be the parent of @sibling. When @sibling is set, 361 * @parent is optional. 362 * 363 * @iter will be changed to point to this new row. The row will be empty after 364 * this function is called. To fill in values, you need to call 365 * gtk_tree_store_set() or gtk_tree_store_set_value(). 366 * 367 * Params: 368 * iter = An unset #GtkTreeIter to set to the new row 369 * parent = A valid #GtkTreeIter, or %NULL 370 * sibling = A valid #GtkTreeIter, or %NULL 371 */ 372 public void insertBefore(out TreeIter iter, TreeIter parent, TreeIter sibling) 373 { 374 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 375 376 gtk_tree_store_insert_before(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct(), (sibling is null) ? null : sibling.getTreeIterStruct()); 377 378 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 379 } 380 381 /** 382 * A variant of gtk_tree_store_insert_with_values() which takes 383 * the columns and values as two arrays, instead of varargs. This 384 * function is mainly intended for language bindings. 385 * 386 * Params: 387 * iter = An unset #GtkTreeIter to set the new row, or %NULL. 388 * parent = A valid #GtkTreeIter, or %NULL 389 * position = position to insert the new row, or -1 for last 390 * columns = an array of column numbers 391 * values = an array of GValues 392 * 393 * Since: 2.10 394 */ 395 public void insertWithValuesv(out TreeIter iter, TreeIter parent, int position, int[] columns, Value[] values) 396 { 397 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 398 399 GValue[] valuesArray = new GValue[values.length]; 400 for ( int i = 0; i < values.length; i++ ) 401 { 402 valuesArray[i] = *(values[i].getValueStruct()); 403 } 404 405 gtk_tree_store_insert_with_valuesv(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct(), position, columns.ptr, valuesArray.ptr, cast(int)values.length); 406 407 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 408 } 409 410 /** 411 * Returns %TRUE if @iter is an ancestor of @descendant. That is, @iter is the 412 * parent (or grandparent or great-grandparent) of @descendant. 413 * 414 * Params: 415 * iter = A valid #GtkTreeIter 416 * descendant = A valid #GtkTreeIter 417 * 418 * Returns: %TRUE, if @iter is an ancestor of @descendant 419 */ 420 public bool isAncestor(TreeIter iter, TreeIter descendant) 421 { 422 return gtk_tree_store_is_ancestor(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), (descendant is null) ? null : descendant.getTreeIterStruct()) != 0; 423 } 424 425 /** 426 * Returns the depth of @iter. This will be 0 for anything on the root level, 1 427 * for anything down a level, etc. 428 * 429 * Params: 430 * iter = A valid #GtkTreeIter 431 * 432 * Returns: The depth of @iter 433 */ 434 public int iterDepth(TreeIter iter) 435 { 436 return gtk_tree_store_iter_depth(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct()); 437 } 438 439 /** 440 * WARNING: This function is slow. Only use it for debugging and/or testing 441 * purposes. 442 * 443 * Checks if the given iter is a valid iter for this #GtkTreeStore. 444 * 445 * Params: 446 * iter = A #GtkTreeIter. 447 * 448 * Returns: %TRUE if the iter is valid, %FALSE if the iter is invalid. 449 * 450 * Since: 2.2 451 */ 452 public bool iterIsValid(TreeIter iter) 453 { 454 return gtk_tree_store_iter_is_valid(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct()) != 0; 455 } 456 457 /** 458 * Moves @iter in @tree_store to the position after @position. @iter and 459 * @position should be in the same level. Note that this function only 460 * works with unsorted stores. If @position is %NULL, @iter will be moved 461 * to the start of the level. 462 * 463 * Params: 464 * iter = A #GtkTreeIter. 465 * position = A #GtkTreeIter. 466 * 467 * Since: 2.2 468 */ 469 public void moveAfter(TreeIter iter, TreeIter position) 470 { 471 gtk_tree_store_move_after(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct()); 472 } 473 474 /** 475 * Moves @iter in @tree_store to the position before @position. @iter and 476 * @position should be in the same level. Note that this function only 477 * works with unsorted stores. If @position is %NULL, @iter will be 478 * moved to the end of the level. 479 * 480 * Params: 481 * iter = A #GtkTreeIter. 482 * position = A #GtkTreeIter or %NULL. 483 * 484 * Since: 2.2 485 */ 486 public void moveBefore(TreeIter iter, TreeIter position) 487 { 488 gtk_tree_store_move_before(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), (position is null) ? null : position.getTreeIterStruct()); 489 } 490 491 /** 492 * Prepends a new row to @tree_store. If @parent is non-%NULL, then it will prepend 493 * the new row before the first child of @parent, otherwise it will prepend a row 494 * to the top level. @iter will be changed to point to this new row. The row 495 * will be empty after this function is called. To fill in values, you need to 496 * call gtk_tree_store_set() or gtk_tree_store_set_value(). 497 * 498 * Params: 499 * iter = An unset #GtkTreeIter to set to the prepended row 500 * parent = A valid #GtkTreeIter, or %NULL 501 */ 502 public void prepend(out TreeIter iter, TreeIter parent) 503 { 504 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 505 506 gtk_tree_store_prepend(gtkTreeStore, outiter, (parent is null) ? null : parent.getTreeIterStruct()); 507 508 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 509 } 510 511 /** 512 * Removes @iter from @tree_store. After being removed, @iter is set to the 513 * next valid row at that level, or invalidated if it previously pointed to the 514 * last one. 515 * 516 * Params: 517 * iter = A valid #GtkTreeIter 518 * 519 * Returns: %TRUE if @iter is still valid, %FALSE if not. 520 */ 521 public bool remove(TreeIter iter) 522 { 523 return gtk_tree_store_remove(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct()) != 0; 524 } 525 526 /** 527 * Reorders the children of @parent in @tree_store to follow the order 528 * indicated by @new_order. Note that this function only works with 529 * unsorted stores. 530 * 531 * Params: 532 * parent = A #GtkTreeIter, or %NULL 533 * newOrder = an array of integers mapping the new position of each child 534 * to its old position before the re-ordering, 535 * i.e. @new_order`[newpos] = oldpos`. 536 * 537 * Since: 2.2 538 */ 539 public void reorder(TreeIter parent, int[] newOrder) 540 { 541 gtk_tree_store_reorder(gtkTreeStore, (parent is null) ? null : parent.getTreeIterStruct(), newOrder.ptr); 542 } 543 544 /** 545 * This function is meant primarily for #GObjects that inherit from 546 * #GtkTreeStore, and should only be used when constructing a new 547 * #GtkTreeStore. It will not function after a row has been added, 548 * or a method on the #GtkTreeModel interface is called. 549 * 550 * Params: 551 * types = An array of #GType types, one for each column 552 */ 553 public void setColumnTypes(GType[] types) 554 { 555 gtk_tree_store_set_column_types(gtkTreeStore, cast(int)types.length, types.ptr); 556 } 557 558 /** 559 * See gtk_tree_store_set(); this version takes a va_list for 560 * use by language bindings. 561 * 562 * Params: 563 * iter = A valid #GtkTreeIter for the row being modified 564 * varArgs = va_list of column/value pairs 565 */ 566 public void setValist(TreeIter iter, void* varArgs) 567 { 568 gtk_tree_store_set_valist(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), varArgs); 569 } 570 571 /** 572 * Sets the data in the cell specified by @iter and @column. 573 * The type of @value must be convertible to the type of the 574 * column. 575 * 576 * Params: 577 * iter = A valid #GtkTreeIter for the row being modified 578 * column = column number to modify 579 * value = new value for the cell 580 */ 581 public void setValue(TreeIter iter, int column, Value value) 582 { 583 gtk_tree_store_set_value(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), column, (value is null) ? null : value.getValueStruct()); 584 } 585 586 /** 587 * A variant of gtk_tree_store_set_valist() which takes 588 * the columns and values as two arrays, instead of varargs. This 589 * function is mainly intended for language bindings or in case 590 * the number of columns to change is not known until run-time. 591 * 592 * Params: 593 * iter = A valid #GtkTreeIter for the row being modified 594 * columns = an array of column numbers 595 * values = an array of GValues 596 * 597 * Since: 2.12 598 */ 599 public void setValuesv(TreeIter iter, int[] columns, Value[] values) 600 { 601 GValue[] valuesArray = new GValue[values.length]; 602 for ( int i = 0; i < values.length; i++ ) 603 { 604 valuesArray[i] = *(values[i].getValueStruct()); 605 } 606 607 gtk_tree_store_set_valuesv(gtkTreeStore, (iter is null) ? null : iter.getTreeIterStruct(), columns.ptr, valuesArray.ptr, cast(int)values.length); 608 } 609 610 /** 611 * Swaps @a and @b in the same level of @tree_store. Note that this function 612 * only works with unsorted stores. 613 * 614 * Params: 615 * a = A #GtkTreeIter. 616 * b = Another #GtkTreeIter. 617 * 618 * Since: 2.2 619 */ 620 public void swap(TreeIter a, TreeIter b) 621 { 622 gtk_tree_store_swap(gtkTreeStore, (a is null) ? null : a.getTreeIterStruct(), (b is null) ? null : b.getTreeIterStruct()); 623 } 624 }