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