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 g_array_set_size (new_path->elems, path->elems->len);
179 for (i = 0; i < path->elems->len; i++)
181 GtkPathElement *elem, *dest;
183 elem = &g_array_index (path->elems, GtkPathElement, i);
184 dest = &g_array_index (new_path->elems, GtkPathElement, i);
186 gtk_path_element_copy (dest, elem);
193 * gtk_widget_path_ref:
194 * @path: a #GtkWidgetPath
196 * Increments the reference count on @path.
198 * Returns: @path itself.
203 gtk_widget_path_ref (GtkWidgetPath *path)
205 g_return_val_if_fail (path != NULL, path);
207 g_atomic_int_add (&path->ref_count, 1);
213 * gtk_widget_path_unref:
214 * @path: a #GtkWidgetPath
216 * Decrements the reference count on @path, freeing the structure
217 * if the reference count reaches 0.
222 gtk_widget_path_unref (GtkWidgetPath *path)
226 g_return_if_fail (path != NULL);
228 if (!g_atomic_int_dec_and_test (&path->ref_count))
231 for (i = 0; i < path->elems->len; i++)
233 GtkPathElement *elem;
235 elem = &g_array_index (path->elems, GtkPathElement, i);
238 g_hash_table_destroy (elem->regions);
241 g_array_free (elem->classes, TRUE);
244 gtk_widget_path_unref (elem->siblings);
247 g_array_free (path->elems, TRUE);
248 g_slice_free (GtkWidgetPath, path);
252 * gtk_widget_path_free:
253 * @path: a #GtkWidgetPath
255 * Decrements the reference count on @path, freeing the structure
256 * if the reference count reaches 0.
261 gtk_widget_path_free (GtkWidgetPath *path)
263 g_return_if_fail (path != NULL);
265 gtk_widget_path_unref (path);
269 * gtk_widget_path_length:
270 * @path: a #GtkWidgetPath
272 * Returns the number of #GtkWidget #GTypes between the represented
273 * widget and its topmost container.
275 * Returns: the number of elements in the path
280 gtk_widget_path_length (const GtkWidgetPath *path)
282 g_return_val_if_fail (path != NULL, 0);
284 return path->elems->len;
288 * gtk_widget_path_to_string:
291 * Dumps the widget path into a string representation. It tries to match
292 * the CSS style as closely as possible (Note that there might be paths
293 * that cannot be represented in CSS).
295 * The main use of this code is for debugging purposes, so that you can
296 * g_print() the path or dump it in a gdb session.
298 * Returns: A new string describing @path.
303 gtk_widget_path_to_string (const GtkWidgetPath *path)
308 g_return_val_if_fail (path != NULL, NULL);
310 string = g_string_new ("");
312 for (i = 0; i < path->elems->len; i++)
314 GtkPathElement *elem;
316 elem = &g_array_index (path->elems, GtkPathElement, i);
319 g_string_append_c (string, ' ');
321 g_string_append (string, g_type_name (elem->type));
325 g_string_append_c (string, '(');
326 g_string_append (string, g_quark_to_string (elem->name));
327 g_string_append_c (string, ')');
332 g_string_append_printf (string, "[%d/%d]",
333 elem->sibling_index + 1,
334 gtk_widget_path_length (elem->siblings));
338 for (j = 0; j < elem->classes->len; j++)
340 g_string_append_c (string, '.');
341 g_string_append (string, g_quark_to_string (g_array_index (elem->classes, GQuark, j)));
350 g_hash_table_iter_init (&iter, elem->regions);
351 while (g_hash_table_iter_next (&iter, &key, &value))
353 GtkRegionFlags flags = GPOINTER_TO_UINT (value);
354 static const char *flag_names[] = {
363 g_string_append_c (string, ' ');
364 g_string_append (string, g_quark_to_string (GPOINTER_TO_UINT (key)));
365 for (j = 0; j < G_N_ELEMENTS(flag_names); j++)
367 if (flags & (1 << j))
369 g_string_append_c (string, ':');
370 g_string_append (string, flag_names[j]);
377 return g_string_free (string, FALSE);
381 * gtk_widget_path_prepend_type:
382 * @path: a #GtkWidgetPath
383 * @type: widget type to prepend
385 * Prepends a widget type to the widget hierachy represented by @path.
390 gtk_widget_path_prepend_type (GtkWidgetPath *path,
393 GtkPathElement new = { 0 };
395 g_return_if_fail (path != NULL);
398 g_array_prepend_val (path->elems, new);
402 * gtk_widget_path_append_type:
403 * @path: a #GtkWidgetPath
404 * @type: widget type to append
406 * Appends a widget type to the widget hierarchy represented by @path.
408 * Returns: the position where the element was inserted
413 gtk_widget_path_append_type (GtkWidgetPath *path,
416 GtkPathElement new = { 0 };
418 g_return_val_if_fail (path != NULL, 0);
421 g_array_append_val (path->elems, new);
423 return path->elems->len - 1;
427 * gtk_widget_path_append_with_siblings:
428 * @path: the widget path to append to
429 * @siblings: a widget path describing a list of siblings. This path
430 * may not contain any siblings itself and it must not be modified
432 * @sibling_index: index into @siblings for where the added element is
435 * Appends a widget type with all its siblings to the widget hierarchy
436 * represented by @path. Using this function instead of
437 * gtk_widget_path_append_type() will allow the CSS theming to use
438 * sibling matches in selectors and apply :nth-child() pseudo classes.
439 * In turn, it requires a lot more care in widget implementations as
440 * widgets need to make sure to call gtk_widget_reset_style() on all
441 * involved widgets when the @siblings path changes.
443 * Returns: the position where the element was inserted.
448 gtk_widget_path_append_with_siblings (GtkWidgetPath *path,
449 GtkWidgetPath *siblings,
454 g_return_val_if_fail (path != NULL, 0);
455 g_return_val_if_fail (siblings != NULL, 0);
456 g_return_val_if_fail (sibling_index < gtk_widget_path_length (siblings), 0);
458 gtk_path_element_copy (&new, &g_array_index (siblings->elems, GtkPathElement, sibling_index));
459 new.siblings = gtk_widget_path_ref (siblings);
460 new.sibling_index = sibling_index;
461 g_array_append_val (path->elems, new);
463 return path->elems->len - 1;
467 * gtk_widget_path_iter_get_siblings:
468 * @path: a #GtkWidgetPath
469 * @pos: position to get the siblings for, -1 for the path head
471 * Returns the list of siblings for the element at @pos. If the element
472 * was not added with siblings, %NULL is returned.
474 * Returns: %NULL or the list of siblings for the element at @pos.
476 const GtkWidgetPath *
477 gtk_widget_path_iter_get_siblings (const GtkWidgetPath *path,
480 GtkPathElement *elem;
482 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
483 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
485 if (pos < 0 || pos >= path->elems->len)
486 pos = path->elems->len - 1;
488 elem = &g_array_index (path->elems, GtkPathElement, pos);
489 return elem->siblings;
493 * gtk_widget_path_iter_get_sibling_index:
494 * @path: a #GtkWidgetPath
495 * @pos: position to get the sibling index for, -1 for the path head
497 * Returns the index into the list of siblings for the element at @pos as
498 * returned by gtk_widget_path_iter_get_siblings(). If that function would
499 * return %NULL because the element at @pos has no siblings, this function
502 * Returns: 0 or the index into the list of siblings for the element at @pos.
505 gtk_widget_path_iter_get_sibling_index (const GtkWidgetPath *path,
508 GtkPathElement *elem;
510 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
511 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
513 if (pos < 0 || pos >= path->elems->len)
514 pos = path->elems->len - 1;
516 elem = &g_array_index (path->elems, GtkPathElement, pos);
517 return elem->sibling_index;
521 * gtk_widget_path_iter_get_object_type:
522 * @path: a #GtkWidgetPath
523 * @pos: position to get the object type for, -1 for the path head
525 * Returns the object #GType that is at position @pos in the widget
526 * hierarchy defined in @path.
528 * Returns: a widget type
533 gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path,
536 GtkPathElement *elem;
538 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
539 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
541 if (pos < 0 || pos >= path->elems->len)
542 pos = path->elems->len - 1;
544 elem = &g_array_index (path->elems, GtkPathElement, pos);
549 * gtk_widget_path_iter_set_object_type:
550 * @path: a #GtkWidgetPath
551 * @pos: position to modify, -1 for the path head
552 * @type: object type to set
554 * Sets the object type for a given position in the widget hierarchy
560 gtk_widget_path_iter_set_object_type (GtkWidgetPath *path,
564 GtkPathElement *elem;
566 g_return_if_fail (path != NULL);
567 g_return_if_fail (path->elems->len != 0);
569 if (pos < 0 || pos >= path->elems->len)
570 pos = path->elems->len - 1;
572 elem = &g_array_index (path->elems, GtkPathElement, pos);
577 * gtk_widget_path_iter_get_name:
578 * @path: a #GtkWidgetPath
579 * @pos: position to get the widget name for, -1 for the path head
581 * Returns the name corresponding to the widget found at
582 * the position @pos in the widget hierarchy defined by
585 * Returns: The widget name, or %NULL if none was set.
588 gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
591 GtkPathElement *elem;
593 g_return_val_if_fail (path != NULL, NULL);
594 g_return_val_if_fail (path->elems->len != 0, NULL);
596 if (pos < 0 || pos >= path->elems->len)
597 pos = path->elems->len - 1;
599 elem = &g_array_index (path->elems, GtkPathElement, pos);
600 return g_quark_to_string (elem->name);
604 * gtk_widget_path_iter_set_name:
605 * @path: a #GtkWidgetPath
606 * @pos: position to modify, -1 for the path head
609 * Sets the widget name for the widget found at position @pos
610 * in the widget hierarchy defined by @path.
615 gtk_widget_path_iter_set_name (GtkWidgetPath *path,
619 GtkPathElement *elem;
621 g_return_if_fail (path != NULL);
622 g_return_if_fail (path->elems->len != 0);
623 g_return_if_fail (name != NULL);
625 if (pos < 0 || pos >= path->elems->len)
626 pos = path->elems->len - 1;
628 elem = &g_array_index (path->elems, GtkPathElement, pos);
630 elem->name = g_quark_from_string (name);
634 * gtk_widget_path_iter_has_qname:
635 * @path: a #GtkWidgetPath
636 * @pos: position to query, -1 for the path head
637 * @qname: widget name as a #GQuark
639 * See gtk_widget_path_iter_has_name(). This is a version
640 * that operates on #GQuark<!-- -->s.
642 * Returns: %TRUE if the widget at @pos has this name
647 gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
651 GtkPathElement *elem;
653 g_return_val_if_fail (path != NULL, FALSE);
654 g_return_val_if_fail (path->elems->len != 0, FALSE);
655 g_return_val_if_fail (qname != 0, FALSE);
657 if (pos < 0 || pos >= path->elems->len)
658 pos = path->elems->len - 1;
660 elem = &g_array_index (path->elems, GtkPathElement, pos);
662 return (elem->name == qname);
666 * gtk_widget_path_iter_has_name:
667 * @path: a #GtkWidgetPath
668 * @pos: position to query, -1 for the path head
669 * @name: a widget name
671 * Returns %TRUE if the widget at position @pos has the name @name,
674 * Returns: %TRUE if the widget at @pos has this name
679 gtk_widget_path_iter_has_name (const GtkWidgetPath *path,
685 g_return_val_if_fail (path != NULL, FALSE);
686 g_return_val_if_fail (path->elems->len != 0, FALSE);
688 if (pos < 0 || pos >= path->elems->len)
689 pos = path->elems->len - 1;
691 qname = g_quark_try_string (name);
696 return gtk_widget_path_iter_has_qname (path, pos, qname);
700 * gtk_widget_path_iter_add_class:
701 * @path: a #GtkWidget
702 * @pos: position to modify, -1 for the path head
703 * @name: a class name
705 * Adds the class @name to the widget at position @pos in
706 * the hierarchy defined in @path. See
707 * gtk_style_context_add_class().
712 gtk_widget_path_iter_add_class (GtkWidgetPath *path,
716 GtkPathElement *elem;
717 gboolean added = FALSE;
721 g_return_if_fail (path != NULL);
722 g_return_if_fail (path->elems->len != 0);
723 g_return_if_fail (name != NULL);
725 if (pos < 0 || pos >= path->elems->len)
726 pos = path->elems->len - 1;
728 elem = &g_array_index (path->elems, GtkPathElement, pos);
729 qname = g_quark_from_string (name);
732 elem->classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
734 for (i = 0; i < elem->classes->len; i++)
738 quark = g_array_index (elem->classes, GQuark, i);
748 g_array_insert_val (elem->classes, i, qname);
755 g_array_append_val (elem->classes, qname);
759 * gtk_widget_path_iter_remove_class:
760 * @path: a #GtkWidgetPath
761 * @pos: position to modify, -1 for the path head
764 * Removes the class @name from the widget at position @pos in
765 * the hierarchy defined in @path.
770 gtk_widget_path_iter_remove_class (GtkWidgetPath *path,
774 GtkPathElement *elem;
778 g_return_if_fail (path != NULL);
779 g_return_if_fail (path->elems->len != 0);
780 g_return_if_fail (name != NULL);
782 if (pos < 0 || pos >= path->elems->len)
783 pos = path->elems->len - 1;
785 qname = g_quark_try_string (name);
790 elem = &g_array_index (path->elems, GtkPathElement, pos);
795 for (i = 0; i < elem->classes->len; i++)
799 quark = g_array_index (elem->classes, GQuark, i);
803 else if (quark == qname)
805 g_array_remove_index (elem->classes, i);
812 * gtk_widget_path_iter_clear_classes:
813 * @path: a #GtkWidget
814 * @pos: position to modify, -1 for the path head
816 * Removes all classes from the widget at position @pos in the
817 * hierarchy defined in @path.
822 gtk_widget_path_iter_clear_classes (GtkWidgetPath *path,
825 GtkPathElement *elem;
827 g_return_if_fail (path != NULL);
828 g_return_if_fail (path->elems->len != 0);
830 if (pos < 0 || pos >= path->elems->len)
831 pos = path->elems->len - 1;
833 elem = &g_array_index (path->elems, GtkPathElement, pos);
838 if (elem->classes->len > 0)
839 g_array_remove_range (elem->classes, 0, elem->classes->len);
843 * gtk_widget_path_iter_list_classes:
844 * @path: a #GtkWidgetPath
845 * @pos: position to query, -1 for the path head
847 * Returns a list with all the class names defined for the widget
848 * at position @pos in the hierarchy defined in @path.
850 * Returns: (transfer container) (element-type utf8): The list of
851 * classes, This is a list of strings, the #GSList contents
852 * are owned by GTK+, but you should use g_slist_free() to
853 * free the list itself.
858 gtk_widget_path_iter_list_classes (const GtkWidgetPath *path,
861 GtkPathElement *elem;
865 g_return_val_if_fail (path != NULL, NULL);
866 g_return_val_if_fail (path->elems->len != 0, NULL);
868 if (pos < 0 || pos >= path->elems->len)
869 pos = path->elems->len - 1;
871 elem = &g_array_index (path->elems, GtkPathElement, pos);
876 for (i = 0; i < elem->classes->len; i++)
880 quark = g_array_index (elem->classes, GQuark, i);
881 list = g_slist_prepend (list, (gchar *) g_quark_to_string (quark));
884 return g_slist_reverse (list);
888 * gtk_widget_path_iter_has_qclass:
889 * @path: a #GtkWidgetPath
890 * @pos: position to query, -1 for the path head
891 * @qname: class name as a #GQuark
893 * See gtk_widget_path_iter_has_class(). This is a version that operates
894 * with GQuark<!-- -->s.
896 * Returns: %TRUE if the widget at @pos has the class defined.
901 gtk_widget_path_iter_has_qclass (const GtkWidgetPath *path,
905 GtkPathElement *elem;
908 g_return_val_if_fail (path != NULL, FALSE);
909 g_return_val_if_fail (path->elems->len != 0, FALSE);
910 g_return_val_if_fail (qname != 0, FALSE);
912 if (pos < 0 || pos >= path->elems->len)
913 pos = path->elems->len - 1;
915 elem = &g_array_index (path->elems, GtkPathElement, pos);
920 for (i = 0; i < elem->classes->len; i++)
924 quark = g_array_index (elem->classes, GQuark, i);
928 else if (quark > qname)
936 * gtk_widget_path_iter_has_class:
937 * @path: a #GtkWidgetPath
938 * @pos: position to query, -1 for the path head
941 * Returns %TRUE if the widget at position @pos has the class @name
942 * defined, %FALSE otherwise.
944 * Returns: %TRUE if the class @name is defined for the widget at @pos
949 gtk_widget_path_iter_has_class (const GtkWidgetPath *path,
955 g_return_val_if_fail (path != NULL, FALSE);
956 g_return_val_if_fail (path->elems->len != 0, FALSE);
957 g_return_val_if_fail (name != NULL, FALSE);
959 if (pos < 0 || pos >= path->elems->len)
960 pos = path->elems->len - 1;
962 qname = g_quark_try_string (name);
967 return gtk_widget_path_iter_has_qclass (path, pos, qname);
971 * gtk_widget_path_iter_add_region:
972 * @path: a #GtkWidgetPath
973 * @pos: position to modify, -1 for the path head
975 * @flags: flags affecting the region
977 * Adds the region @name to the widget at position @pos in
978 * the hierarchy defined in @path. See
979 * gtk_style_context_add_region().
981 * <note><para>Region names must only contain lowercase letters
982 * and '-', starting always with a lowercase letter.</para></note>
987 gtk_widget_path_iter_add_region (GtkWidgetPath *path,
990 GtkRegionFlags flags)
992 GtkPathElement *elem;
995 g_return_if_fail (path != NULL);
996 g_return_if_fail (path->elems->len != 0);
997 g_return_if_fail (name != NULL);
998 g_return_if_fail (_gtk_style_context_check_region_name (name));
1000 if (pos < 0 || pos >= path->elems->len)
1001 pos = path->elems->len - 1;
1003 elem = &g_array_index (path->elems, GtkPathElement, pos);
1004 qname = g_quark_from_string (name);
1007 elem->regions = g_hash_table_new (NULL, NULL);
1009 g_hash_table_insert (elem->regions,
1010 GUINT_TO_POINTER (qname),
1011 GUINT_TO_POINTER (flags));
1015 * gtk_widget_path_iter_remove_region:
1016 * @path: a #GtkWidgetPath
1017 * @pos: position to modify, -1 for the path head
1018 * @name: region name
1020 * Removes the region @name from the widget at position @pos in
1021 * the hierarchy defined in @path.
1026 gtk_widget_path_iter_remove_region (GtkWidgetPath *path,
1030 GtkPathElement *elem;
1033 g_return_if_fail (path != NULL);
1034 g_return_if_fail (path->elems->len != 0);
1035 g_return_if_fail (name != NULL);
1037 if (pos < 0 || pos >= path->elems->len)
1038 pos = path->elems->len - 1;
1040 qname = g_quark_try_string (name);
1045 elem = &g_array_index (path->elems, GtkPathElement, pos);
1048 g_hash_table_remove (elem->regions, GUINT_TO_POINTER (qname));
1052 * gtk_widget_path_iter_clear_regions:
1053 * @path: a #GtkWidgetPath
1054 * @pos: position to modify, -1 for the path head
1056 * Removes all regions from the widget at position @pos in the
1057 * hierarchy defined in @path.
1062 gtk_widget_path_iter_clear_regions (GtkWidgetPath *path,
1065 GtkPathElement *elem;
1067 g_return_if_fail (path != NULL);
1068 g_return_if_fail (path->elems->len != 0);
1070 if (pos < 0 || pos >= path->elems->len)
1071 pos = path->elems->len - 1;
1073 elem = &g_array_index (path->elems, GtkPathElement, pos);
1076 g_hash_table_remove_all (elem->regions);
1080 * gtk_widget_path_iter_list_regions:
1081 * @path: a #GtkWidgetPath
1082 * @pos: position to query, -1 for the path head
1084 * Returns a list with all the region names defined for the widget
1085 * at position @pos in the hierarchy defined in @path.
1087 * Returns: (transfer container) (element-type utf8): The list of
1088 * regions, This is a list of strings, the #GSList contents
1089 * are owned by GTK+, but you should use g_slist_free() to
1090 * free the list itself.
1095 gtk_widget_path_iter_list_regions (const GtkWidgetPath *path,
1098 GtkPathElement *elem;
1099 GHashTableIter iter;
1100 GSList *list = NULL;
1103 g_return_val_if_fail (path != NULL, NULL);
1104 g_return_val_if_fail (path->elems->len != 0, NULL);
1106 if (pos < 0 || pos >= path->elems->len)
1107 pos = path->elems->len - 1;
1109 elem = &g_array_index (path->elems, GtkPathElement, pos);
1114 g_hash_table_iter_init (&iter, elem->regions);
1116 while (g_hash_table_iter_next (&iter, &key, NULL))
1120 qname = GPOINTER_TO_UINT (key);
1121 list = g_slist_prepend (list, (gchar *) g_quark_to_string (qname));
1128 * gtk_widget_path_iter_has_qregion:
1129 * @path: a #GtkWidgetPath
1130 * @pos: position to query, -1 for the path head
1131 * @qname: region name as a #GQuark
1132 * @flags: (out): return location for the region flags
1134 * See gtk_widget_path_iter_has_region(). This is a version that operates
1135 * with GQuark<!-- -->s.
1137 * Returns: %TRUE if the widget at @pos has the region defined.
1142 gtk_widget_path_iter_has_qregion (const GtkWidgetPath *path,
1145 GtkRegionFlags *flags)
1147 GtkPathElement *elem;
1150 g_return_val_if_fail (path != NULL, FALSE);
1151 g_return_val_if_fail (path->elems->len != 0, FALSE);
1152 g_return_val_if_fail (qname != 0, FALSE);
1154 if (pos < 0 || pos >= path->elems->len)
1155 pos = path->elems->len - 1;
1157 elem = &g_array_index (path->elems, GtkPathElement, pos);
1162 if (!g_hash_table_lookup_extended (elem->regions,
1163 GUINT_TO_POINTER (qname),
1168 *flags = GPOINTER_TO_UINT (value);
1174 * gtk_widget_path_iter_has_region:
1175 * @path: a #GtkWidgetPath
1176 * @pos: position to query, -1 for the path head
1177 * @name: region name
1178 * @flags: (out): return location for the region flags
1180 * Returns %TRUE if the widget at position @pos has the class @name
1181 * defined, %FALSE otherwise.
1183 * Returns: %TRUE if the class @name is defined for the widget at @pos
1188 gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
1191 GtkRegionFlags *flags)
1195 g_return_val_if_fail (path != NULL, FALSE);
1196 g_return_val_if_fail (path->elems->len != 0, FALSE);
1197 g_return_val_if_fail (name != NULL, FALSE);
1199 if (pos < 0 || pos >= path->elems->len)
1200 pos = path->elems->len - 1;
1202 qname = g_quark_try_string (name);
1207 return gtk_widget_path_iter_has_qregion (path, pos, qname, flags);
1211 * gtk_widget_path_get_object_type:
1212 * @path: a #GtkWidget
1214 * Returns the topmost object type, that is, the object type this path
1217 * Returns: The object type
1222 gtk_widget_path_get_object_type (const GtkWidgetPath *path)
1224 GtkPathElement *elem;
1226 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
1228 elem = &g_array_index (path->elems, GtkPathElement,
1229 path->elems->len - 1);
1234 * gtk_widget_path_is_type:
1235 * @path: a #GtkWidgetPath
1236 * @type: widget type to match
1238 * Returns %TRUE if the widget type represented by this path
1239 * is @type, or a subtype of it.
1241 * Returns: %TRUE if the widget represented by @path is of type @type
1246 gtk_widget_path_is_type (const GtkWidgetPath *path,
1249 GtkPathElement *elem;
1251 g_return_val_if_fail (path != NULL, FALSE);
1253 elem = &g_array_index (path->elems, GtkPathElement,
1254 path->elems->len - 1);
1256 if (elem->type == type ||
1257 g_type_is_a (elem->type, type))
1264 * gtk_widget_path_has_parent:
1265 * @path: a #GtkWidgetPath
1266 * @type: widget type to check in parents
1268 * Returns %TRUE if any of the parents of the widget represented
1269 * in @path is of type @type, or any subtype of it.
1271 * Returns: %TRUE if any parent is of type @type
1276 gtk_widget_path_has_parent (const GtkWidgetPath *path,
1281 g_return_val_if_fail (path != NULL, FALSE);
1283 for (i = 0; i < path->elems->len - 1; i++)
1285 GtkPathElement *elem;
1287 elem = &g_array_index (path->elems, GtkPathElement, i);
1289 if (elem->type == type ||
1290 g_type_is_a (elem->type, type))