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