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