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