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