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 g_string_append_printf (string, "[%d/%d]",
334 elem->sibling_index + 1,
335 gtk_widget_path_length (elem->siblings));
339 for (j = 0; j < elem->classes->len; j++)
341 g_string_append_c (string, '.');
342 g_string_append (string, g_quark_to_string (g_array_index (elem->classes, GQuark, j)));
351 g_hash_table_iter_init (&iter, elem->regions);
352 while (g_hash_table_iter_next (&iter, &key, &value))
354 GtkRegionFlags flags = GPOINTER_TO_UINT (value);
355 static const char *flag_names[] = {
364 g_string_append_c (string, ' ');
365 g_string_append (string, g_quark_to_string (GPOINTER_TO_UINT (key)));
366 for (j = 0; j < G_N_ELEMENTS(flag_names); j++)
368 if (flags & (1 << j))
370 g_string_append_c (string, ':');
371 g_string_append (string, flag_names[j]);
378 return g_string_free (string, FALSE);
382 * gtk_widget_path_prepend_type:
383 * @path: a #GtkWidgetPath
384 * @type: widget type to prepend
386 * Prepends a widget type to the widget hierachy represented by @path.
391 gtk_widget_path_prepend_type (GtkWidgetPath *path,
394 GtkPathElement new = { 0 };
396 g_return_if_fail (path != NULL);
399 g_array_prepend_val (path->elems, new);
403 * gtk_widget_path_append_type:
404 * @path: a #GtkWidgetPath
405 * @type: widget type to append
407 * Appends a widget type to the widget hierarchy represented by @path.
409 * Returns: the position where the element was inserted
414 gtk_widget_path_append_type (GtkWidgetPath *path,
417 GtkPathElement new = { 0 };
419 g_return_val_if_fail (path != NULL, 0);
422 g_array_append_val (path->elems, new);
424 return path->elems->len - 1;
428 * gtk_widget_path_append_with_siblings:
429 * @path: the widget path to append to
430 * @siblings: a widget path describing a list of siblings. This path
431 * may not contain any siblings itself and it must not be modified
433 * @sibling_index: index into @siblings for where the added element is
436 * Appends a widget type with all its siblings to the widget hierarchy
437 * represented by @path. Using this function instead of
438 * gtk_widget_path_append_type() will allow the CSS theming to use
439 * sibling matches in selectors and apply :nth-child() pseudo classes.
440 * In turn, it requires a lot more care in widget implementations as
441 * widgets need to make sure to call gtk_widget_reset_style() on all
442 * involved widgets when the @siblings path changes.
444 * Returns: the position where the element was inserted.
449 gtk_widget_path_append_with_siblings (GtkWidgetPath *path,
450 GtkWidgetPath *siblings,
455 g_return_val_if_fail (path != NULL, 0);
456 g_return_val_if_fail (siblings != NULL, 0);
457 g_return_val_if_fail (sibling_index < gtk_widget_path_length (siblings), 0);
459 gtk_path_element_copy (&new, &g_array_index (siblings->elems, GtkPathElement, sibling_index));
460 new.siblings = gtk_widget_path_ref (siblings);
461 new.sibling_index = sibling_index;
462 g_array_append_val (path->elems, new);
464 return path->elems->len - 1;
468 * gtk_widget_path_iter_get_siblings:
469 * @path: a #GtkWidgetPath
470 * @pos: position to get the siblings for, -1 for the path head
472 * Returns the list of siblings for the element at @pos. If the element
473 * was not added with siblings, %NULL is returned.
475 * Returns: %NULL or the list of siblings for the element at @pos.
477 const GtkWidgetPath *
478 gtk_widget_path_iter_get_siblings (const GtkWidgetPath *path,
481 GtkPathElement *elem;
483 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
484 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
486 if (pos < 0 || pos >= path->elems->len)
487 pos = path->elems->len - 1;
489 elem = &g_array_index (path->elems, GtkPathElement, pos);
490 return elem->siblings;
494 * gtk_widget_path_iter_get_sibling_index:
495 * @path: a #GtkWidgetPath
496 * @pos: position to get the sibling index for, -1 for the path head
498 * Returns the index into the list of siblings for the element at @pos as
499 * returned by gtk_widget_path_iter_get_siblings(). If that function would
500 * return %NULL because the element at @pos has no siblings, this function
503 * Returns: 0 or the index into the list of siblings for the element at @pos.
506 gtk_widget_path_iter_get_sibling_index (const GtkWidgetPath *path,
509 GtkPathElement *elem;
511 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
512 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
514 if (pos < 0 || pos >= path->elems->len)
515 pos = path->elems->len - 1;
517 elem = &g_array_index (path->elems, GtkPathElement, pos);
518 return elem->sibling_index;
522 * gtk_widget_path_iter_get_object_type:
523 * @path: a #GtkWidgetPath
524 * @pos: position to get the object type for, -1 for the path head
526 * Returns the object #GType that is at position @pos in the widget
527 * hierarchy defined in @path.
529 * Returns: a widget type
534 gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path,
537 GtkPathElement *elem;
539 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
540 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
542 if (pos < 0 || pos >= path->elems->len)
543 pos = path->elems->len - 1;
545 elem = &g_array_index (path->elems, GtkPathElement, pos);
550 * gtk_widget_path_iter_set_object_type:
551 * @path: a #GtkWidgetPath
552 * @pos: position to modify, -1 for the path head
553 * @type: object type to set
555 * Sets the object type for a given position in the widget hierarchy
561 gtk_widget_path_iter_set_object_type (GtkWidgetPath *path,
565 GtkPathElement *elem;
567 g_return_if_fail (path != NULL);
568 g_return_if_fail (path->elems->len != 0);
570 if (pos < 0 || pos >= path->elems->len)
571 pos = path->elems->len - 1;
573 elem = &g_array_index (path->elems, GtkPathElement, pos);
578 * gtk_widget_path_iter_get_name:
579 * @path: a #GtkWidgetPath
580 * @pos: position to get the widget name for, -1 for the path head
582 * Returns the name corresponding to the widget found at
583 * the position @pos in the widget hierarchy defined by
586 * Returns: The widget name, or %NULL if none was set.
589 gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
592 GtkPathElement *elem;
594 g_return_val_if_fail (path != NULL, NULL);
595 g_return_val_if_fail (path->elems->len != 0, NULL);
597 if (pos < 0 || pos >= path->elems->len)
598 pos = path->elems->len - 1;
600 elem = &g_array_index (path->elems, GtkPathElement, pos);
601 return g_quark_to_string (elem->name);
605 * gtk_widget_path_iter_set_name:
606 * @path: a #GtkWidgetPath
607 * @pos: position to modify, -1 for the path head
610 * Sets the widget name for the widget found at position @pos
611 * in the widget hierarchy defined by @path.
616 gtk_widget_path_iter_set_name (GtkWidgetPath *path,
620 GtkPathElement *elem;
622 g_return_if_fail (path != NULL);
623 g_return_if_fail (path->elems->len != 0);
624 g_return_if_fail (name != NULL);
626 if (pos < 0 || pos >= path->elems->len)
627 pos = path->elems->len - 1;
629 elem = &g_array_index (path->elems, GtkPathElement, pos);
631 elem->name = g_quark_from_string (name);
635 * gtk_widget_path_iter_has_qname:
636 * @path: a #GtkWidgetPath
637 * @pos: position to query, -1 for the path head
638 * @qname: widget name as a #GQuark
640 * See gtk_widget_path_iter_has_name(). This is a version
641 * that operates on #GQuark<!-- -->s.
643 * Returns: %TRUE if the widget at @pos has this name
648 gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
652 GtkPathElement *elem;
654 g_return_val_if_fail (path != NULL, FALSE);
655 g_return_val_if_fail (path->elems->len != 0, FALSE);
656 g_return_val_if_fail (qname != 0, FALSE);
658 if (pos < 0 || pos >= path->elems->len)
659 pos = path->elems->len - 1;
661 elem = &g_array_index (path->elems, GtkPathElement, pos);
663 return (elem->name == qname);
667 * gtk_widget_path_iter_has_name:
668 * @path: a #GtkWidgetPath
669 * @pos: position to query, -1 for the path head
670 * @name: a widget name
672 * Returns %TRUE if the widget at position @pos has the name @name,
675 * Returns: %TRUE if the widget at @pos has this name
680 gtk_widget_path_iter_has_name (const GtkWidgetPath *path,
686 g_return_val_if_fail (path != NULL, FALSE);
687 g_return_val_if_fail (path->elems->len != 0, FALSE);
689 if (pos < 0 || pos >= path->elems->len)
690 pos = path->elems->len - 1;
692 qname = g_quark_try_string (name);
697 return gtk_widget_path_iter_has_qname (path, pos, qname);
701 * gtk_widget_path_iter_add_class:
702 * @path: a #GtkWidget
703 * @pos: position to modify, -1 for the path head
704 * @name: a class name
706 * Adds the class @name to the widget at position @pos in
707 * the hierarchy defined in @path. See
708 * gtk_style_context_add_class().
713 gtk_widget_path_iter_add_class (GtkWidgetPath *path,
717 GtkPathElement *elem;
718 gboolean added = FALSE;
722 g_return_if_fail (path != NULL);
723 g_return_if_fail (path->elems->len != 0);
724 g_return_if_fail (name != NULL);
726 if (pos < 0 || pos >= path->elems->len)
727 pos = path->elems->len - 1;
729 elem = &g_array_index (path->elems, GtkPathElement, pos);
730 qname = g_quark_from_string (name);
733 elem->classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
735 for (i = 0; i < elem->classes->len; i++)
739 quark = g_array_index (elem->classes, GQuark, i);
749 g_array_insert_val (elem->classes, i, qname);
756 g_array_append_val (elem->classes, qname);
760 * gtk_widget_path_iter_remove_class:
761 * @path: a #GtkWidgetPath
762 * @pos: position to modify, -1 for the path head
765 * Removes the class @name from the widget at position @pos in
766 * the hierarchy defined in @path.
771 gtk_widget_path_iter_remove_class (GtkWidgetPath *path,
775 GtkPathElement *elem;
779 g_return_if_fail (path != NULL);
780 g_return_if_fail (path->elems->len != 0);
781 g_return_if_fail (name != NULL);
783 if (pos < 0 || pos >= path->elems->len)
784 pos = path->elems->len - 1;
786 qname = g_quark_try_string (name);
791 elem = &g_array_index (path->elems, GtkPathElement, pos);
796 for (i = 0; i < elem->classes->len; i++)
800 quark = g_array_index (elem->classes, GQuark, i);
804 else if (quark == qname)
806 g_array_remove_index (elem->classes, i);
813 * gtk_widget_path_iter_clear_classes:
814 * @path: a #GtkWidget
815 * @pos: position to modify, -1 for the path head
817 * Removes all classes from the widget at position @pos in the
818 * hierarchy defined in @path.
823 gtk_widget_path_iter_clear_classes (GtkWidgetPath *path,
826 GtkPathElement *elem;
828 g_return_if_fail (path != NULL);
829 g_return_if_fail (path->elems->len != 0);
831 if (pos < 0 || pos >= path->elems->len)
832 pos = path->elems->len - 1;
834 elem = &g_array_index (path->elems, GtkPathElement, pos);
839 if (elem->classes->len > 0)
840 g_array_remove_range (elem->classes, 0, elem->classes->len);
844 * gtk_widget_path_iter_list_classes:
845 * @path: a #GtkWidgetPath
846 * @pos: position to query, -1 for the path head
848 * Returns a list with all the class names defined for the widget
849 * at position @pos in the hierarchy defined in @path.
851 * Returns: (transfer container) (element-type utf8): The list of
852 * classes, This is a list of strings, the #GSList contents
853 * are owned by GTK+, but you should use g_slist_free() to
854 * free the list itself.
859 gtk_widget_path_iter_list_classes (const GtkWidgetPath *path,
862 GtkPathElement *elem;
866 g_return_val_if_fail (path != NULL, NULL);
867 g_return_val_if_fail (path->elems->len != 0, NULL);
869 if (pos < 0 || pos >= path->elems->len)
870 pos = path->elems->len - 1;
872 elem = &g_array_index (path->elems, GtkPathElement, pos);
877 for (i = 0; i < elem->classes->len; i++)
881 quark = g_array_index (elem->classes, GQuark, i);
882 list = g_slist_prepend (list, (gchar *) g_quark_to_string (quark));
885 return g_slist_reverse (list);
889 * gtk_widget_path_iter_has_qclass:
890 * @path: a #GtkWidgetPath
891 * @pos: position to query, -1 for the path head
892 * @qname: class name as a #GQuark
894 * See gtk_widget_path_iter_has_class(). This is a version that operates
895 * with GQuark<!-- -->s.
897 * Returns: %TRUE if the widget at @pos has the class defined.
902 gtk_widget_path_iter_has_qclass (const GtkWidgetPath *path,
906 GtkPathElement *elem;
909 g_return_val_if_fail (path != NULL, FALSE);
910 g_return_val_if_fail (path->elems->len != 0, FALSE);
911 g_return_val_if_fail (qname != 0, FALSE);
913 if (pos < 0 || pos >= path->elems->len)
914 pos = path->elems->len - 1;
916 elem = &g_array_index (path->elems, GtkPathElement, pos);
921 for (i = 0; i < elem->classes->len; i++)
925 quark = g_array_index (elem->classes, GQuark, i);
929 else if (quark > qname)
937 * gtk_widget_path_iter_has_class:
938 * @path: a #GtkWidgetPath
939 * @pos: position to query, -1 for the path head
942 * Returns %TRUE if the widget at position @pos has the class @name
943 * defined, %FALSE otherwise.
945 * Returns: %TRUE if the class @name is defined for the widget at @pos
950 gtk_widget_path_iter_has_class (const GtkWidgetPath *path,
956 g_return_val_if_fail (path != NULL, FALSE);
957 g_return_val_if_fail (path->elems->len != 0, FALSE);
958 g_return_val_if_fail (name != NULL, FALSE);
960 if (pos < 0 || pos >= path->elems->len)
961 pos = path->elems->len - 1;
963 qname = g_quark_try_string (name);
968 return gtk_widget_path_iter_has_qclass (path, pos, qname);
972 * gtk_widget_path_iter_add_region:
973 * @path: a #GtkWidgetPath
974 * @pos: position to modify, -1 for the path head
976 * @flags: flags affecting the region
978 * Adds the region @name to the widget at position @pos in
979 * the hierarchy defined in @path. See
980 * gtk_style_context_add_region().
982 * <note><para>Region names must only contain lowercase letters
983 * and '-', starting always with a lowercase letter.</para></note>
988 gtk_widget_path_iter_add_region (GtkWidgetPath *path,
991 GtkRegionFlags flags)
993 GtkPathElement *elem;
996 g_return_if_fail (path != NULL);
997 g_return_if_fail (path->elems->len != 0);
998 g_return_if_fail (name != NULL);
999 g_return_if_fail (_gtk_style_context_check_region_name (name));
1001 if (pos < 0 || pos >= path->elems->len)
1002 pos = path->elems->len - 1;
1004 elem = &g_array_index (path->elems, GtkPathElement, pos);
1005 qname = g_quark_from_string (name);
1008 elem->regions = g_hash_table_new (NULL, NULL);
1010 g_hash_table_insert (elem->regions,
1011 GUINT_TO_POINTER (qname),
1012 GUINT_TO_POINTER (flags));
1016 * gtk_widget_path_iter_remove_region:
1017 * @path: a #GtkWidgetPath
1018 * @pos: position to modify, -1 for the path head
1019 * @name: region name
1021 * Removes the region @name from the widget at position @pos in
1022 * the hierarchy defined in @path.
1027 gtk_widget_path_iter_remove_region (GtkWidgetPath *path,
1031 GtkPathElement *elem;
1034 g_return_if_fail (path != NULL);
1035 g_return_if_fail (path->elems->len != 0);
1036 g_return_if_fail (name != NULL);
1038 if (pos < 0 || pos >= path->elems->len)
1039 pos = path->elems->len - 1;
1041 qname = g_quark_try_string (name);
1046 elem = &g_array_index (path->elems, GtkPathElement, pos);
1049 g_hash_table_remove (elem->regions, GUINT_TO_POINTER (qname));
1053 * gtk_widget_path_iter_clear_regions:
1054 * @path: a #GtkWidgetPath
1055 * @pos: position to modify, -1 for the path head
1057 * Removes all regions from the widget at position @pos in the
1058 * hierarchy defined in @path.
1063 gtk_widget_path_iter_clear_regions (GtkWidgetPath *path,
1066 GtkPathElement *elem;
1068 g_return_if_fail (path != NULL);
1069 g_return_if_fail (path->elems->len != 0);
1071 if (pos < 0 || pos >= path->elems->len)
1072 pos = path->elems->len - 1;
1074 elem = &g_array_index (path->elems, GtkPathElement, pos);
1077 g_hash_table_remove_all (elem->regions);
1081 * gtk_widget_path_iter_list_regions:
1082 * @path: a #GtkWidgetPath
1083 * @pos: position to query, -1 for the path head
1085 * Returns a list with all the region names defined for the widget
1086 * at position @pos in the hierarchy defined in @path.
1088 * Returns: (transfer container) (element-type utf8): The list of
1089 * regions, This is a list of strings, the #GSList contents
1090 * are owned by GTK+, but you should use g_slist_free() to
1091 * free the list itself.
1096 gtk_widget_path_iter_list_regions (const GtkWidgetPath *path,
1099 GtkPathElement *elem;
1100 GHashTableIter iter;
1101 GSList *list = NULL;
1104 g_return_val_if_fail (path != NULL, NULL);
1105 g_return_val_if_fail (path->elems->len != 0, NULL);
1107 if (pos < 0 || pos >= path->elems->len)
1108 pos = path->elems->len - 1;
1110 elem = &g_array_index (path->elems, GtkPathElement, pos);
1115 g_hash_table_iter_init (&iter, elem->regions);
1117 while (g_hash_table_iter_next (&iter, &key, NULL))
1121 qname = GPOINTER_TO_UINT (key);
1122 list = g_slist_prepend (list, (gchar *) g_quark_to_string (qname));
1129 * gtk_widget_path_iter_has_qregion:
1130 * @path: a #GtkWidgetPath
1131 * @pos: position to query, -1 for the path head
1132 * @qname: region name as a #GQuark
1133 * @flags: (out): return location for the region flags
1135 * See gtk_widget_path_iter_has_region(). This is a version that operates
1136 * with GQuark<!-- -->s.
1138 * Returns: %TRUE if the widget at @pos has the region defined.
1143 gtk_widget_path_iter_has_qregion (const GtkWidgetPath *path,
1146 GtkRegionFlags *flags)
1148 GtkPathElement *elem;
1151 g_return_val_if_fail (path != NULL, FALSE);
1152 g_return_val_if_fail (path->elems->len != 0, FALSE);
1153 g_return_val_if_fail (qname != 0, FALSE);
1155 if (pos < 0 || pos >= path->elems->len)
1156 pos = path->elems->len - 1;
1158 elem = &g_array_index (path->elems, GtkPathElement, pos);
1163 if (!g_hash_table_lookup_extended (elem->regions,
1164 GUINT_TO_POINTER (qname),
1169 *flags = GPOINTER_TO_UINT (value);
1175 * gtk_widget_path_iter_has_region:
1176 * @path: a #GtkWidgetPath
1177 * @pos: position to query, -1 for the path head
1178 * @name: region name
1179 * @flags: (out): return location for the region flags
1181 * Returns %TRUE if the widget at position @pos has the class @name
1182 * defined, %FALSE otherwise.
1184 * Returns: %TRUE if the class @name is defined for the widget at @pos
1189 gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
1192 GtkRegionFlags *flags)
1196 g_return_val_if_fail (path != NULL, FALSE);
1197 g_return_val_if_fail (path->elems->len != 0, FALSE);
1198 g_return_val_if_fail (name != NULL, FALSE);
1200 if (pos < 0 || pos >= path->elems->len)
1201 pos = path->elems->len - 1;
1203 qname = g_quark_try_string (name);
1208 return gtk_widget_path_iter_has_qregion (path, pos, qname, flags);
1212 * gtk_widget_path_get_object_type:
1213 * @path: a #GtkWidget
1215 * Returns the topmost object type, that is, the object type this path
1218 * Returns: The object type
1223 gtk_widget_path_get_object_type (const GtkWidgetPath *path)
1225 GtkPathElement *elem;
1227 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
1229 elem = &g_array_index (path->elems, GtkPathElement,
1230 path->elems->len - 1);
1235 * gtk_widget_path_is_type:
1236 * @path: a #GtkWidgetPath
1237 * @type: widget type to match
1239 * Returns %TRUE if the widget type represented by this path
1240 * is @type, or a subtype of it.
1242 * Returns: %TRUE if the widget represented by @path is of type @type
1247 gtk_widget_path_is_type (const GtkWidgetPath *path,
1250 GtkPathElement *elem;
1252 g_return_val_if_fail (path != NULL, FALSE);
1254 elem = &g_array_index (path->elems, GtkPathElement,
1255 path->elems->len - 1);
1257 if (elem->type == type ||
1258 g_type_is_a (elem->type, type))
1265 * gtk_widget_path_has_parent:
1266 * @path: a #GtkWidgetPath
1267 * @type: widget type to check in parents
1269 * Returns %TRUE if any of the parents of the widget represented
1270 * in @path is of type @type, or any subtype of it.
1272 * Returns: %TRUE if any parent is of type @type
1277 gtk_widget_path_has_parent (const GtkWidgetPath *path,
1282 g_return_val_if_fail (path != NULL, FALSE);
1284 for (i = 0; i < path->elems->len - 1; i++)
1286 GtkPathElement *elem;
1288 elem = &g_array_index (path->elems, GtkPathElement, i);
1290 if (elem->type == type ||
1291 g_type_is_a (elem->type, type))