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.TreeModelT; 26 27 public import glib.Str; 28 public import gobject.ObjectG; 29 public import gobject.Signals; 30 public import gobject.Value; 31 public import gtk.TreeIter; 32 public import gtk.TreeModel; 33 public import gtk.TreeModelIF; 34 public import gtk.TreePath; 35 public import gtkc.gdktypes; 36 public import gtkc.gtk; 37 public import gtkc.gtktypes; 38 public import std.algorithm; 39 40 41 /** 42 * The #GtkTreeModel interface defines a generic tree interface for 43 * use by the #GtkTreeView widget. It is an abstract interface, and 44 * is designed to be usable with any appropriate data structure. The 45 * programmer just has to implement this interface on their own data 46 * type for it to be viewable by a #GtkTreeView widget. 47 * 48 * The model is represented as a hierarchical tree of strongly-typed, 49 * columned data. In other words, the model can be seen as a tree where 50 * every node has different values depending on which column is being 51 * queried. The type of data found in a column is determined by using 52 * the GType system (ie. #G_TYPE_INT, #GTK_TYPE_BUTTON, #G_TYPE_POINTER, 53 * etc). The types are homogeneous per column across all nodes. It is 54 * important to note that this interface only provides a way of examining 55 * a model and observing changes. The implementation of each individual 56 * model decides how and if changes are made. 57 * 58 * In order to make life simpler for programmers who do not need to 59 * write their own specialized model, two generic models are provided 60 * — the #GtkTreeStore and the #GtkListStore. To use these, the 61 * developer simply pushes data into these models as necessary. These 62 * models provide the data structure as well as all appropriate tree 63 * interfaces. As a result, implementing drag and drop, sorting, and 64 * storing data is trivial. For the vast majority of trees and lists, 65 * these two models are sufficient. 66 * 67 * Models are accessed on a node/column level of granularity. One can 68 * query for the value of a model at a certain node and a certain 69 * column on that node. There are two structures used to reference a 70 * particular node in a model. They are the #GtkTreePath-struct and 71 * the #GtkTreeIter-struct (“iter” is short for iterator). Most of the 72 * interface consists of operations on a #GtkTreeIter-struct. 73 * 74 * A path is essentially a potential node. It is a location on a model 75 * that may or may not actually correspond to a node on a specific 76 * model. The #GtkTreePath-struct can be converted into either an 77 * array of unsigned integers or a string. The string form is a list 78 * of numbers separated by a colon. Each number refers to the offset 79 * at that level. Thus, the path `0` refers to the root 80 * node and the path `2:4` refers to the fifth child of 81 * the third node. 82 * 83 * By contrast, a #GtkTreeIter-struct is a reference to a specific node on 84 * a specific model. It is a generic struct with an integer and three 85 * generic pointers. These are filled in by the model in a model-specific 86 * way. One can convert a path to an iterator by calling 87 * gtk_tree_model_get_iter(). These iterators are the primary way 88 * of accessing a model and are similar to the iterators used by 89 * #GtkTextBuffer. They are generally statically allocated on the 90 * stack and only used for a short time. The model interface defines 91 * a set of operations using them for navigating the model. 92 * 93 * It is expected that models fill in the iterator with private data. 94 * For example, the #GtkListStore model, which is internally a simple 95 * linked list, stores a list node in one of the pointers. The 96 * #GtkTreeModelSort stores an array and an offset in two of the 97 * pointers. Additionally, there is an integer field. This field is 98 * generally filled with a unique stamp per model. This stamp is for 99 * catching errors resulting from using invalid iterators with a model. 100 * 101 * The lifecycle of an iterator can be a little confusing at first. 102 * Iterators are expected to always be valid for as long as the model 103 * is unchanged (and doesn’t emit a signal). The model is considered 104 * to own all outstanding iterators and nothing needs to be done to 105 * free them from the user’s point of view. Additionally, some models 106 * guarantee that an iterator is valid for as long as the node it refers 107 * to is valid (most notably the #GtkTreeStore and #GtkListStore). 108 * Although generally uninteresting, as one always has to allow for 109 * the case where iterators do not persist beyond a signal, some very 110 * important performance enhancements were made in the sort model. 111 * As a result, the #GTK_TREE_MODEL_ITERS_PERSIST flag was added to 112 * indicate this behavior. 113 * 114 * To help show some common operation of a model, some examples are 115 * provided. The first example shows three ways of getting the iter at 116 * the location `3:2:5`. While the first method shown is 117 * easier, the second is much more common, as you often get paths from 118 * callbacks. 119 * 120 * ## Acquiring a #GtkTreeIter-struct 121 * 122 * |[<!-- language="C" --> 123 * // Three ways of getting the iter pointing to the location 124 * GtkTreePath *path; 125 * GtkTreeIter iter; 126 * GtkTreeIter parent_iter; 127 * 128 * // get the iterator from a string 129 * gtk_tree_model_get_iter_from_string (model, 130 * &iter, 131 * "3:2:5"); 132 * 133 * // get the iterator from a path 134 * path = gtk_tree_path_new_from_string ("3:2:5"); 135 * gtk_tree_model_get_iter (model, &iter, path); 136 * gtk_tree_path_free (path); 137 * 138 * // walk the tree to find the iterator 139 * gtk_tree_model_iter_nth_child (model, &iter, 140 * NULL, 3); 141 * parent_iter = iter; 142 * gtk_tree_model_iter_nth_child (model, &iter, 143 * &parent_iter, 2); 144 * parent_iter = iter; 145 * gtk_tree_model_iter_nth_child (model, &iter, 146 * &parent_iter, 5); 147 * ]| 148 * 149 * This second example shows a quick way of iterating through a list 150 * and getting a string and an integer from each row. The 151 * populate_model() function used below is not 152 * shown, as it is specific to the #GtkListStore. For information on 153 * how to write such a function, see the #GtkListStore documentation. 154 * 155 * ## Reading data from a #GtkTreeModel 156 * 157 * |[<!-- language="C" --> 158 * enum 159 * { 160 * STRING_COLUMN, 161 * INT_COLUMN, 162 * N_COLUMNS 163 * }; 164 * 165 * ... 166 * 167 * GtkTreeModel *list_store; 168 * GtkTreeIter iter; 169 * gboolean valid; 170 * gint row_count = 0; 171 * 172 * // make a new list_store 173 * list_store = gtk_list_store_new (N_COLUMNS, 174 * G_TYPE_STRING, 175 * G_TYPE_INT); 176 * 177 * // Fill the list store with data 178 * populate_model (list_store); 179 * 180 * // Get the first iter in the list, check it is valid and walk 181 * // through the list, reading each row. 182 * 183 * valid = gtk_tree_model_get_iter_first (list_store, 184 * &iter); 185 * while (valid) 186 * { 187 * gchar *str_data; 188 * gint int_data; 189 * 190 * // Make sure you terminate calls to gtk_tree_model_get() with a “-1” value 191 * gtk_tree_model_get (list_store, &iter, 192 * STRING_COLUMN, &str_data, 193 * INT_COLUMN, &int_data, 194 * -1); 195 * 196 * // Do something with the data 197 * g_print ("Row %d: (%s,%d)\n", 198 * row_count, str_data, int_data); 199 * g_free (str_data); 200 * 201 * valid = gtk_tree_model_iter_next (list_store, 202 * &iter); 203 * row_count++; 204 * } 205 * ]| 206 * 207 * The #GtkTreeModel interface contains two methods for reference 208 * counting: gtk_tree_model_ref_node() and gtk_tree_model_unref_node(). 209 * These two methods are optional to implement. The reference counting 210 * is meant as a way for views to let models know when nodes are being 211 * displayed. #GtkTreeView will take a reference on a node when it is 212 * visible, which means the node is either in the toplevel or expanded. 213 * Being displayed does not mean that the node is currently directly 214 * visible to the user in the viewport. Based on this reference counting 215 * scheme a caching model, for example, can decide whether or not to cache 216 * a node based on the reference count. A file-system based model would 217 * not want to keep the entire file hierarchy in memory, but just the 218 * folders that are currently expanded in every current view. 219 * 220 * When working with reference counting, the following rules must be taken 221 * into account: 222 * 223 * - Never take a reference on a node without owning a reference on its parent. 224 * This means that all parent nodes of a referenced node must be referenced 225 * as well. 226 * 227 * - Outstanding references on a deleted node are not released. This is not 228 * possible because the node has already been deleted by the time the 229 * row-deleted signal is received. 230 * 231 * - Models are not obligated to emit a signal on rows of which none of its 232 * siblings are referenced. To phrase this differently, signals are only 233 * required for levels in which nodes are referenced. For the root level 234 * however, signals must be emitted at all times (however the root level 235 * is always referenced when any view is attached). 236 */ 237 public template TreeModelT(TStruct) 238 { 239 /** Get the main Gtk struct */ 240 public GtkTreeModel* getTreeModelStruct() 241 { 242 return cast(GtkTreeModel*)getStruct(); 243 } 244 245 /** 246 * Get the value of a column as a char array. 247 * this is the same calling getValue and get the string from the value object 248 */ 249 string getValueString(TreeIter iter, int column) 250 { 251 Value value = getValue(iter, column); 252 return value.getString(); 253 } 254 255 /** 256 * Get the value of a column as a char array. 257 * this is the same calling getValue and get the int from the value object 258 */ 259 int getValueInt(TreeIter iter, int column) 260 { 261 Value value = getValue(iter, column); 262 return value.getInt(); 263 } 264 265 /** 266 * Sets iter to a valid iterator pointing to path. 267 * Params: 268 * iter = The uninitialized GtkTreeIter. 269 * path = The GtkTreePath. 270 * Returns: 271 * TRUE, if iter was set. 272 */ 273 public int getIter(TreeIter iter, TreePath path) 274 { 275 iter.setModel(this); 276 return gtk_tree_model_get_iter( 277 getTreeModelStruct(), 278 (iter is null) ? null : iter.getTreeIterStruct(), 279 (path is null) ? null : path.getTreePathStruct()); 280 } 281 282 /** 283 * Initializes and sets value to that at column. 284 * When done with value, g_value_unset() needs to be called 285 * to free any allocated memory. 286 * Params: 287 * iter = The GtkTreeIter. 288 * column = The column to lookup the value at. 289 * value = (inout) (transfer none) An empty GValue to set. 290 */ 291 public Value getValue(TreeIter iter, int column, Value value = null) 292 { 293 if ( value is null ) 294 value = new Value(); 295 296 gtk_tree_model_get_value(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct(), column, (value is null) ? null : value.getValueStruct()); 297 298 return value; 299 } 300 301 /** 302 */ 303 304 /** 305 * Creates a new #GtkTreeModel, with @child_model as the child_model 306 * and @root as the virtual root. 307 * 308 * Params: 309 * root = A #GtkTreePath or %NULL. 310 * 311 * Return: A new #GtkTreeModel. 312 * 313 * Since: 2.4 314 */ 315 public TreeModelIF filterNew(TreePath root) 316 { 317 auto p = gtk_tree_model_filter_new(getTreeModelStruct(), (root is null) ? null : root.getTreePathStruct()); 318 319 if(p is null) 320 { 321 return null; 322 } 323 324 return ObjectG.getDObject!(TreeModel, TreeModelIF)(cast(GtkTreeModel*) p, true); 325 } 326 327 /** 328 * Calls func on each node in model in a depth-first fashion. 329 * 330 * If @func returns %TRUE, then the tree ceases to be walked, 331 * and gtk_tree_model_foreach() returns. 332 * 333 * Params: 334 * func = a function to be called on each row 335 * userData = user data to passed to @func 336 */ 337 public void foreac(GtkTreeModelForeachFunc func, void* userData) 338 { 339 gtk_tree_model_foreach(getTreeModelStruct(), func, userData); 340 } 341 342 /** 343 * Returns the type of the column. 344 * 345 * Params: 346 * index = the column index 347 * 348 * Return: the type of the column 349 */ 350 public GType getColumnType(int index) 351 { 352 return gtk_tree_model_get_column_type(getTreeModelStruct(), index); 353 } 354 355 /** 356 * Returns a set of flags supported by this interface. 357 * 358 * The flags are a bitwise combination of #GtkTreeModelFlags. 359 * The flags supported should not change during the lifetime 360 * of the @tree_model. 361 * 362 * Return: the flags supported by this interface 363 */ 364 public GtkTreeModelFlags getFlags() 365 { 366 return gtk_tree_model_get_flags(getTreeModelStruct()); 367 } 368 369 /** 370 * Initializes @iter with the first iterator in the tree 371 * (the one at the path "0") and returns %TRUE. Returns 372 * %FALSE if the tree is empty. 373 * 374 * Params: 375 * iter = the uninitialized #GtkTreeIter-struct 376 * 377 * Return: %TRUE, if @iter was set 378 */ 379 public bool getIterFirst(out TreeIter iter) 380 { 381 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 382 383 auto p = gtk_tree_model_get_iter_first(getTreeModelStruct(), outiter) != 0; 384 385 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 386 387 return p; 388 } 389 390 /** 391 * Sets @iter to a valid iterator pointing to @path_string, if it 392 * exists. Otherwise, @iter is left invalid and %FALSE is returned. 393 * 394 * Params: 395 * iter = an uninitialized #GtkTreeIter-struct 396 * pathString = a string representation of a #GtkTreePath-struct 397 * 398 * Return: %TRUE, if @iter was set 399 */ 400 public bool getIterFromString(out TreeIter iter, string pathString) 401 { 402 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 403 404 auto p = gtk_tree_model_get_iter_from_string(getTreeModelStruct(), outiter, Str.toStringz(pathString)) != 0; 405 406 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 407 408 return p; 409 } 410 411 /** 412 * Returns the number of columns supported by @tree_model. 413 * 414 * Return: the number of columns 415 */ 416 public int getNColumns() 417 { 418 return gtk_tree_model_get_n_columns(getTreeModelStruct()); 419 } 420 421 /** 422 * Returns a newly-created #GtkTreePath-struct referenced by @iter. 423 * 424 * This path should be freed with gtk_tree_path_free(). 425 * 426 * Params: 427 * iter = the #GtkTreeIter-struct 428 * 429 * Return: a newly-created #GtkTreePath-struct 430 */ 431 public TreePath getPath(TreeIter iter) 432 { 433 auto p = gtk_tree_model_get_path(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct()); 434 435 if(p is null) 436 { 437 return null; 438 } 439 440 return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) p, true); 441 } 442 443 /** 444 * Generates a string representation of the iter. 445 * 446 * This string is a “:” separated list of numbers. 447 * For example, “4:10:0:3” would be an acceptable 448 * return value for this string. 449 * 450 * Params: 451 * iter = a #GtkTreeIter-struct 452 * 453 * Return: a newly-allocated string. 454 * Must be freed with g_free(). 455 * 456 * Since: 2.2 457 */ 458 public string getStringFromIter(TreeIter iter) 459 { 460 auto retStr = gtk_tree_model_get_string_from_iter(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct()); 461 462 scope(exit) Str.freeString(retStr); 463 return Str.toString(retStr); 464 } 465 466 /** 467 * See gtk_tree_model_get(), this version takes a va_list 468 * for language bindings to use. 469 * 470 * Params: 471 * iter = a row in @tree_model 472 * varArgs = va_list of column/return location pairs 473 */ 474 public void getValist(TreeIter iter, void* varArgs) 475 { 476 gtk_tree_model_get_valist(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct(), varArgs); 477 } 478 479 /** 480 * Sets @iter to point to the first child of @parent. 481 * 482 * If @parent has no children, %FALSE is returned and @iter is 483 * set to be invalid. @parent will remain a valid node after this 484 * function has been called. 485 * 486 * If @parent is %NULL returns the first node, equivalent to 487 * `gtk_tree_model_get_iter_first (tree_model, iter);` 488 * 489 * Params: 490 * iter = the new #GtkTreeIter-struct to be set to the child 491 * parent = the #GtkTreeIter-struct, or %NULL 492 * 493 * Return: %TRUE, if @iter has been set to the first child 494 */ 495 public bool iterChildren(out TreeIter iter, TreeIter parent) 496 { 497 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 498 499 auto p = gtk_tree_model_iter_children(getTreeModelStruct(), outiter, (parent is null) ? null : parent.getTreeIterStruct()) != 0; 500 501 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 502 503 return p; 504 } 505 506 /** 507 * Returns %TRUE if @iter has children, %FALSE otherwise. 508 * 509 * Params: 510 * iter = the #GtkTreeIter-struct to test for children 511 * 512 * Return: %TRUE if @iter has children 513 */ 514 public bool iterHasChild(TreeIter iter) 515 { 516 return gtk_tree_model_iter_has_child(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct()) != 0; 517 } 518 519 /** 520 * Returns the number of children that @iter has. 521 * 522 * As a special case, if @iter is %NULL, then the number 523 * of toplevel nodes is returned. 524 * 525 * Params: 526 * iter = the #GtkTreeIter-struct, or %NULL 527 * 528 * Return: the number of children of @iter 529 */ 530 public int iterNChildren(TreeIter iter) 531 { 532 return gtk_tree_model_iter_n_children(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct()); 533 } 534 535 /** 536 * Sets @iter to point to the node following it at the current level. 537 * 538 * If there is no next @iter, %FALSE is returned and @iter is set 539 * to be invalid. 540 * 541 * Params: 542 * iter = the #GtkTreeIter-struct 543 * 544 * Return: %TRUE if @iter has been changed to the next node 545 */ 546 public bool iterNext(TreeIter iter) 547 { 548 return gtk_tree_model_iter_next(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct()) != 0; 549 } 550 551 /** 552 * Sets @iter to be the child of @parent, using the given index. 553 * 554 * The first index is 0. If @n is too big, or @parent has no children, 555 * @iter is set to an invalid iterator and %FALSE is returned. @parent 556 * will remain a valid node after this function has been called. As a 557 * special case, if @parent is %NULL, then the @n-th root node 558 * is set. 559 * 560 * Params: 561 * iter = the #GtkTreeIter-struct to set to the nth child 562 * parent = the #GtkTreeIter-struct to get the child from, or %NULL. 563 * n = the index of the desired child 564 * 565 * Return: %TRUE, if @parent has an @n-th child 566 */ 567 public bool iterNthChild(out TreeIter iter, TreeIter parent, int n) 568 { 569 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 570 571 auto p = gtk_tree_model_iter_nth_child(getTreeModelStruct(), outiter, (parent is null) ? null : parent.getTreeIterStruct(), n) != 0; 572 573 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 574 575 return p; 576 } 577 578 /** 579 * Sets @iter to be the parent of @child. 580 * 581 * If @child is at the toplevel, and doesn’t have a parent, then 582 * @iter is set to an invalid iterator and %FALSE is returned. 583 * @child will remain a valid node after this function has been 584 * called. 585 * 586 * @iter will be initialized before the lookup is performed, so @child 587 * and @iter cannot point to the same memory location. 588 * 589 * Params: 590 * iter = the new #GtkTreeIter-struct to set to the parent 591 * child = the #GtkTreeIter-struct 592 * 593 * Return: %TRUE, if @iter is set to the parent of @child 594 */ 595 public bool iterParent(out TreeIter iter, TreeIter child) 596 { 597 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 598 599 auto p = gtk_tree_model_iter_parent(getTreeModelStruct(), outiter, (child is null) ? null : child.getTreeIterStruct()) != 0; 600 601 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 602 603 return p; 604 } 605 606 /** 607 * Sets @iter to point to the previous node at the current level. 608 * 609 * If there is no previous @iter, %FALSE is returned and @iter is 610 * set to be invalid. 611 * 612 * Params: 613 * iter = the #GtkTreeIter-struct 614 * 615 * Return: %TRUE if @iter has been changed to the previous node 616 * 617 * Since: 3.0 618 */ 619 public bool iterPrevious(TreeIter iter) 620 { 621 return gtk_tree_model_iter_previous(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct()) != 0; 622 } 623 624 /** 625 * Lets the tree ref the node. 626 * 627 * This is an optional method for models to implement. 628 * To be more specific, models may ignore this call as it exists 629 * primarily for performance reasons. 630 * 631 * This function is primarily meant as a way for views to let 632 * caching models know when nodes are being displayed (and hence, 633 * whether or not to cache that node). Being displayed means a node 634 * is in an expanded branch, regardless of whether the node is currently 635 * visible in the viewport. For example, a file-system based model 636 * would not want to keep the entire file-hierarchy in memory, 637 * just the sections that are currently being displayed by 638 * every current view. 639 * 640 * A model should be expected to be able to get an iter independent 641 * of its reffed state. 642 * 643 * Params: 644 * iter = the #GtkTreeIter-struct 645 */ 646 public void refNode(TreeIter iter) 647 { 648 gtk_tree_model_ref_node(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct()); 649 } 650 651 /** 652 * Emits the #GtkTreeModel::row-changed signal on @tree_model. 653 * 654 * Params: 655 * path = a #GtkTreePath-struct pointing to the changed row 656 * iter = a valid #GtkTreeIter-struct pointing to the changed row 657 */ 658 public void rowChanged(TreePath path, TreeIter iter) 659 { 660 gtk_tree_model_row_changed(getTreeModelStruct(), (path is null) ? null : path.getTreePathStruct(), (iter is null) ? null : iter.getTreeIterStruct()); 661 } 662 663 /** 664 * Emits the #GtkTreeModel::row-deleted signal on @tree_model. 665 * 666 * This should be called by models after a row has been removed. 667 * The location pointed to by @path should be the location that 668 * the row previously was at. It may not be a valid location anymore. 669 * 670 * Nodes that are deleted are not unreffed, this means that any 671 * outstanding references on the deleted node should not be released. 672 * 673 * Params: 674 * path = a #GtkTreePath-struct pointing to the previous location of 675 * the deleted row 676 */ 677 public void rowDeleted(TreePath path) 678 { 679 gtk_tree_model_row_deleted(getTreeModelStruct(), (path is null) ? null : path.getTreePathStruct()); 680 } 681 682 /** 683 * Emits the #GtkTreeModel::row-has-child-toggled signal on 684 * @tree_model. This should be called by models after the child 685 * state of a node changes. 686 * 687 * Params: 688 * path = a #GtkTreePath-struct pointing to the changed row 689 * iter = a valid #GtkTreeIter-struct pointing to the changed row 690 */ 691 public void rowHasChildToggled(TreePath path, TreeIter iter) 692 { 693 gtk_tree_model_row_has_child_toggled(getTreeModelStruct(), (path is null) ? null : path.getTreePathStruct(), (iter is null) ? null : iter.getTreeIterStruct()); 694 } 695 696 /** 697 * Emits the #GtkTreeModel::row-inserted signal on @tree_model. 698 * 699 * Params: 700 * path = a #GtkTreePath-struct pointing to the inserted row 701 * iter = a valid #GtkTreeIter-struct pointing to the inserted row 702 */ 703 public void rowInserted(TreePath path, TreeIter iter) 704 { 705 gtk_tree_model_row_inserted(getTreeModelStruct(), (path is null) ? null : path.getTreePathStruct(), (iter is null) ? null : iter.getTreeIterStruct()); 706 } 707 708 /** 709 * Emits the #GtkTreeModel::rows-reordered signal on @tree_model. 710 * 711 * This should be called by models when their rows have been 712 * reordered. 713 * 714 * Params: 715 * path = a #GtkTreePath-struct pointing to the tree node whose children 716 * have been reordered 717 * iter = a valid #GtkTreeIter-struct pointing to the node whose children 718 * have been reordered, or %NULL if the depth of @path is 0 719 * newOrder = an array of integers mapping the current position of 720 * each child to its old position before the re-ordering, 721 * i.e. @new_order`[newpos] = oldpos` 722 */ 723 public void rowsReordered(TreePath path, TreeIter iter, int* newOrder) 724 { 725 gtk_tree_model_rows_reordered(getTreeModelStruct(), (path is null) ? null : path.getTreePathStruct(), (iter is null) ? null : iter.getTreeIterStruct(), newOrder); 726 } 727 728 /** 729 * Emits the #GtkTreeModel::rows-reordered signal on @tree_model. 730 * 731 * This should be called by models when their rows have been 732 * reordered. 733 * 734 * Params: 735 * path = a #GtkTreePath-struct pointing to the tree node whose children 736 * have been reordered 737 * iter = a valid #GtkTreeIter-struct pointing to the node 738 * whose children have been reordered, or %NULL if the depth 739 * of @path is 0 740 * newOrder = an array of integers 741 * mapping the current position of each child to its old 742 * position before the re-ordering, 743 * i.e. @new_order`[newpos] = oldpos` 744 * length = length of @new_order array 745 * 746 * Since: 3.10 747 */ 748 public void rowsReorderedWithLength(TreePath path, TreeIter iter, int[] newOrder) 749 { 750 gtk_tree_model_rows_reordered_with_length(getTreeModelStruct(), (path is null) ? null : path.getTreePathStruct(), (iter is null) ? null : iter.getTreeIterStruct(), newOrder.ptr, cast(int)newOrder.length); 751 } 752 753 /** 754 * Creates a new #GtkTreeModel, with @child_model as the child model. 755 * 756 * Return: A new #GtkTreeModel. 757 */ 758 public TreeModelIF sortNewWithModel() 759 { 760 auto p = gtk_tree_model_sort_new_with_model(getTreeModelStruct()); 761 762 if(p is null) 763 { 764 return null; 765 } 766 767 return ObjectG.getDObject!(TreeModel, TreeModelIF)(cast(GtkTreeModel*) p, true); 768 } 769 770 /** 771 * Lets the tree unref the node. 772 * 773 * This is an optional method for models to implement. 774 * To be more specific, models may ignore this call as it exists 775 * primarily for performance reasons. For more information on what 776 * this means, see gtk_tree_model_ref_node(). 777 * 778 * Please note that nodes that are deleted are not unreffed. 779 * 780 * Params: 781 * iter = the #GtkTreeIter-struct 782 */ 783 public void unrefNode(TreeIter iter) 784 { 785 gtk_tree_model_unref_node(getTreeModelStruct(), (iter is null) ? null : iter.getTreeIterStruct()); 786 } 787 788 protected class OnRowChangedDelegateWrapper 789 { 790 void delegate(TreePath, TreeIter, TreeModelIF) dlg; 791 gulong handlerId; 792 ConnectFlags flags; 793 this(void delegate(TreePath, TreeIter, TreeModelIF) dlg, gulong handlerId, ConnectFlags flags) 794 { 795 this.dlg = dlg; 796 this.handlerId = handlerId; 797 this.flags = flags; 798 } 799 } 800 protected OnRowChangedDelegateWrapper[] onRowChangedListeners; 801 802 /** 803 * This signal is emitted when a row in the model has changed. 804 * 805 * Params: 806 * path = a #GtkTreePath-struct identifying the changed row 807 * iter = a valid #GtkTreeIter-struct pointing to the changed row 808 */ 809 gulong addOnRowChanged(void delegate(TreePath, TreeIter, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 810 { 811 onRowChangedListeners ~= new OnRowChangedDelegateWrapper(dlg, 0, connectFlags); 812 onRowChangedListeners[onRowChangedListeners.length - 1].handlerId = Signals.connectData( 813 this, 814 "row-changed", 815 cast(GCallback)&callBackRowChanged, 816 cast(void*)onRowChangedListeners[onRowChangedListeners.length - 1], 817 cast(GClosureNotify)&callBackRowChangedDestroy, 818 connectFlags); 819 return onRowChangedListeners[onRowChangedListeners.length - 1].handlerId; 820 } 821 822 extern(C) static void callBackRowChanged(GtkTreeModel* treemodelStruct, GtkTreePath* path, GtkTreeIter* iter,OnRowChangedDelegateWrapper wrapper) 823 { 824 wrapper.dlg(ObjectG.getDObject!(TreePath)(path), ObjectG.getDObject!(TreeIter)(iter), wrapper.outer); 825 } 826 827 extern(C) static void callBackRowChangedDestroy(OnRowChangedDelegateWrapper wrapper, GClosure* closure) 828 { 829 wrapper.outer.internalRemoveOnRowChanged(wrapper); 830 } 831 832 protected void internalRemoveOnRowChanged(OnRowChangedDelegateWrapper source) 833 { 834 foreach(index, wrapper; onRowChangedListeners) 835 { 836 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 837 { 838 onRowChangedListeners[index] = null; 839 onRowChangedListeners = std.algorithm.remove(onRowChangedListeners, index); 840 break; 841 } 842 } 843 } 844 845 846 protected class OnRowDeletedDelegateWrapper 847 { 848 void delegate(TreePath, TreeModelIF) dlg; 849 gulong handlerId; 850 ConnectFlags flags; 851 this(void delegate(TreePath, TreeModelIF) dlg, gulong handlerId, ConnectFlags flags) 852 { 853 this.dlg = dlg; 854 this.handlerId = handlerId; 855 this.flags = flags; 856 } 857 } 858 protected OnRowDeletedDelegateWrapper[] onRowDeletedListeners; 859 860 /** 861 * This signal is emitted when a row has been deleted. 862 * 863 * Note that no iterator is passed to the signal handler, 864 * since the row is already deleted. 865 * 866 * This should be called by models after a row has been removed. 867 * The location pointed to by @path should be the location that 868 * the row previously was at. It may not be a valid location anymore. 869 * 870 * Params: 871 * path = a #GtkTreePath-struct identifying the row 872 */ 873 gulong addOnRowDeleted(void delegate(TreePath, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 874 { 875 onRowDeletedListeners ~= new OnRowDeletedDelegateWrapper(dlg, 0, connectFlags); 876 onRowDeletedListeners[onRowDeletedListeners.length - 1].handlerId = Signals.connectData( 877 this, 878 "row-deleted", 879 cast(GCallback)&callBackRowDeleted, 880 cast(void*)onRowDeletedListeners[onRowDeletedListeners.length - 1], 881 cast(GClosureNotify)&callBackRowDeletedDestroy, 882 connectFlags); 883 return onRowDeletedListeners[onRowDeletedListeners.length - 1].handlerId; 884 } 885 886 extern(C) static void callBackRowDeleted(GtkTreeModel* treemodelStruct, GtkTreePath* path,OnRowDeletedDelegateWrapper wrapper) 887 { 888 wrapper.dlg(ObjectG.getDObject!(TreePath)(path), wrapper.outer); 889 } 890 891 extern(C) static void callBackRowDeletedDestroy(OnRowDeletedDelegateWrapper wrapper, GClosure* closure) 892 { 893 wrapper.outer.internalRemoveOnRowDeleted(wrapper); 894 } 895 896 protected void internalRemoveOnRowDeleted(OnRowDeletedDelegateWrapper source) 897 { 898 foreach(index, wrapper; onRowDeletedListeners) 899 { 900 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 901 { 902 onRowDeletedListeners[index] = null; 903 onRowDeletedListeners = std.algorithm.remove(onRowDeletedListeners, index); 904 break; 905 } 906 } 907 } 908 909 910 protected class OnRowHasChildToggledDelegateWrapper 911 { 912 void delegate(TreePath, TreeIter, TreeModelIF) dlg; 913 gulong handlerId; 914 ConnectFlags flags; 915 this(void delegate(TreePath, TreeIter, TreeModelIF) dlg, gulong handlerId, ConnectFlags flags) 916 { 917 this.dlg = dlg; 918 this.handlerId = handlerId; 919 this.flags = flags; 920 } 921 } 922 protected OnRowHasChildToggledDelegateWrapper[] onRowHasChildToggledListeners; 923 924 /** 925 * This signal is emitted when a row has gotten the first child 926 * row or lost its last child row. 927 * 928 * Params: 929 * path = a #GtkTreePath-struct identifying the row 930 * iter = a valid #GtkTreeIter-struct pointing to the row 931 */ 932 gulong addOnRowHasChildToggled(void delegate(TreePath, TreeIter, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 933 { 934 onRowHasChildToggledListeners ~= new OnRowHasChildToggledDelegateWrapper(dlg, 0, connectFlags); 935 onRowHasChildToggledListeners[onRowHasChildToggledListeners.length - 1].handlerId = Signals.connectData( 936 this, 937 "row-has-child-toggled", 938 cast(GCallback)&callBackRowHasChildToggled, 939 cast(void*)onRowHasChildToggledListeners[onRowHasChildToggledListeners.length - 1], 940 cast(GClosureNotify)&callBackRowHasChildToggledDestroy, 941 connectFlags); 942 return onRowHasChildToggledListeners[onRowHasChildToggledListeners.length - 1].handlerId; 943 } 944 945 extern(C) static void callBackRowHasChildToggled(GtkTreeModel* treemodelStruct, GtkTreePath* path, GtkTreeIter* iter,OnRowHasChildToggledDelegateWrapper wrapper) 946 { 947 wrapper.dlg(ObjectG.getDObject!(TreePath)(path), ObjectG.getDObject!(TreeIter)(iter), wrapper.outer); 948 } 949 950 extern(C) static void callBackRowHasChildToggledDestroy(OnRowHasChildToggledDelegateWrapper wrapper, GClosure* closure) 951 { 952 wrapper.outer.internalRemoveOnRowHasChildToggled(wrapper); 953 } 954 955 protected void internalRemoveOnRowHasChildToggled(OnRowHasChildToggledDelegateWrapper source) 956 { 957 foreach(index, wrapper; onRowHasChildToggledListeners) 958 { 959 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 960 { 961 onRowHasChildToggledListeners[index] = null; 962 onRowHasChildToggledListeners = std.algorithm.remove(onRowHasChildToggledListeners, index); 963 break; 964 } 965 } 966 } 967 968 969 protected class OnRowInsertedDelegateWrapper 970 { 971 void delegate(TreePath, TreeIter, TreeModelIF) dlg; 972 gulong handlerId; 973 ConnectFlags flags; 974 this(void delegate(TreePath, TreeIter, TreeModelIF) dlg, gulong handlerId, ConnectFlags flags) 975 { 976 this.dlg = dlg; 977 this.handlerId = handlerId; 978 this.flags = flags; 979 } 980 } 981 protected OnRowInsertedDelegateWrapper[] onRowInsertedListeners; 982 983 /** 984 * This signal is emitted when a new row has been inserted in 985 * the model. 986 * 987 * Note that the row may still be empty at this point, since 988 * it is a common pattern to first insert an empty row, and 989 * then fill it with the desired values. 990 * 991 * Params: 992 * path = a #GtkTreePath-struct identifying the new row 993 * iter = a valid #GtkTreeIter-struct pointing to the new row 994 */ 995 gulong addOnRowInserted(void delegate(TreePath, TreeIter, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 996 { 997 onRowInsertedListeners ~= new OnRowInsertedDelegateWrapper(dlg, 0, connectFlags); 998 onRowInsertedListeners[onRowInsertedListeners.length - 1].handlerId = Signals.connectData( 999 this, 1000 "row-inserted", 1001 cast(GCallback)&callBackRowInserted, 1002 cast(void*)onRowInsertedListeners[onRowInsertedListeners.length - 1], 1003 cast(GClosureNotify)&callBackRowInsertedDestroy, 1004 connectFlags); 1005 return onRowInsertedListeners[onRowInsertedListeners.length - 1].handlerId; 1006 } 1007 1008 extern(C) static void callBackRowInserted(GtkTreeModel* treemodelStruct, GtkTreePath* path, GtkTreeIter* iter,OnRowInsertedDelegateWrapper wrapper) 1009 { 1010 wrapper.dlg(ObjectG.getDObject!(TreePath)(path), ObjectG.getDObject!(TreeIter)(iter), wrapper.outer); 1011 } 1012 1013 extern(C) static void callBackRowInsertedDestroy(OnRowInsertedDelegateWrapper wrapper, GClosure* closure) 1014 { 1015 wrapper.outer.internalRemoveOnRowInserted(wrapper); 1016 } 1017 1018 protected void internalRemoveOnRowInserted(OnRowInsertedDelegateWrapper source) 1019 { 1020 foreach(index, wrapper; onRowInsertedListeners) 1021 { 1022 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1023 { 1024 onRowInsertedListeners[index] = null; 1025 onRowInsertedListeners = std.algorithm.remove(onRowInsertedListeners, index); 1026 break; 1027 } 1028 } 1029 } 1030 1031 1032 protected class OnRowsReorderedDelegateWrapper 1033 { 1034 void delegate(TreePath, TreeIter, void*, TreeModelIF) dlg; 1035 gulong handlerId; 1036 ConnectFlags flags; 1037 this(void delegate(TreePath, TreeIter, void*, TreeModelIF) dlg, gulong handlerId, ConnectFlags flags) 1038 { 1039 this.dlg = dlg; 1040 this.handlerId = handlerId; 1041 this.flags = flags; 1042 } 1043 } 1044 protected OnRowsReorderedDelegateWrapper[] onRowsReorderedListeners; 1045 1046 /** 1047 * This signal is emitted when the children of a node in the 1048 * #GtkTreeModel have been reordered. 1049 * 1050 * Note that this signal is not emitted 1051 * when rows are reordered by DND, since this is implemented 1052 * by removing and then reinserting the row. 1053 * 1054 * Params: 1055 * path = a #GtkTreePath-struct identifying the tree node whose children 1056 * have been reordered 1057 * iter = a valid #GtkTreeIter-struct pointing to the node whose children 1058 * have been reordered, or %NULL if the depth of @path is 0 1059 * newOrder = an array of integers mapping the current position 1060 * of each child to its old position before the re-ordering, 1061 * i.e. @new_order`[newpos] = oldpos` 1062 */ 1063 gulong addOnRowsReordered(void delegate(TreePath, TreeIter, void*, TreeModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1064 { 1065 onRowsReorderedListeners ~= new OnRowsReorderedDelegateWrapper(dlg, 0, connectFlags); 1066 onRowsReorderedListeners[onRowsReorderedListeners.length - 1].handlerId = Signals.connectData( 1067 this, 1068 "rows-reordered", 1069 cast(GCallback)&callBackRowsReordered, 1070 cast(void*)onRowsReorderedListeners[onRowsReorderedListeners.length - 1], 1071 cast(GClosureNotify)&callBackRowsReorderedDestroy, 1072 connectFlags); 1073 return onRowsReorderedListeners[onRowsReorderedListeners.length - 1].handlerId; 1074 } 1075 1076 extern(C) static void callBackRowsReordered(GtkTreeModel* treemodelStruct, GtkTreePath* path, GtkTreeIter* iter, void* newOrder,OnRowsReorderedDelegateWrapper wrapper) 1077 { 1078 wrapper.dlg(ObjectG.getDObject!(TreePath)(path), ObjectG.getDObject!(TreeIter)(iter), newOrder, wrapper.outer); 1079 } 1080 1081 extern(C) static void callBackRowsReorderedDestroy(OnRowsReorderedDelegateWrapper wrapper, GClosure* closure) 1082 { 1083 wrapper.outer.internalRemoveOnRowsReordered(wrapper); 1084 } 1085 1086 protected void internalRemoveOnRowsReordered(OnRowsReorderedDelegateWrapper source) 1087 { 1088 foreach(index, wrapper; onRowsReorderedListeners) 1089 { 1090 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1091 { 1092 onRowsReorderedListeners[index] = null; 1093 onRowsReorderedListeners = std.algorithm.remove(onRowsReorderedListeners, index); 1094 break; 1095 } 1096 } 1097 } 1098 1099 }