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, see <http://www.gnu.org/licenses/>.
22 #include "gtkwidget.h"
23 #include "gtkwidgetpath.h"
24 #include "gtkstylecontextprivate.h"
27 * SECTION:gtkwidgetpath
28 * @Short_description: Widget path abstraction
29 * @Title: GtkWidgetPath
30 * @See_also: #GtkStyleContext
32 * GtkWidgetPath is a boxed type that represents a widget hierarchy from
33 * the topmost widget, typically a toplevel, to any child. This widget
34 * path abstraction is used in #GtkStyleContext on behalf of the real
35 * widget in order to query style information.
37 * If you are using GTK+ widgets, you probably will not need to use
38 * this API directly, as there is gtk_widget_get_path(), and the style
39 * context returned by gtk_widget_get_style_context() will be automatically
40 * updated on widget hierarchy changes.
42 * The widget path generation is generally simple:
44 * <title>Defining a button within a window</title>
47 * GtkWidgetPath *path;
49 * path = gtk_widget_path_new ();
50 * gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
51 * gtk_widget_path_append_type (path, GTK_TYPE_BUTTON);
56 * Although more complex information, such as widget names, or
57 * different classes (property that may be used by other widget
58 * types) and intermediate regions may be included:
61 * <title>Defining the first tab widget in a notebook</title>
64 * GtkWidgetPath *path;
67 * path = gtk_widget_path_new ();
69 * pos = gtk_widget_path_append_type (path, GTK_TYPE_NOTEBOOK);
70 * gtk_widget_path_iter_add_region (path, pos, "tab", GTK_REGION_EVEN | GTK_REGION_FIRST);
72 * pos = gtk_widget_path_append_type (path, GTK_TYPE_LABEL);
73 * gtk_widget_path_iter_set_name (path, pos, "first tab label");
78 * All this information will be used to match the style information
79 * that applies to the described widget.
82 G_DEFINE_BOXED_TYPE (GtkWidgetPath, gtk_widget_path,
83 gtk_widget_path_ref, gtk_widget_path_unref)
86 typedef struct GtkPathElement GtkPathElement;
94 GtkWidgetPath *siblings;
100 volatile guint ref_count;
102 GArray *elems; /* First element contains the described widget */
106 * gtk_widget_path_new:
108 * Returns an empty widget path.
110 * Returns: (transfer full): A newly created, empty, #GtkWidgetPath
115 gtk_widget_path_new (void)
119 path = g_slice_new0 (GtkWidgetPath);
120 path->elems = g_array_new (FALSE, TRUE, sizeof (GtkPathElement));
127 gtk_path_element_copy (GtkPathElement *dest,
128 const GtkPathElement *src)
130 memset (dest, 0, sizeof (GtkPathElement));
132 dest->type = src->type;
133 dest->name = src->name;
135 dest->siblings = gtk_widget_path_ref (src->siblings);
136 dest->sibling_index = src->sibling_index;
143 g_hash_table_iter_init (&iter, src->regions);
144 dest->regions = g_hash_table_new (NULL, NULL);
146 while (g_hash_table_iter_next (&iter, &key, &value))
147 g_hash_table_insert (dest->regions, key, value);
152 dest->classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
153 g_array_append_vals (dest->classes, src->classes->data, src->classes->len);
158 * gtk_widget_path_copy:
159 * @path: a #GtkWidgetPath
161 * Returns a copy of @path
163 * Returns: (transfer full): a copy of @path
168 gtk_widget_path_copy (const GtkWidgetPath *path)
170 GtkWidgetPath *new_path;
173 g_return_val_if_fail (path != NULL, NULL);
175 new_path = gtk_widget_path_new ();
177 for (i = 0; i < path->elems->len; i++)
179 GtkPathElement *elem, new;
181 elem = &g_array_index (path->elems, GtkPathElement, i);
183 gtk_path_element_copy (&new, elem);
185 g_array_append_val (new_path->elems, new);
192 * gtk_widget_path_ref:
193 * @path: a #GtkWidgetPath
195 * Increments the reference count on @path.
197 * Returns: @path itself.
202 gtk_widget_path_ref (GtkWidgetPath *path)
204 g_return_val_if_fail (path != NULL, path);
206 g_atomic_int_add (&path->ref_count, 1);
212 * gtk_widget_path_unref:
213 * @path: a #GtkWidgetPath
215 * Decrements the reference count on @path, freeing the structure
216 * if the reference count reaches 0.
221 gtk_widget_path_unref (GtkWidgetPath *path)
225 g_return_if_fail (path != NULL);
227 if (!g_atomic_int_dec_and_test (&path->ref_count))
230 for (i = 0; i < path->elems->len; i++)
232 GtkPathElement *elem;
234 elem = &g_array_index (path->elems, GtkPathElement, i);
237 g_hash_table_destroy (elem->regions);
240 g_array_free (elem->classes, TRUE);
243 gtk_widget_path_unref (elem->siblings);
246 g_array_free (path->elems, TRUE);
247 g_slice_free (GtkWidgetPath, path);
251 * gtk_widget_path_free:
252 * @path: a #GtkWidgetPath
254 * Decrements the reference count on @path, freeing the structure
255 * if the reference count reaches 0.
260 gtk_widget_path_free (GtkWidgetPath *path)
262 g_return_if_fail (path != NULL);
264 gtk_widget_path_unref (path);
268 * gtk_widget_path_length:
269 * @path: a #GtkWidgetPath
271 * Returns the number of #GtkWidget #GTypes between the represented
272 * widget and its topmost container.
274 * Returns: the number of elements in the path
279 gtk_widget_path_length (const GtkWidgetPath *path)
281 g_return_val_if_fail (path != NULL, 0);
283 return path->elems->len;
287 * gtk_widget_path_to_string:
290 * Dumps the widget path into a string representation. It tries to match
291 * the CSS style as closely as possible (Note that there might be paths
292 * that cannot be represented in CSS).
294 * The main use of this code is for debugging purposes, so that you can
295 * g_print() the path or dump it in a gdb session.
297 * Returns: A new string describing @path.
302 gtk_widget_path_to_string (const GtkWidgetPath *path)
307 g_return_val_if_fail (path != NULL, NULL);
309 string = g_string_new ("");
311 for (i = 0; i < path->elems->len; i++)
313 GtkPathElement *elem;
315 elem = &g_array_index (path->elems, GtkPathElement, i);
318 g_string_append_c (string, ' ');
320 g_string_append (string, g_type_name (elem->type));
324 g_string_append_c (string, '(');
325 g_string_append (string, g_quark_to_string (elem->name));
326 g_string_append_c (string, ')');
331 g_string_append_printf (string, "[%d/%d]",
332 elem->sibling_index + 1,
333 gtk_widget_path_length (elem->siblings));
337 for (j = 0; j < elem->classes->len; j++)
339 g_string_append_c (string, '.');
340 g_string_append (string, g_quark_to_string (g_array_index (elem->classes, GQuark, j)));
349 g_hash_table_iter_init (&iter, elem->regions);
350 while (g_hash_table_iter_next (&iter, &key, &value))
352 GtkRegionFlags flags = GPOINTER_TO_UINT (value);
353 static const char *flag_names[] = {
362 g_string_append_c (string, ' ');
363 g_string_append (string, g_quark_to_string (GPOINTER_TO_UINT (key)));
364 for (j = 0; j < G_N_ELEMENTS(flag_names); j++)
366 if (flags & (1 << j))
368 g_string_append_c (string, ':');
369 g_string_append (string, flag_names[j]);
376 return g_string_free (string, FALSE);
380 * gtk_widget_path_prepend_type:
381 * @path: a #GtkWidgetPath
382 * @type: widget type to prepend
384 * Prepends a widget type to the widget hierachy represented by @path.
389 gtk_widget_path_prepend_type (GtkWidgetPath *path,
392 GtkPathElement new = { 0 };
394 g_return_if_fail (path != NULL);
397 g_array_prepend_val (path->elems, new);
401 * gtk_widget_path_append_type:
402 * @path: a #GtkWidgetPath
403 * @type: widget type to append
405 * Appends a widget type to the widget hierarchy represented by @path.
407 * Returns: the position where the element was inserted
412 gtk_widget_path_append_type (GtkWidgetPath *path,
415 GtkPathElement new = { 0 };
417 g_return_val_if_fail (path != NULL, 0);
420 g_array_append_val (path->elems, new);
422 return path->elems->len - 1;
426 * gtk_widget_path_append_with_siblings:
427 * @path: the widget path to append to
428 * @siblings: a widget path describing a list of siblings. This path
429 * may not contain any siblings itself and it must not be modified
431 * @sibling_index: index into @siblings for where the added element is
434 * Appends a widget type with all its siblings to the widget hierarchy
435 * represented by @path. Using this function instead of
436 * gtk_widget_path_append_type() will allow the CSS theming to use
437 * sibling matches in selectors and apply :nth-child() pseudo classes.
438 * In turn, it requires a lot more care in widget implementations as
439 * widgets need to make sure to call gtk_widget_reset_style() on all
440 * involved widgets when the @siblings path changes.
442 * Returns: the position where the element was inserted.
447 gtk_widget_path_append_with_siblings (GtkWidgetPath *path,
448 GtkWidgetPath *siblings,
453 g_return_val_if_fail (path != NULL, 0);
454 g_return_val_if_fail (siblings != NULL, 0);
455 g_return_val_if_fail (sibling_index < gtk_widget_path_length (siblings), 0);
457 gtk_path_element_copy (&new, &g_array_index (siblings->elems, GtkPathElement, sibling_index));
458 new.siblings = gtk_widget_path_ref (siblings);
459 new.sibling_index = sibling_index;
460 g_array_append_val (path->elems, new);
462 return path->elems->len - 1;
466 * gtk_widget_path_iter_get_siblings:
467 * @path: a #GtkWidgetPath
468 * @pos: position to get the siblings for, -1 for the path head
470 * Returns the list of siblings for the element at @pos. If the element
471 * was not added with siblings, %NULL is returned.
473 * Returns: %NULL or the list of siblings for the element at @pos.
475 const GtkWidgetPath *
476 gtk_widget_path_iter_get_siblings (const GtkWidgetPath *path,
479 GtkPathElement *elem;
481 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
482 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
484 if (pos < 0 || pos >= path->elems->len)
485 pos = path->elems->len - 1;
487 elem = &g_array_index (path->elems, GtkPathElement, pos);
488 return elem->siblings;
492 * gtk_widget_path_iter_get_sibling_index:
493 * @path: a #GtkWidgetPath
494 * @pos: position to get the sibling index for, -1 for the path head
496 * Returns the index into the list of siblings for the element at @pos as
497 * returned by gtk_widget_path_iter_get_siblings(). If that function would
498 * return %NULL because the element at @pos has no siblings, this function
501 * Returns: 0 or the index into the list of siblings for the element at @pos.
504 gtk_widget_path_iter_get_sibling_index (const GtkWidgetPath *path,
507 GtkPathElement *elem;
509 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
510 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
512 if (pos < 0 || pos >= path->elems->len)
513 pos = path->elems->len - 1;
515 elem = &g_array_index (path->elems, GtkPathElement, pos);
516 return elem->sibling_index;
520 * gtk_widget_path_iter_get_object_type:
521 * @path: a #GtkWidgetPath
522 * @pos: position to get the object type for, -1 for the path head
524 * Returns the object #GType that is at position @pos in the widget
525 * hierarchy defined in @path.
527 * Returns: a widget type
532 gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path,
535 GtkPathElement *elem;
537 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
538 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
540 if (pos < 0 || pos >= path->elems->len)
541 pos = path->elems->len - 1;
543 elem = &g_array_index (path->elems, GtkPathElement, pos);
548 * gtk_widget_path_iter_set_object_type:
549 * @path: a #GtkWidgetPath
550 * @pos: position to modify, -1 for the path head
551 * @type: object type to set
553 * Sets the object type for a given position in the widget hierarchy
559 gtk_widget_path_iter_set_object_type (GtkWidgetPath *path,
563 GtkPathElement *elem;
565 g_return_if_fail (path != NULL);
566 g_return_if_fail (path->elems->len != 0);
568 if (pos < 0 || pos >= path->elems->len)
569 pos = path->elems->len - 1;
571 elem = &g_array_index (path->elems, GtkPathElement, pos);
576 * gtk_widget_path_iter_get_name:
577 * @path: a #GtkWidgetPath
578 * @pos: position to get the widget name for, -1 for the path head
580 * Returns the name corresponding to the widget found at
581 * the position @pos in the widget hierarchy defined by
584 * Returns: The widget name, or %NULL if none was set.
587 gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
590 GtkPathElement *elem;
592 g_return_val_if_fail (path != NULL, NULL);
593 g_return_val_if_fail (path->elems->len != 0, NULL);
595 if (pos < 0 || pos >= path->elems->len)
596 pos = path->elems->len - 1;
598 elem = &g_array_index (path->elems, GtkPathElement, pos);
599 return g_quark_to_string (elem->name);
603 * gtk_widget_path_iter_set_name:
604 * @path: a #GtkWidgetPath
605 * @pos: position to modify, -1 for the path head
608 * Sets the widget name for the widget found at position @pos
609 * in the widget hierarchy defined by @path.
614 gtk_widget_path_iter_set_name (GtkWidgetPath *path,
618 GtkPathElement *elem;
620 g_return_if_fail (path != NULL);
621 g_return_if_fail (path->elems->len != 0);
622 g_return_if_fail (name != NULL);
624 if (pos < 0 || pos >= path->elems->len)
625 pos = path->elems->len - 1;
627 elem = &g_array_index (path->elems, GtkPathElement, pos);
629 elem->name = g_quark_from_string (name);
633 * gtk_widget_path_iter_has_qname:
634 * @path: a #GtkWidgetPath
635 * @pos: position to query, -1 for the path head
636 * @qname: widget name as a #GQuark
638 * See gtk_widget_path_iter_has_name(). This is a version
639 * that operates on #GQuark<!-- -->s.
641 * Returns: %TRUE if the widget at @pos has this name
646 gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
650 GtkPathElement *elem;
652 g_return_val_if_fail (path != NULL, FALSE);
653 g_return_val_if_fail (path->elems->len != 0, FALSE);
654 g_return_val_if_fail (qname != 0, FALSE);
656 if (pos < 0 || pos >= path->elems->len)
657 pos = path->elems->len - 1;
659 elem = &g_array_index (path->elems, GtkPathElement, pos);
661 return (elem->name == qname);
665 * gtk_widget_path_iter_has_name:
666 * @path: a #GtkWidgetPath
667 * @pos: position to query, -1 for the path head
668 * @name: a widget name
670 * Returns %TRUE if the widget at position @pos has the name @name,
673 * Returns: %TRUE if the widget at @pos has this name
678 gtk_widget_path_iter_has_name (const GtkWidgetPath *path,
684 g_return_val_if_fail (path != NULL, FALSE);
685 g_return_val_if_fail (path->elems->len != 0, FALSE);
687 if (pos < 0 || pos >= path->elems->len)
688 pos = path->elems->len - 1;
690 qname = g_quark_try_string (name);
695 return gtk_widget_path_iter_has_qname (path, pos, qname);
699 * gtk_widget_path_iter_add_class:
700 * @path: a #GtkWidget
701 * @pos: position to modify, -1 for the path head
702 * @name: a class name
704 * Adds the class @name to the widget at position @pos in
705 * the hierarchy defined in @path. See
706 * gtk_style_context_add_class().
711 gtk_widget_path_iter_add_class (GtkWidgetPath *path,
715 GtkPathElement *elem;
716 gboolean added = FALSE;
720 g_return_if_fail (path != NULL);
721 g_return_if_fail (path->elems->len != 0);
722 g_return_if_fail (name != NULL);
724 if (pos < 0 || pos >= path->elems->len)
725 pos = path->elems->len - 1;
727 elem = &g_array_index (path->elems, GtkPathElement, pos);
728 qname = g_quark_from_string (name);
731 elem->classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
733 for (i = 0; i < elem->classes->len; i++)
737 quark = g_array_index (elem->classes, GQuark, i);
747 g_array_insert_val (elem->classes, i, qname);
754 g_array_append_val (elem->classes, qname);
758 * gtk_widget_path_iter_remove_class:
759 * @path: a #GtkWidgetPath
760 * @pos: position to modify, -1 for the path head
763 * Removes the class @name from the widget at position @pos in
764 * the hierarchy defined in @path.
769 gtk_widget_path_iter_remove_class (GtkWidgetPath *path,
773 GtkPathElement *elem;
777 g_return_if_fail (path != NULL);
778 g_return_if_fail (path->elems->len != 0);
779 g_return_if_fail (name != NULL);
781 if (pos < 0 || pos >= path->elems->len)
782 pos = path->elems->len - 1;
784 qname = g_quark_try_string (name);
789 elem = &g_array_index (path->elems, GtkPathElement, pos);
794 for (i = 0; i < elem->classes->len; i++)
798 quark = g_array_index (elem->classes, GQuark, i);
802 else if (quark == qname)
804 g_array_remove_index (elem->classes, i);
811 * gtk_widget_path_iter_clear_classes:
812 * @path: a #GtkWidget
813 * @pos: position to modify, -1 for the path head
815 * Removes all classes from the widget at position @pos in the
816 * hierarchy defined in @path.
821 gtk_widget_path_iter_clear_classes (GtkWidgetPath *path,
824 GtkPathElement *elem;
826 g_return_if_fail (path != NULL);
827 g_return_if_fail (path->elems->len != 0);
829 if (pos < 0 || pos >= path->elems->len)
830 pos = path->elems->len - 1;
832 elem = &g_array_index (path->elems, GtkPathElement, pos);
837 if (elem->classes->len > 0)
838 g_array_remove_range (elem->classes, 0, elem->classes->len);
842 * gtk_widget_path_iter_list_classes:
843 * @path: a #GtkWidgetPath
844 * @pos: position to query, -1 for the path head
846 * Returns a list with all the class names defined for the widget
847 * at position @pos in the hierarchy defined in @path.
849 * Returns: (transfer container) (element-type utf8): The list of
850 * classes, This is a list of strings, the #GSList contents
851 * are owned by GTK+, but you should use g_slist_free() to
852 * free the list itself.
857 gtk_widget_path_iter_list_classes (const GtkWidgetPath *path,
860 GtkPathElement *elem;
864 g_return_val_if_fail (path != NULL, NULL);
865 g_return_val_if_fail (path->elems->len != 0, NULL);
867 if (pos < 0 || pos >= path->elems->len)
868 pos = path->elems->len - 1;
870 elem = &g_array_index (path->elems, GtkPathElement, pos);
875 for (i = 0; i < elem->classes->len; i++)
879 quark = g_array_index (elem->classes, GQuark, i);
880 list = g_slist_prepend (list, (gchar *) g_quark_to_string (quark));
883 return g_slist_reverse (list);
887 * gtk_widget_path_iter_has_qclass:
888 * @path: a #GtkWidgetPath
889 * @pos: position to query, -1 for the path head
890 * @qname: class name as a #GQuark
892 * See gtk_widget_path_iter_has_class(). This is a version that operates
893 * with GQuark<!-- -->s.
895 * Returns: %TRUE if the widget at @pos has the class defined.
900 gtk_widget_path_iter_has_qclass (const GtkWidgetPath *path,
904 GtkPathElement *elem;
907 g_return_val_if_fail (path != NULL, FALSE);
908 g_return_val_if_fail (path->elems->len != 0, FALSE);
909 g_return_val_if_fail (qname != 0, FALSE);
911 if (pos < 0 || pos >= path->elems->len)
912 pos = path->elems->len - 1;
914 elem = &g_array_index (path->elems, GtkPathElement, pos);
919 for (i = 0; i < elem->classes->len; i++)
923 quark = g_array_index (elem->classes, GQuark, i);
927 else if (quark > qname)
935 * gtk_widget_path_iter_has_class:
936 * @path: a #GtkWidgetPath
937 * @pos: position to query, -1 for the path head
940 * Returns %TRUE if the widget at position @pos has the class @name
941 * defined, %FALSE otherwise.
943 * Returns: %TRUE if the class @name is defined for the widget at @pos
948 gtk_widget_path_iter_has_class (const GtkWidgetPath *path,
954 g_return_val_if_fail (path != NULL, FALSE);
955 g_return_val_if_fail (path->elems->len != 0, FALSE);
956 g_return_val_if_fail (name != NULL, FALSE);
958 if (pos < 0 || pos >= path->elems->len)
959 pos = path->elems->len - 1;
961 qname = g_quark_try_string (name);
966 return gtk_widget_path_iter_has_qclass (path, pos, qname);
970 * gtk_widget_path_iter_add_region:
971 * @path: a #GtkWidgetPath
972 * @pos: position to modify, -1 for the path head
974 * @flags: flags affecting the region
976 * Adds the region @name to the widget at position @pos in
977 * the hierarchy defined in @path. See
978 * gtk_style_context_add_region().
980 * <note><para>Region names must only contain lowercase letters
981 * and '-', starting always with a lowercase letter.</para></note>
986 gtk_widget_path_iter_add_region (GtkWidgetPath *path,
989 GtkRegionFlags flags)
991 GtkPathElement *elem;
994 g_return_if_fail (path != NULL);
995 g_return_if_fail (path->elems->len != 0);
996 g_return_if_fail (name != NULL);
997 g_return_if_fail (_gtk_style_context_check_region_name (name));
999 if (pos < 0 || pos >= path->elems->len)
1000 pos = path->elems->len - 1;
1002 elem = &g_array_index (path->elems, GtkPathElement, pos);
1003 qname = g_quark_from_string (name);
1006 elem->regions = g_hash_table_new (NULL, NULL);
1008 g_hash_table_insert (elem->regions,
1009 GUINT_TO_POINTER (qname),
1010 GUINT_TO_POINTER (flags));
1014 * gtk_widget_path_iter_remove_region:
1015 * @path: a #GtkWidgetPath
1016 * @pos: position to modify, -1 for the path head
1017 * @name: region name
1019 * Removes the region @name from the widget at position @pos in
1020 * the hierarchy defined in @path.
1025 gtk_widget_path_iter_remove_region (GtkWidgetPath *path,
1029 GtkPathElement *elem;
1032 g_return_if_fail (path != NULL);
1033 g_return_if_fail (path->elems->len != 0);
1034 g_return_if_fail (name != NULL);
1036 if (pos < 0 || pos >= path->elems->len)
1037 pos = path->elems->len - 1;
1039 qname = g_quark_try_string (name);
1044 elem = &g_array_index (path->elems, GtkPathElement, pos);
1047 g_hash_table_remove (elem->regions, GUINT_TO_POINTER (qname));
1051 * gtk_widget_path_iter_clear_regions:
1052 * @path: a #GtkWidgetPath
1053 * @pos: position to modify, -1 for the path head
1055 * Removes all regions from the widget at position @pos in the
1056 * hierarchy defined in @path.
1061 gtk_widget_path_iter_clear_regions (GtkWidgetPath *path,
1064 GtkPathElement *elem;
1066 g_return_if_fail (path != NULL);
1067 g_return_if_fail (path->elems->len != 0);
1069 if (pos < 0 || pos >= path->elems->len)
1070 pos = path->elems->len - 1;
1072 elem = &g_array_index (path->elems, GtkPathElement, pos);
1075 g_hash_table_remove_all (elem->regions);
1079 * gtk_widget_path_iter_list_regions:
1080 * @path: a #GtkWidgetPath
1081 * @pos: position to query, -1 for the path head
1083 * Returns a list with all the region names defined for the widget
1084 * at position @pos in the hierarchy defined in @path.
1086 * Returns: (transfer container) (element-type utf8): The list of
1087 * regions, This is a list of strings, the #GSList contents
1088 * are owned by GTK+, but you should use g_slist_free() to
1089 * free the list itself.
1094 gtk_widget_path_iter_list_regions (const GtkWidgetPath *path,
1097 GtkPathElement *elem;
1098 GHashTableIter iter;
1099 GSList *list = NULL;
1102 g_return_val_if_fail (path != NULL, NULL);
1103 g_return_val_if_fail (path->elems->len != 0, NULL);
1105 if (pos < 0 || pos >= path->elems->len)
1106 pos = path->elems->len - 1;
1108 elem = &g_array_index (path->elems, GtkPathElement, pos);
1113 g_hash_table_iter_init (&iter, elem->regions);
1115 while (g_hash_table_iter_next (&iter, &key, NULL))
1119 qname = GPOINTER_TO_UINT (key);
1120 list = g_slist_prepend (list, (gchar *) g_quark_to_string (qname));
1127 * gtk_widget_path_iter_has_qregion:
1128 * @path: a #GtkWidgetPath
1129 * @pos: position to query, -1 for the path head
1130 * @qname: region name as a #GQuark
1131 * @flags: (out): return location for the region flags
1133 * See gtk_widget_path_iter_has_region(). This is a version that operates
1134 * with GQuark<!-- -->s.
1136 * Returns: %TRUE if the widget at @pos has the region defined.
1141 gtk_widget_path_iter_has_qregion (const GtkWidgetPath *path,
1144 GtkRegionFlags *flags)
1146 GtkPathElement *elem;
1149 g_return_val_if_fail (path != NULL, FALSE);
1150 g_return_val_if_fail (path->elems->len != 0, FALSE);
1151 g_return_val_if_fail (qname != 0, FALSE);
1153 if (pos < 0 || pos >= path->elems->len)
1154 pos = path->elems->len - 1;
1156 elem = &g_array_index (path->elems, GtkPathElement, pos);
1161 if (!g_hash_table_lookup_extended (elem->regions,
1162 GUINT_TO_POINTER (qname),
1167 *flags = GPOINTER_TO_UINT (value);
1173 * gtk_widget_path_iter_has_region:
1174 * @path: a #GtkWidgetPath
1175 * @pos: position to query, -1 for the path head
1176 * @name: region name
1177 * @flags: (out): return location for the region flags
1179 * Returns %TRUE if the widget at position @pos has the class @name
1180 * defined, %FALSE otherwise.
1182 * Returns: %TRUE if the class @name is defined for the widget at @pos
1187 gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
1190 GtkRegionFlags *flags)
1194 g_return_val_if_fail (path != NULL, FALSE);
1195 g_return_val_if_fail (path->elems->len != 0, FALSE);
1196 g_return_val_if_fail (name != NULL, FALSE);
1198 if (pos < 0 || pos >= path->elems->len)
1199 pos = path->elems->len - 1;
1201 qname = g_quark_try_string (name);
1206 return gtk_widget_path_iter_has_qregion (path, pos, qname, flags);
1210 * gtk_widget_path_get_object_type:
1211 * @path: a #GtkWidget
1213 * Returns the topmost object type, that is, the object type this path
1216 * Returns: The object type
1221 gtk_widget_path_get_object_type (const GtkWidgetPath *path)
1223 GtkPathElement *elem;
1225 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
1227 elem = &g_array_index (path->elems, GtkPathElement,
1228 path->elems->len - 1);
1233 * gtk_widget_path_is_type:
1234 * @path: a #GtkWidgetPath
1235 * @type: widget type to match
1237 * Returns %TRUE if the widget type represented by this path
1238 * is @type, or a subtype of it.
1240 * Returns: %TRUE if the widget represented by @path is of type @type
1245 gtk_widget_path_is_type (const GtkWidgetPath *path,
1248 GtkPathElement *elem;
1250 g_return_val_if_fail (path != NULL, FALSE);
1252 elem = &g_array_index (path->elems, GtkPathElement,
1253 path->elems->len - 1);
1255 if (elem->type == type ||
1256 g_type_is_a (elem->type, type))
1263 * gtk_widget_path_has_parent:
1264 * @path: a #GtkWidgetPath
1265 * @type: widget type to check in parents
1267 * Returns %TRUE if any of the parents of the widget represented
1268 * in @path is of type @type, or any subtype of it.
1270 * Returns: %TRUE if any parent is of type @type
1275 gtk_widget_path_has_parent (const GtkWidgetPath *path,
1280 g_return_val_if_fail (path != NULL, FALSE);
1282 for (i = 0; i < path->elems->len - 1; i++)
1284 GtkPathElement *elem;
1286 elem = &g_array_index (path->elems, GtkPathElement, i);
1288 if (elem->type == type ||
1289 g_type_is_a (elem->type, type))