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