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.WidgetPath; 26 27 private import glib.ConstructionException; 28 private import glib.ListSG; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gtk.Widget; 32 private import gtkc.gtk; 33 public import gtkc.gtktypes; 34 private import gtkd.Loader; 35 private import gtkd.paths; 36 37 38 /** 39 * GtkWidgetPath is a boxed type that represents a widget hierarchy from 40 * the topmost widget, typically a toplevel, to any child. This widget 41 * path abstraction is used in #GtkStyleContext on behalf of the real 42 * widget in order to query style information. 43 * 44 * If you are using GTK+ widgets, you probably will not need to use 45 * this API directly, as there is gtk_widget_get_path(), and the style 46 * context returned by gtk_widget_get_style_context() will be automatically 47 * updated on widget hierarchy changes. 48 * 49 * The widget path generation is generally simple: 50 * 51 * ## Defining a button within a window 52 * 53 * |[<!-- language="C" --> 54 * { 55 * GtkWidgetPath *path; 56 * 57 * path = gtk_widget_path_new (); 58 * gtk_widget_path_append_type (path, GTK_TYPE_WINDOW); 59 * gtk_widget_path_append_type (path, GTK_TYPE_BUTTON); 60 * } 61 * ]| 62 * 63 * Although more complex information, such as widget names, or 64 * different classes (property that may be used by other widget 65 * types) and intermediate regions may be included: 66 * 67 * ## Defining the first tab widget in a notebook 68 * 69 * |[<!-- language="C" --> 70 * { 71 * GtkWidgetPath *path; 72 * guint pos; 73 * 74 * path = gtk_widget_path_new (); 75 * 76 * pos = gtk_widget_path_append_type (path, GTK_TYPE_NOTEBOOK); 77 * gtk_widget_path_iter_add_region (path, pos, "tab", GTK_REGION_EVEN | GTK_REGION_FIRST); 78 * 79 * pos = gtk_widget_path_append_type (path, GTK_TYPE_LABEL); 80 * gtk_widget_path_iter_set_name (path, pos, "first tab label"); 81 * } 82 * ]| 83 * 84 * All this information will be used to match the style information 85 * that applies to the described widget. 86 */ 87 public class WidgetPath 88 { 89 /** the main Gtk struct */ 90 protected GtkWidgetPath* gtkWidgetPath; 91 protected bool ownedRef; 92 93 /** Get the main Gtk struct */ 94 public GtkWidgetPath* getWidgetPathStruct() 95 { 96 return gtkWidgetPath; 97 } 98 99 /** the main Gtk struct as a void* */ 100 protected void* getStruct() 101 { 102 return cast(void*)gtkWidgetPath; 103 } 104 105 /** 106 * Sets our main struct and passes it to the parent class. 107 */ 108 public this (GtkWidgetPath* gtkWidgetPath, bool ownedRef = false) 109 { 110 this.gtkWidgetPath = gtkWidgetPath; 111 this.ownedRef = ownedRef; 112 } 113 114 ~this () 115 { 116 if ( Linker.isLoaded(LIBRARY.GTK) && ownedRef ) 117 { 118 gtk_widget_path_free(gtkWidgetPath); 119 } 120 } 121 122 /** 123 */ 124 125 /** */ 126 public static GType getType() 127 { 128 return gtk_widget_path_get_type(); 129 } 130 131 /** 132 * Returns an empty widget path. 133 * 134 * Returns: A newly created, empty, #GtkWidgetPath 135 * 136 * Since: 3.0 137 * 138 * Throws: ConstructionException GTK+ fails to create the object. 139 */ 140 public this() 141 { 142 auto p = gtk_widget_path_new(); 143 144 if(p is null) 145 { 146 throw new ConstructionException("null returned by new"); 147 } 148 149 this(cast(GtkWidgetPath*) p); 150 } 151 152 /** 153 * Appends the data from @widget to the widget hierarchy represented 154 * by @path. This function is a shortcut for adding information from 155 * @widget to the given @path. This includes setting the name or 156 * adding the style classes from @widget. 157 * 158 * Params: 159 * widget = the widget to append to the widget path 160 * 161 * Returns: the position where the data was inserted 162 * 163 * Since: 3.2 164 */ 165 public int appendForWidget(Widget widget) 166 { 167 return gtk_widget_path_append_for_widget(gtkWidgetPath, (widget is null) ? null : widget.getWidgetStruct()); 168 } 169 170 /** 171 * Appends a widget type to the widget hierarchy represented by @path. 172 * 173 * Params: 174 * type = widget type to append 175 * 176 * Returns: the position where the element was inserted 177 * 178 * Since: 3.0 179 */ 180 public int appendType(GType type) 181 { 182 return gtk_widget_path_append_type(gtkWidgetPath, type); 183 } 184 185 /** 186 * Appends a widget type with all its siblings to the widget hierarchy 187 * represented by @path. Using this function instead of 188 * gtk_widget_path_append_type() will allow the CSS theming to use 189 * sibling matches in selectors and apply :nth-child() pseudo classes. 190 * In turn, it requires a lot more care in widget implementations as 191 * widgets need to make sure to call gtk_widget_reset_style() on all 192 * involved widgets when the @siblings path changes. 193 * 194 * Params: 195 * siblings = a widget path describing a list of siblings. This path 196 * may not contain any siblings itself and it must not be modified 197 * afterwards. 198 * siblingIndex = index into @siblings for where the added element is 199 * positioned. 200 * 201 * Returns: the position where the element was inserted. 202 * 203 * Since: 3.2 204 */ 205 public int appendWithSiblings(WidgetPath siblings, uint siblingIndex) 206 { 207 return gtk_widget_path_append_with_siblings(gtkWidgetPath, (siblings is null) ? null : siblings.getWidgetPathStruct(), siblingIndex); 208 } 209 210 /** 211 * Returns a copy of @path 212 * 213 * Returns: a copy of @path 214 * 215 * Since: 3.0 216 */ 217 public WidgetPath copy() 218 { 219 auto p = gtk_widget_path_copy(gtkWidgetPath); 220 221 if(p is null) 222 { 223 return null; 224 } 225 226 return ObjectG.getDObject!(WidgetPath)(cast(GtkWidgetPath*) p, true); 227 } 228 229 /** 230 * Decrements the reference count on @path, freeing the structure 231 * if the reference count reaches 0. 232 * 233 * Since: 3.0 234 */ 235 public void free() 236 { 237 gtk_widget_path_free(gtkWidgetPath); 238 } 239 240 /** 241 * Returns the topmost object type, that is, the object type this path 242 * is representing. 243 * 244 * Returns: The object type 245 * 246 * Since: 3.0 247 */ 248 public GType getObjectType() 249 { 250 return gtk_widget_path_get_object_type(gtkWidgetPath); 251 } 252 253 /** 254 * Returns %TRUE if any of the parents of the widget represented 255 * in @path is of type @type, or any subtype of it. 256 * 257 * Params: 258 * type = widget type to check in parents 259 * 260 * Returns: %TRUE if any parent is of type @type 261 * 262 * Since: 3.0 263 */ 264 public bool hasParent(GType type) 265 { 266 return gtk_widget_path_has_parent(gtkWidgetPath, type) != 0; 267 } 268 269 /** 270 * Returns %TRUE if the widget type represented by this path 271 * is @type, or a subtype of it. 272 * 273 * Params: 274 * type = widget type to match 275 * 276 * Returns: %TRUE if the widget represented by @path is of type @type 277 * 278 * Since: 3.0 279 */ 280 public bool isType(GType type) 281 { 282 return gtk_widget_path_is_type(gtkWidgetPath, type) != 0; 283 } 284 285 /** 286 * Adds the class @name to the widget at position @pos in 287 * the hierarchy defined in @path. See 288 * gtk_style_context_add_class(). 289 * 290 * Params: 291 * pos = position to modify, -1 for the path head 292 * name = a class name 293 * 294 * Since: 3.0 295 */ 296 public void iterAddClass(int pos, string name) 297 { 298 gtk_widget_path_iter_add_class(gtkWidgetPath, pos, Str.toStringz(name)); 299 } 300 301 /** 302 * Adds the region @name to the widget at position @pos in 303 * the hierarchy defined in @path. See 304 * gtk_style_context_add_region(). 305 * 306 * Region names must only contain lowercase letters 307 * and “-”, starting always with a lowercase letter. 308 * 309 * Deprecated: The use of regions is deprecated. 310 * 311 * Params: 312 * pos = position to modify, -1 for the path head 313 * name = region name 314 * flags = flags affecting the region 315 * 316 * Since: 3.0 317 */ 318 public void iterAddRegion(int pos, string name, GtkRegionFlags flags) 319 { 320 gtk_widget_path_iter_add_region(gtkWidgetPath, pos, Str.toStringz(name), flags); 321 } 322 323 /** 324 * Removes all classes from the widget at position @pos in the 325 * hierarchy defined in @path. 326 * 327 * Params: 328 * pos = position to modify, -1 for the path head 329 * 330 * Since: 3.0 331 */ 332 public void iterClearClasses(int pos) 333 { 334 gtk_widget_path_iter_clear_classes(gtkWidgetPath, pos); 335 } 336 337 /** 338 * Removes all regions from the widget at position @pos in the 339 * hierarchy defined in @path. 340 * 341 * Deprecated: The use of regions is deprecated. 342 * 343 * Params: 344 * pos = position to modify, -1 for the path head 345 * 346 * Since: 3.0 347 */ 348 public void iterClearRegions(int pos) 349 { 350 gtk_widget_path_iter_clear_regions(gtkWidgetPath, pos); 351 } 352 353 /** 354 * Returns the name corresponding to the widget found at 355 * the position @pos in the widget hierarchy defined by 356 * @path 357 * 358 * Params: 359 * pos = position to get the widget name for, -1 for the path head 360 * 361 * Returns: The widget name, or %NULL if none was set. 362 */ 363 public string iterGetName(int pos) 364 { 365 return Str.toString(gtk_widget_path_iter_get_name(gtkWidgetPath, pos)); 366 } 367 368 /** 369 * Returns the object name that is at position @pos in the widget 370 * hierarchy defined in @path. 371 * 372 * Params: 373 * pos = position to get the object name for, -1 for the path head 374 * 375 * Returns: the name or %NULL 376 * 377 * Since: 3.20 378 */ 379 public string iterGetObjectName(int pos) 380 { 381 return Str.toString(gtk_widget_path_iter_get_object_name(gtkWidgetPath, pos)); 382 } 383 384 /** 385 * Returns the object #GType that is at position @pos in the widget 386 * hierarchy defined in @path. 387 * 388 * Params: 389 * pos = position to get the object type for, -1 for the path head 390 * 391 * Returns: a widget type 392 * 393 * Since: 3.0 394 */ 395 public GType iterGetObjectType(int pos) 396 { 397 return gtk_widget_path_iter_get_object_type(gtkWidgetPath, pos); 398 } 399 400 /** 401 * Returns the index into the list of siblings for the element at @pos as 402 * returned by gtk_widget_path_iter_get_siblings(). If that function would 403 * return %NULL because the element at @pos has no siblings, this function 404 * will return 0. 405 * 406 * Params: 407 * pos = position to get the sibling index for, -1 for the path head 408 * 409 * Returns: 0 or the index into the list of siblings for the element at @pos. 410 */ 411 public uint iterGetSiblingIndex(int pos) 412 { 413 return gtk_widget_path_iter_get_sibling_index(gtkWidgetPath, pos); 414 } 415 416 /** 417 * Returns the list of siblings for the element at @pos. If the element 418 * was not added with siblings, %NULL is returned. 419 * 420 * Params: 421 * pos = position to get the siblings for, -1 for the path head 422 * 423 * Returns: %NULL or the list of siblings for the element at @pos. 424 */ 425 public WidgetPath iterGetSiblings(int pos) 426 { 427 auto p = gtk_widget_path_iter_get_siblings(gtkWidgetPath, pos); 428 429 if(p is null) 430 { 431 return null; 432 } 433 434 return ObjectG.getDObject!(WidgetPath)(cast(GtkWidgetPath*) p); 435 } 436 437 /** 438 * Returns the state flags corresponding to the widget found at 439 * the position @pos in the widget hierarchy defined by 440 * @path 441 * 442 * Params: 443 * pos = position to get the state for, -1 for the path head 444 * 445 * Returns: The state flags 446 * 447 * Since: 3.14 448 */ 449 public GtkStateFlags iterGetState(int pos) 450 { 451 return gtk_widget_path_iter_get_state(gtkWidgetPath, pos); 452 } 453 454 /** 455 * Returns %TRUE if the widget at position @pos has the class @name 456 * defined, %FALSE otherwise. 457 * 458 * Params: 459 * pos = position to query, -1 for the path head 460 * name = class name 461 * 462 * Returns: %TRUE if the class @name is defined for the widget at @pos 463 * 464 * Since: 3.0 465 */ 466 public bool iterHasClass(int pos, string name) 467 { 468 return gtk_widget_path_iter_has_class(gtkWidgetPath, pos, Str.toStringz(name)) != 0; 469 } 470 471 /** 472 * Returns %TRUE if the widget at position @pos has the name @name, 473 * %FALSE otherwise. 474 * 475 * Params: 476 * pos = position to query, -1 for the path head 477 * name = a widget name 478 * 479 * Returns: %TRUE if the widget at @pos has this name 480 * 481 * Since: 3.0 482 */ 483 public bool iterHasName(int pos, string name) 484 { 485 return gtk_widget_path_iter_has_name(gtkWidgetPath, pos, Str.toStringz(name)) != 0; 486 } 487 488 /** 489 * See gtk_widget_path_iter_has_class(). This is a version that operates 490 * with GQuarks. 491 * 492 * Params: 493 * pos = position to query, -1 for the path head 494 * qname = class name as a #GQuark 495 * 496 * Returns: %TRUE if the widget at @pos has the class defined. 497 * 498 * Since: 3.0 499 */ 500 public bool iterHasQclass(int pos, GQuark qname) 501 { 502 return gtk_widget_path_iter_has_qclass(gtkWidgetPath, pos, qname) != 0; 503 } 504 505 /** 506 * See gtk_widget_path_iter_has_name(). This is a version 507 * that operates on #GQuarks. 508 * 509 * Params: 510 * pos = position to query, -1 for the path head 511 * qname = widget name as a #GQuark 512 * 513 * Returns: %TRUE if the widget at @pos has this name 514 * 515 * Since: 3.0 516 */ 517 public bool iterHasQname(int pos, GQuark qname) 518 { 519 return gtk_widget_path_iter_has_qname(gtkWidgetPath, pos, qname) != 0; 520 } 521 522 /** 523 * See gtk_widget_path_iter_has_region(). This is a version that operates 524 * with GQuarks. 525 * 526 * Deprecated: The use of regions is deprecated. 527 * 528 * Params: 529 * pos = position to query, -1 for the path head 530 * qname = region name as a #GQuark 531 * flags = return location for the region flags 532 * 533 * Returns: %TRUE if the widget at @pos has the region defined. 534 * 535 * Since: 3.0 536 */ 537 public bool iterHasQregion(int pos, GQuark qname, out GtkRegionFlags flags) 538 { 539 return gtk_widget_path_iter_has_qregion(gtkWidgetPath, pos, qname, &flags) != 0; 540 } 541 542 /** 543 * Returns %TRUE if the widget at position @pos has the class @name 544 * defined, %FALSE otherwise. 545 * 546 * Deprecated: The use of regions is deprecated. 547 * 548 * Params: 549 * pos = position to query, -1 for the path head 550 * name = region name 551 * flags = return location for the region flags 552 * 553 * Returns: %TRUE if the class @name is defined for the widget at @pos 554 * 555 * Since: 3.0 556 */ 557 public bool iterHasRegion(int pos, string name, out GtkRegionFlags flags) 558 { 559 return gtk_widget_path_iter_has_region(gtkWidgetPath, pos, Str.toStringz(name), &flags) != 0; 560 } 561 562 /** 563 * Returns a list with all the class names defined for the widget 564 * at position @pos in the hierarchy defined in @path. 565 * 566 * Params: 567 * pos = position to query, -1 for the path head 568 * 569 * Returns: The list of 570 * classes, This is a list of strings, the #GSList contents 571 * are owned by GTK+, but you should use g_slist_free() to 572 * free the list itself. 573 * 574 * Since: 3.0 575 */ 576 public ListSG iterListClasses(int pos) 577 { 578 auto p = gtk_widget_path_iter_list_classes(gtkWidgetPath, pos); 579 580 if(p is null) 581 { 582 return null; 583 } 584 585 return new ListSG(cast(GSList*) p); 586 } 587 588 /** 589 * Returns a list with all the region names defined for the widget 590 * at position @pos in the hierarchy defined in @path. 591 * 592 * Deprecated: The use of regions is deprecated. 593 * 594 * Params: 595 * pos = position to query, -1 for the path head 596 * 597 * Returns: The list of 598 * regions, This is a list of strings, the #GSList contents 599 * are owned by GTK+, but you should use g_slist_free() to 600 * free the list itself. 601 * 602 * Since: 3.0 603 */ 604 public ListSG iterListRegions(int pos) 605 { 606 auto p = gtk_widget_path_iter_list_regions(gtkWidgetPath, pos); 607 608 if(p is null) 609 { 610 return null; 611 } 612 613 return new ListSG(cast(GSList*) p); 614 } 615 616 /** 617 * Removes the class @name from the widget at position @pos in 618 * the hierarchy defined in @path. 619 * 620 * Params: 621 * pos = position to modify, -1 for the path head 622 * name = class name 623 * 624 * Since: 3.0 625 */ 626 public void iterRemoveClass(int pos, string name) 627 { 628 gtk_widget_path_iter_remove_class(gtkWidgetPath, pos, Str.toStringz(name)); 629 } 630 631 /** 632 * Removes the region @name from the widget at position @pos in 633 * the hierarchy defined in @path. 634 * 635 * Deprecated: The use of regions is deprecated. 636 * 637 * Params: 638 * pos = position to modify, -1 for the path head 639 * name = region name 640 * 641 * Since: 3.0 642 */ 643 public void iterRemoveRegion(int pos, string name) 644 { 645 gtk_widget_path_iter_remove_region(gtkWidgetPath, pos, Str.toStringz(name)); 646 } 647 648 /** 649 * Sets the widget name for the widget found at position @pos 650 * in the widget hierarchy defined by @path. 651 * 652 * Params: 653 * pos = position to modify, -1 for the path head 654 * name = widget name 655 * 656 * Since: 3.0 657 */ 658 public void iterSetName(int pos, string name) 659 { 660 gtk_widget_path_iter_set_name(gtkWidgetPath, pos, Str.toStringz(name)); 661 } 662 663 /** 664 * Sets the object name for a given position in the widget hierarchy 665 * defined by @path. 666 * 667 * When set, the object name overrides the object type when matching 668 * CSS. 669 * 670 * Params: 671 * pos = position to modify, -1 for the path head 672 * name = object name to set or %NULL to unset 673 * 674 * Since: 3.20 675 */ 676 public void iterSetObjectName(int pos, string name) 677 { 678 gtk_widget_path_iter_set_object_name(gtkWidgetPath, pos, Str.toStringz(name)); 679 } 680 681 /** 682 * Sets the object type for a given position in the widget hierarchy 683 * defined by @path. 684 * 685 * Params: 686 * pos = position to modify, -1 for the path head 687 * type = object type to set 688 * 689 * Since: 3.0 690 */ 691 public void iterSetObjectType(int pos, GType type) 692 { 693 gtk_widget_path_iter_set_object_type(gtkWidgetPath, pos, type); 694 } 695 696 /** 697 * Sets the widget name for the widget found at position @pos 698 * in the widget hierarchy defined by @path. 699 * 700 * If you want to update just a single state flag, you need to do 701 * this manually, as this function updates all state flags. 702 * 703 * ## Setting a flag 704 * 705 * |[<!-- language="C" --> 706 * gtk_widget_path_iter_set_state (path, pos, gtk_widget_path_iter_get_state (path, pos) | flag); 707 * ]| 708 * 709 * ## Unsetting a flag 710 * 711 * |[<!-- language="C" --> 712 * gtk_widget_path_iter_set_state (path, pos, gtk_widget_path_iter_get_state (path, pos) & ~flag); 713 * ]| 714 * 715 * Params: 716 * pos = position to modify, -1 for the path head 717 * state = state flags 718 * 719 * Since: 3.14 720 */ 721 public void iterSetState(int pos, GtkStateFlags state) 722 { 723 gtk_widget_path_iter_set_state(gtkWidgetPath, pos, state); 724 } 725 726 /** 727 * Returns the number of #GtkWidget #GTypes between the represented 728 * widget and its topmost container. 729 * 730 * Returns: the number of elements in the path 731 * 732 * Since: 3.0 733 */ 734 public int length() 735 { 736 return gtk_widget_path_length(gtkWidgetPath); 737 } 738 739 /** 740 * Prepends a widget type to the widget hierachy represented by @path. 741 * 742 * Params: 743 * type = widget type to prepend 744 * 745 * Since: 3.0 746 */ 747 public void prependType(GType type) 748 { 749 gtk_widget_path_prepend_type(gtkWidgetPath, type); 750 } 751 752 /** 753 * Increments the reference count on @path. 754 * 755 * Returns: @path itself. 756 * 757 * Since: 3.2 758 */ 759 public WidgetPath doref() 760 { 761 auto p = gtk_widget_path_ref(gtkWidgetPath); 762 763 if(p is null) 764 { 765 return null; 766 } 767 768 return ObjectG.getDObject!(WidgetPath)(cast(GtkWidgetPath*) p, true); 769 } 770 771 /** 772 * Dumps the widget path into a string representation. It tries to match 773 * the CSS style as closely as possible (Note that there might be paths 774 * that cannot be represented in CSS). 775 * 776 * The main use of this code is for debugging purposes, so that you can 777 * g_print() the path or dump it in a gdb session. 778 * 779 * Returns: A new string describing @path. 780 * 781 * Since: 3.2 782 */ 783 public override string toString() 784 { 785 auto retStr = gtk_widget_path_to_string(gtkWidgetPath); 786 787 scope(exit) Str.freeString(retStr); 788 return Str.toString(retStr); 789 } 790 791 /** 792 * Decrements the reference count on @path, freeing the structure 793 * if the reference count reaches 0. 794 * 795 * Since: 3.2 796 */ 797 public void unref() 798 { 799 gtk_widget_path_unref(gtkWidgetPath); 800 } 801 }