1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include "gtkwidget.h"
25 #include "gtkwidgetpath.h"
26 #include "gtkstylecontextprivate.h"
29 * SECTION:gtkwidgetpath
30 * @Short_description: Widget path abstraction
31 * @Title: GtkWidgetPath
32 * @See_also: #GtkStyleContext
34 * GtkWidgetPath is a boxed type that represents a widget hierarchy from
35 * the topmost widget, typically a toplevel, to any child. This widget
36 * path abstraction is used in #GtkStyleContext on behalf of the real
37 * widget in order to query style information.
39 * If you are using GTK+ widgets, you probably will not need to use
40 * this API directly, as there is gtk_widget_get_path(), and the style
41 * context returned by gtk_widget_get_style_context() will be automatically
42 * updated on widget hierarchy changes.
44 * The widget path generation is generally simple:
46 * <title>Defining a button within a window</title>
49 * GtkWidgetPath *path;
51 * path = gtk_widget_path_new ();
52 * gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
53 * gtk_widget_path_append_type (path, GTK_TYPE_BUTTON);
58 * Although more complex information, such as widget names, or
59 * different classes (property that may be used by other widget
60 * types) and intermediate regions may be included:
63 * <title>Defining the first tab widget in a notebook</title>
66 * GtkWidgetPath *path;
69 * path = gtk_widget_path_new ();
71 * pos = gtk_widget_path_append_type (path, GTK_TYPE_NOTEBOOK);
72 * gtk_widget_path_iter_add_region (path, pos, "tab", GTK_REGION_EVEN | GTK_REGION_FIRST);
74 * pos = gtk_widget_path_append_type (path, GTK_TYPE_LABEL);
75 * gtk_widget_path_iter_set_name (path, pos, "first tab label");
80 * All this information will be used to match the style information
81 * that applies to the described widget.
84 G_DEFINE_BOXED_TYPE (GtkWidgetPath, gtk_widget_path,
85 gtk_widget_path_ref, gtk_widget_path_unref)
88 typedef struct GtkPathElement GtkPathElement;
96 GtkWidgetPath *siblings;
100 struct _GtkWidgetPath
102 volatile guint ref_count;
104 GArray *elems; /* First element contains the described widget */
108 * gtk_widget_path_new:
110 * Returns an empty widget path.
112 * Returns: (transfer full): A newly created, empty, #GtkWidgetPath
117 gtk_widget_path_new (void)
121 path = g_slice_new0 (GtkWidgetPath);
122 path->elems = g_array_new (FALSE, TRUE, sizeof (GtkPathElement));
129 gtk_path_element_copy (GtkPathElement *dest,
130 const GtkPathElement *src)
132 memset (dest, 0, sizeof (GtkPathElement));
134 dest->type = src->type;
135 dest->name = src->name;
137 dest->siblings = gtk_widget_path_ref (src->siblings);
138 dest->sibling_index = src->sibling_index;
145 g_hash_table_iter_init (&iter, src->regions);
146 dest->regions = g_hash_table_new (NULL, NULL);
148 while (g_hash_table_iter_next (&iter, &key, &value))
149 g_hash_table_insert (dest->regions, key, value);
154 dest->classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
155 g_array_append_vals (dest->classes, src->classes->data, src->classes->len);
160 * gtk_widget_path_copy:
161 * @path: a #GtkWidgetPath
163 * Returns a copy of @path
165 * Returns: (transfer full): a copy of @path
170 gtk_widget_path_copy (const GtkWidgetPath *path)
172 GtkWidgetPath *new_path;
175 g_return_val_if_fail (path != NULL, NULL);
177 new_path = gtk_widget_path_new ();
179 for (i = 0; i < path->elems->len; i++)
181 GtkPathElement *elem, new;
183 elem = &g_array_index (path->elems, GtkPathElement, i);
185 gtk_path_element_copy (&new, elem);
187 g_array_append_val (new_path->elems, new);
194 * gtk_widget_path_ref:
195 * @path: a #GtkWidgetPath
197 * Increments the reference count on @path.
199 * Returns: @path itself.
204 gtk_widget_path_ref (GtkWidgetPath *path)
206 g_return_val_if_fail (path != NULL, path);
208 g_atomic_int_add (&path->ref_count, 1);
214 * gtk_widget_path_unref:
215 * @path: a #GtkWidgetPath
217 * Decrements the reference count on @path, freeing the structure
218 * if the reference count reaches 0.
223 gtk_widget_path_unref (GtkWidgetPath *path)
227 g_return_if_fail (path != NULL);
229 if (!g_atomic_int_dec_and_test (&path->ref_count))
232 for (i = 0; i < path->elems->len; i++)
234 GtkPathElement *elem;
236 elem = &g_array_index (path->elems, GtkPathElement, i);
239 g_hash_table_destroy (elem->regions);
242 g_array_free (elem->classes, TRUE);
245 gtk_widget_path_unref (elem->siblings);
248 g_array_free (path->elems, TRUE);
249 g_slice_free (GtkWidgetPath, path);
253 * gtk_widget_path_free:
254 * @path: a #GtkWidgetPath
256 * Decrements the reference count on @path, freeing the structure
257 * if the reference count reaches 0.
262 gtk_widget_path_free (GtkWidgetPath *path)
264 g_return_if_fail (path != NULL);
266 gtk_widget_path_unref (path);
270 * gtk_widget_path_length:
271 * @path: a #GtkWidgetPath
273 * Returns the number of #GtkWidget #GTypes between the represented
274 * widget and its topmost container.
276 * Returns: the number of elements in the path
281 gtk_widget_path_length (const GtkWidgetPath *path)
283 g_return_val_if_fail (path != NULL, 0);
285 return path->elems->len;
289 * gtk_widget_path_to_string:
292 * Dumps the widget path into a string representation. It tries to match
293 * the CSS style as closely as possible (Note that there might be paths
294 * that cannot be represented in CSS).
296 * The main use of this code is for debugging purposes, so that you can
297 * g_print() the path or dump it in a gdb session.
299 * Returns: A new string describing @path.
304 gtk_widget_path_to_string (const GtkWidgetPath *path)
309 g_return_val_if_fail (path != NULL, NULL);
311 string = g_string_new ("");
313 for (i = 0; i < path->elems->len; i++)
315 GtkPathElement *elem;
317 elem = &g_array_index (path->elems, GtkPathElement, i);
320 g_string_append_c (string, ' ');
322 g_string_append (string, g_type_name (elem->type));
326 g_string_append_c (string, '(');
327 g_string_append (string, g_quark_to_string (elem->name));
328 g_string_append_c (string, ')');
333 for (j = 0; j < elem->classes->len; j++)
335 g_string_append_c (string, '.');
336 g_string_append (string, g_quark_to_string (g_array_index (elem->classes, GQuark, j)));
345 g_hash_table_iter_init (&iter, elem->regions);
346 while (g_hash_table_iter_next (&iter, &key, &value))
348 GtkRegionFlags flags = GPOINTER_TO_UINT (value);
349 static const char *flag_names[] = {
357 g_string_append_c (string, ' ');
358 g_string_append (string, g_quark_to_string (GPOINTER_TO_UINT (key)));
359 for (j = 0; j < G_N_ELEMENTS(flag_names); j++)
361 if (flags & (1 << j))
363 g_string_append_c (string, ':');
364 g_string_append (string, flag_names[j]);
371 return g_string_free (string, FALSE);
375 * gtk_widget_path_prepend_type:
376 * @path: a #GtkWidgetPath
377 * @type: widget type to prepend
379 * Prepends a widget type to the widget hierachy represented by @path.
384 gtk_widget_path_prepend_type (GtkWidgetPath *path,
387 GtkPathElement new = { 0 };
389 g_return_if_fail (path != NULL);
392 g_array_prepend_val (path->elems, new);
396 * gtk_widget_path_append_type:
397 * @path: a #GtkWidgetPath
398 * @type: widget type to append
400 * Appends a widget type to the widget hierarchy represented by @path.
402 * Returns: the position where the element was inserted
407 gtk_widget_path_append_type (GtkWidgetPath *path,
410 GtkPathElement new = { 0 };
412 g_return_val_if_fail (path != NULL, 0);
415 g_array_append_val (path->elems, new);
417 return path->elems->len - 1;
421 * gtk_widget_path_append_with_siblings:
422 * @path: the widget path to append to
423 * @siblings: a widget path describing a list of siblings. This path
424 * may not contain any siblings itself and it must not be modified
426 * @sibling_index: index into @siblings for where the added element is
429 * Appends a widget type with all its siblings to the widget hierarchy
430 * represented by @path. Using this function instead of
431 * gtk_widget_path_append_type() will allow the CSS theming to use
432 * sibling matches in selectors and apply :nth-child() pseudo classes.
433 * In turn, it requires a lot more care in widget implementations as
434 * widgets need to make sure to call gtk_widget_reset_style() on all
435 * involved widgets when the @siblings path changes.
437 * Returns: the position where the element was inserted.
442 gtk_widget_path_append_with_siblings (GtkWidgetPath *path,
443 GtkWidgetPath *siblings,
448 g_return_val_if_fail (path != NULL, 0);
449 g_return_val_if_fail (siblings != NULL, 0);
450 g_return_val_if_fail (sibling_index < gtk_widget_path_length (siblings), 0);
452 gtk_path_element_copy (&new, &g_array_index (siblings->elems, GtkPathElement, sibling_index));
453 new.siblings = gtk_widget_path_ref (siblings);
454 new.sibling_index = sibling_index;
455 g_array_append_val (path->elems, new);
457 return path->elems->len - 1;
461 * gtk_widget_path_iter_get_siblings:
462 * @path: a #GtkWidgetPath
463 * @pos: position to get the siblings for, -1 for the path head
465 * Returns the list of siblings for the element at @pos. If the element
466 * was not added with siblings, %NULL is returned.
468 * Returns: %NULL or the list of siblings for the element at @pos.
470 const GtkWidgetPath *
471 gtk_widget_path_iter_get_siblings (const GtkWidgetPath *path,
474 GtkPathElement *elem;
476 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
477 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
479 if (pos < 0 || pos >= path->elems->len)
480 pos = path->elems->len - 1;
482 elem = &g_array_index (path->elems, GtkPathElement, pos);
483 return elem->siblings;
487 * gtk_widget_path_iter_get_sibling_index:
488 * @path: a #GtkWidgetPath
489 * @pos: position to get the sibling index for, -1 for the path head
491 * Returns the index into the list of siblings for the element at @pos as
492 * returned by gtk_widget_path_iter_get_siblings(). If that function would
493 * return %NULL because the element at @pos has no siblings, this function
496 * Returns: 0 or the index into the list of siblings for the element at @pos.
499 gtk_widget_path_iter_get_sibling_index (const GtkWidgetPath *path,
502 GtkPathElement *elem;
504 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
505 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
507 if (pos < 0 || pos >= path->elems->len)
508 pos = path->elems->len - 1;
510 elem = &g_array_index (path->elems, GtkPathElement, pos);
511 return elem->sibling_index;
515 * gtk_widget_path_iter_get_object_type:
516 * @path: a #GtkWidgetPath
517 * @pos: position to get the object type for, -1 for the path head
519 * Returns the object #GType that is at position @pos in the widget
520 * hierarchy defined in @path.
522 * Returns: a widget type
527 gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path,
530 GtkPathElement *elem;
532 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
533 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
535 if (pos < 0 || pos >= path->elems->len)
536 pos = path->elems->len - 1;
538 elem = &g_array_index (path->elems, GtkPathElement, pos);
543 * gtk_widget_path_iter_set_object_type:
544 * @path: a #GtkWidgetPath
545 * @pos: position to modify, -1 for the path head
546 * @type: object type to set
548 * Sets the object type for a given position in the widget hierarchy
554 gtk_widget_path_iter_set_object_type (GtkWidgetPath *path,
558 GtkPathElement *elem;
560 g_return_if_fail (path != NULL);
561 g_return_if_fail (path->elems->len != 0);
563 if (pos < 0 || pos >= path->elems->len)
564 pos = path->elems->len - 1;
566 elem = &g_array_index (path->elems, GtkPathElement, pos);
571 * gtk_widget_path_iter_get_name:
572 * @path: a #GtkWidgetPath
573 * @pos: position to get the widget name for, -1 for the path head
575 * Returns the name corresponding to the widget found at
576 * the position @pos in the widget hierarchy defined by
579 * Returns: The widget name, or %NULL if none was set.
581 G_CONST_RETURN gchar *
582 gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
585 GtkPathElement *elem;
587 g_return_val_if_fail (path != NULL, NULL);
588 g_return_val_if_fail (path->elems->len != 0, NULL);
590 if (pos < 0 || pos >= path->elems->len)
591 pos = path->elems->len - 1;
593 elem = &g_array_index (path->elems, GtkPathElement, pos);
594 return g_quark_to_string (elem->name);
598 * gtk_widget_path_iter_set_name:
599 * @path: a #GtkWidgetPath
600 * @pos: position to modify, -1 for the path head
603 * Sets the widget name for the widget found at position @pos
604 * in the widget hierarchy defined by @path.
609 gtk_widget_path_iter_set_name (GtkWidgetPath *path,
613 GtkPathElement *elem;
615 g_return_if_fail (path != NULL);
616 g_return_if_fail (path->elems->len != 0);
617 g_return_if_fail (name != NULL);
619 if (pos < 0 || pos >= path->elems->len)
620 pos = path->elems->len - 1;
622 elem = &g_array_index (path->elems, GtkPathElement, pos);
624 elem->name = g_quark_from_string (name);
628 * gtk_widget_path_iter_has_qname:
629 * @path: a #GtkWidgetPath
630 * @pos: position to query, -1 for the path head
631 * @qname: widget name as a #GQuark
633 * See gtk_widget_path_iter_has_name(). This is a version
634 * that operates on #GQuark<!-- -->s.
636 * Returns: %TRUE if the widget at @pos has this name
641 gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
645 GtkPathElement *elem;
647 g_return_val_if_fail (path != NULL, FALSE);
648 g_return_val_if_fail (path->elems->len != 0, FALSE);
649 g_return_val_if_fail (qname != 0, FALSE);
651 if (pos < 0 || pos >= path->elems->len)
652 pos = path->elems->len - 1;
654 elem = &g_array_index (path->elems, GtkPathElement, pos);
656 return (elem->name == qname);
660 * gtk_widget_path_iter_has_name:
661 * @path: a #GtkWidgetPath
662 * @pos: position to query, -1 for the path head
663 * @name: a widget name
665 * Returns %TRUE if the widget at position @pos has the name @name,
668 * Returns: %TRUE if the widget at @pos has this name
673 gtk_widget_path_iter_has_name (const GtkWidgetPath *path,
679 g_return_val_if_fail (path != NULL, FALSE);
680 g_return_val_if_fail (path->elems->len != 0, FALSE);
682 if (pos < 0 || pos >= path->elems->len)
683 pos = path->elems->len - 1;
685 qname = g_quark_try_string (name);
690 return gtk_widget_path_iter_has_qname (path, pos, qname);
694 * gtk_widget_path_iter_add_class:
695 * @path: a #GtkWidget
696 * @pos: position to modify, -1 for the path head
697 * @name: a class name
699 * Adds the class @name to the widget at position @pos in
700 * the hierarchy defined in @path. See
701 * gtk_style_context_add_class().
706 gtk_widget_path_iter_add_class (GtkWidgetPath *path,
710 GtkPathElement *elem;
711 gboolean added = FALSE;
715 g_return_if_fail (path != NULL);
716 g_return_if_fail (path->elems->len != 0);
717 g_return_if_fail (name != NULL);
719 if (pos < 0 || pos >= path->elems->len)
720 pos = path->elems->len - 1;
722 elem = &g_array_index (path->elems, GtkPathElement, pos);
723 qname = g_quark_from_string (name);
726 elem->classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
728 for (i = 0; i < elem->classes->len; i++)
732 quark = g_array_index (elem->classes, GQuark, i);
742 g_array_insert_val (elem->classes, i, qname);
749 g_array_append_val (elem->classes, qname);
753 * gtk_widget_path_iter_remove_class:
754 * @path: a #GtkWidgetPath
755 * @pos: position to modify, -1 for the path head
758 * Removes the class @name from the widget at position @pos in
759 * the hierarchy defined in @path.
764 gtk_widget_path_iter_remove_class (GtkWidgetPath *path,
768 GtkPathElement *elem;
772 g_return_if_fail (path != NULL);
773 g_return_if_fail (path->elems->len != 0);
774 g_return_if_fail (name != NULL);
776 if (pos < 0 || pos >= path->elems->len)
777 pos = path->elems->len - 1;
779 qname = g_quark_try_string (name);
784 elem = &g_array_index (path->elems, GtkPathElement, pos);
789 for (i = 0; i < elem->classes->len; i++)
793 quark = g_array_index (elem->classes, GQuark, i);
797 else if (quark == qname)
799 g_array_remove_index (elem->classes, i);
806 * gtk_widget_path_iter_clear_classes:
807 * @path: a #GtkWidget
808 * @pos: position to modify, -1 for the path head
810 * Removes all classes from the widget at position @pos in the
811 * hierarchy defined in @path.
816 gtk_widget_path_iter_clear_classes (GtkWidgetPath *path,
819 GtkPathElement *elem;
821 g_return_if_fail (path != NULL);
822 g_return_if_fail (path->elems->len != 0);
824 if (pos < 0 || pos >= path->elems->len)
825 pos = path->elems->len - 1;
827 elem = &g_array_index (path->elems, GtkPathElement, pos);
832 if (elem->classes->len > 0)
833 g_array_remove_range (elem->classes, 0, elem->classes->len);
837 * gtk_widget_path_iter_list_classes:
838 * @path: a #GtkWidgetPath
839 * @pos: position to query, -1 for the path head
841 * Returns a list with all the class names defined for the widget
842 * at position @pos in the hierarchy defined in @path.
844 * Returns: (transfer container) (element-type utf8): The list of
845 * classes, This is a list of strings, the #GSList contents
846 * are owned by GTK+, but you should use g_slist_free() to
847 * free the list itself.
852 gtk_widget_path_iter_list_classes (const GtkWidgetPath *path,
855 GtkPathElement *elem;
859 g_return_val_if_fail (path != NULL, NULL);
860 g_return_val_if_fail (path->elems->len != 0, NULL);
862 if (pos < 0 || pos >= path->elems->len)
863 pos = path->elems->len - 1;
865 elem = &g_array_index (path->elems, GtkPathElement, pos);
870 for (i = 0; i < elem->classes->len; i++)
874 quark = g_array_index (elem->classes, GQuark, i);
875 list = g_slist_prepend (list, (gchar *) g_quark_to_string (quark));
878 return g_slist_reverse (list);
882 * gtk_widget_path_iter_has_qclass:
883 * @path: a #GtkWidgetPath
884 * @pos: position to query, -1 for the path head
885 * @qname: class name as a #GQuark
887 * See gtk_widget_path_iter_has_class(). This is a version that operates
888 * with GQuark<!-- -->s.
890 * Returns: %TRUE if the widget at @pos has the class defined.
895 gtk_widget_path_iter_has_qclass (const GtkWidgetPath *path,
899 GtkPathElement *elem;
902 g_return_val_if_fail (path != NULL, FALSE);
903 g_return_val_if_fail (path->elems->len != 0, FALSE);
904 g_return_val_if_fail (qname != 0, FALSE);
906 if (pos < 0 || pos >= path->elems->len)
907 pos = path->elems->len - 1;
909 elem = &g_array_index (path->elems, GtkPathElement, pos);
914 for (i = 0; i < elem->classes->len; i++)
918 quark = g_array_index (elem->classes, GQuark, i);
922 else if (quark > qname)
930 * gtk_widget_path_iter_has_class:
931 * @path: a #GtkWidgetPath
932 * @pos: position to query, -1 for the path head
935 * Returns %TRUE if the widget at position @pos has the class @name
936 * defined, %FALSE otherwise.
938 * Returns: %TRUE if the class @name is defined for the widget at @pos
943 gtk_widget_path_iter_has_class (const GtkWidgetPath *path,
949 g_return_val_if_fail (path != NULL, FALSE);
950 g_return_val_if_fail (path->elems->len != 0, FALSE);
951 g_return_val_if_fail (name != NULL, FALSE);
953 if (pos < 0 || pos >= path->elems->len)
954 pos = path->elems->len - 1;
956 qname = g_quark_try_string (name);
961 return gtk_widget_path_iter_has_qclass (path, pos, qname);
965 * gtk_widget_path_iter_add_region:
966 * @path: a #GtkWidgetPath
967 * @pos: position to modify, -1 for the path head
969 * @flags: flags affecting the region
971 * Adds the region @name to the widget at position @pos in
972 * the hierarchy defined in @path. See
973 * gtk_style_context_add_region().
975 * <note><para>Region names must only contain lowercase letters
976 * and '-', starting always with a lowercase letter.</para></note>
981 gtk_widget_path_iter_add_region (GtkWidgetPath *path,
984 GtkRegionFlags flags)
986 GtkPathElement *elem;
989 g_return_if_fail (path != NULL);
990 g_return_if_fail (path->elems->len != 0);
991 g_return_if_fail (name != NULL);
992 g_return_if_fail (_gtk_style_context_check_region_name (name));
994 if (pos < 0 || pos >= path->elems->len)
995 pos = path->elems->len - 1;
997 elem = &g_array_index (path->elems, GtkPathElement, pos);
998 qname = g_quark_from_string (name);
1001 elem->regions = g_hash_table_new (NULL, NULL);
1003 g_hash_table_insert (elem->regions,
1004 GUINT_TO_POINTER (qname),
1005 GUINT_TO_POINTER (flags));
1009 * gtk_widget_path_iter_remove_region:
1010 * @path: a #GtkWidgetPath
1011 * @pos: position to modify, -1 for the path head
1012 * @name: region name
1014 * Removes the region @name from the widget at position @pos in
1015 * the hierarchy defined in @path.
1020 gtk_widget_path_iter_remove_region (GtkWidgetPath *path,
1024 GtkPathElement *elem;
1027 g_return_if_fail (path != NULL);
1028 g_return_if_fail (path->elems->len != 0);
1029 g_return_if_fail (name != NULL);
1031 if (pos < 0 || pos >= path->elems->len)
1032 pos = path->elems->len - 1;
1034 qname = g_quark_try_string (name);
1039 elem = &g_array_index (path->elems, GtkPathElement, pos);
1042 g_hash_table_remove (elem->regions, GUINT_TO_POINTER (qname));
1046 * gtk_widget_path_iter_clear_regions:
1047 * @path: a #GtkWidgetPath
1048 * @pos: position to modify, -1 for the path head
1050 * Removes all regions from the widget at position @pos in the
1051 * hierarchy defined in @path.
1056 gtk_widget_path_iter_clear_regions (GtkWidgetPath *path,
1059 GtkPathElement *elem;
1061 g_return_if_fail (path != NULL);
1062 g_return_if_fail (path->elems->len != 0);
1064 if (pos < 0 || pos >= path->elems->len)
1065 pos = path->elems->len - 1;
1067 elem = &g_array_index (path->elems, GtkPathElement, pos);
1070 g_hash_table_remove_all (elem->regions);
1074 * gtk_widget_path_iter_list_regions:
1075 * @path: a #GtkWidgetPath
1076 * @pos: position to query, -1 for the path head
1078 * Returns a list with all the region names defined for the widget
1079 * at position @pos in the hierarchy defined in @path.
1081 * Returns: (transfer container) (element-type utf8): The list of
1082 * regions, This is a list of strings, the #GSList contents
1083 * are owned by GTK+, but you should use g_slist_free() to
1084 * free the list itself.
1089 gtk_widget_path_iter_list_regions (const GtkWidgetPath *path,
1092 GtkPathElement *elem;
1093 GHashTableIter iter;
1094 GSList *list = NULL;
1097 g_return_val_if_fail (path != NULL, NULL);
1098 g_return_val_if_fail (path->elems->len != 0, NULL);
1100 if (pos < 0 || pos >= path->elems->len)
1101 pos = path->elems->len - 1;
1103 elem = &g_array_index (path->elems, GtkPathElement, pos);
1108 g_hash_table_iter_init (&iter, elem->regions);
1110 while (g_hash_table_iter_next (&iter, &key, NULL))
1114 qname = GPOINTER_TO_UINT (key);
1115 list = g_slist_prepend (list, (gchar *) g_quark_to_string (qname));
1122 * gtk_widget_path_iter_has_qregion:
1123 * @path: a #GtkWidgetPath
1124 * @pos: position to query, -1 for the path head
1125 * @qname: region name as a #GQuark
1126 * @flags: (out): return location for the region flags
1128 * See gtk_widget_path_iter_has_region(). This is a version that operates
1129 * with GQuark<!-- -->s.
1131 * Returns: %TRUE if the widget at @pos has the region defined.
1136 gtk_widget_path_iter_has_qregion (const GtkWidgetPath *path,
1139 GtkRegionFlags *flags)
1141 GtkPathElement *elem;
1144 g_return_val_if_fail (path != NULL, FALSE);
1145 g_return_val_if_fail (path->elems->len != 0, FALSE);
1146 g_return_val_if_fail (qname != 0, FALSE);
1148 if (pos < 0 || pos >= path->elems->len)
1149 pos = path->elems->len - 1;
1151 elem = &g_array_index (path->elems, GtkPathElement, pos);
1156 if (!g_hash_table_lookup_extended (elem->regions,
1157 GUINT_TO_POINTER (qname),
1162 *flags = GPOINTER_TO_UINT (value);
1168 * gtk_widget_path_iter_has_region:
1169 * @path: a #GtkWidgetPath
1170 * @pos: position to query, -1 for the path head
1171 * @name: region name
1172 * @flags: (out): return location for the region flags
1174 * Returns %TRUE if the widget at position @pos has the class @name
1175 * defined, %FALSE otherwise.
1177 * Returns: %TRUE if the class @name is defined for the widget at @pos
1182 gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
1185 GtkRegionFlags *flags)
1189 g_return_val_if_fail (path != NULL, FALSE);
1190 g_return_val_if_fail (path->elems->len != 0, FALSE);
1191 g_return_val_if_fail (name != NULL, FALSE);
1193 if (pos < 0 || pos >= path->elems->len)
1194 pos = path->elems->len - 1;
1196 qname = g_quark_try_string (name);
1201 return gtk_widget_path_iter_has_qregion (path, pos, qname, flags);
1205 * gtk_widget_path_get_object_type:
1206 * @path: a #GtkWidget
1208 * Returns the topmost object type, that is, the object type this path
1211 * Returns: The object type
1216 gtk_widget_path_get_object_type (const GtkWidgetPath *path)
1218 GtkPathElement *elem;
1220 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
1222 elem = &g_array_index (path->elems, GtkPathElement,
1223 path->elems->len - 1);
1228 * gtk_widget_path_is_type:
1229 * @path: a #GtkWidgetPath
1230 * @type: widget type to match
1232 * Returns %TRUE if the widget type represented by this path
1233 * is @type, or a subtype of it.
1235 * Returns: %TRUE if the widget represented by @path is of type @type
1240 gtk_widget_path_is_type (const GtkWidgetPath *path,
1243 GtkPathElement *elem;
1245 g_return_val_if_fail (path != NULL, FALSE);
1247 elem = &g_array_index (path->elems, GtkPathElement,
1248 path->elems->len - 1);
1250 if (elem->type == type ||
1251 g_type_is_a (elem->type, type))
1258 * gtk_widget_path_has_parent:
1259 * @path: a #GtkWidgetPath
1260 * @type: widget type to check in parents
1262 * Returns %TRUE if any of the parents of the widget represented
1263 * in @path is of type @type, or any subtype of it.
1265 * Returns: %TRUE if any parent is of type @type
1270 gtk_widget_path_has_parent (const GtkWidgetPath *path,
1275 g_return_val_if_fail (path != NULL, FALSE);
1277 for (i = 0; i < path->elems->len - 1; i++)
1279 GtkPathElement *elem;
1281 elem = &g_array_index (path->elems, GtkPathElement, i);
1283 if (elem->type == type ||
1284 g_type_is_a (elem->type, type))