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