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