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;
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;
140 g_hash_table_iter_init (&iter, src->regions);
141 dest->regions = g_hash_table_new (NULL, NULL);
143 while (g_hash_table_iter_next (&iter, &key, &value))
144 g_hash_table_insert (dest->regions, key, value);
149 dest->classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
150 g_array_append_vals (dest->classes, src->classes->data, src->classes->len);
155 * gtk_widget_path_copy:
156 * @path: a #GtkWidgetPath
158 * Returns a copy of @path
160 * Returns: (transfer full): a copy of @path
165 gtk_widget_path_copy (const GtkWidgetPath *path)
167 GtkWidgetPath *new_path;
170 g_return_val_if_fail (path != NULL, NULL);
172 new_path = gtk_widget_path_new ();
174 for (i = 0; i < path->elems->len; i++)
176 GtkPathElement *elem, new;
178 elem = &g_array_index (path->elems, GtkPathElement, i);
180 gtk_path_element_copy (&new, elem);
182 g_array_append_val (new_path->elems, new);
189 * gtk_widget_path_ref:
190 * @path: a #GtkWidgetPath
192 * Increments the reference count on @path.
194 * Returns: @path itself.
199 gtk_widget_path_ref (GtkWidgetPath *path)
201 g_return_val_if_fail (path != NULL, path);
203 g_atomic_int_add (&path->ref_count, 1);
209 * gtk_widget_path_unref:
210 * @path: a #GtkWidgetPath
212 * Decrements the reference count on @path, freeing the structure
213 * if the reference count reaches 0.
218 gtk_widget_path_unref (GtkWidgetPath *path)
222 g_return_if_fail (path != NULL);
224 if (!g_atomic_int_dec_and_test (&path->ref_count))
227 for (i = 0; i < path->elems->len; i++)
229 GtkPathElement *elem;
231 elem = &g_array_index (path->elems, GtkPathElement, i);
234 g_hash_table_destroy (elem->regions);
237 g_array_free (elem->classes, TRUE);
240 g_array_free (path->elems, TRUE);
241 g_slice_free (GtkWidgetPath, path);
245 * gtk_widget_path_free:
246 * @path: a #GtkWidgetPath
248 * Decrements the reference count on @path, freeing the structure
249 * if the reference count reaches 0.
254 gtk_widget_path_free (GtkWidgetPath *path)
256 g_return_if_fail (path != NULL);
258 gtk_widget_path_unref (path);
262 * gtk_widget_path_length:
263 * @path: a #GtkWidgetPath
265 * Returns the number of #GtkWidget #GTypes between the represented
266 * widget and its topmost container.
268 * Returns: the number of elements in the path
273 gtk_widget_path_length (const GtkWidgetPath *path)
275 g_return_val_if_fail (path != NULL, 0);
277 return path->elems->len;
281 * gtk_widget_path_to_string:
284 * Dumps the widget path into a string representation. It tries to match
285 * the CSS style as closely as possible (Note that there might be paths
286 * that cannot be represented in CSS).
288 * The main use of this code is for debugging purposes, so that you can
289 * g_print() the path or dump it in a gdb session.
291 * Returns: A new string describing @path.
296 gtk_widget_path_to_string (const GtkWidgetPath *path)
301 g_return_val_if_fail (path != NULL, NULL);
303 string = g_string_new ("");
305 for (i = 0; i < path->elems->len; i++)
307 GtkPathElement *elem;
309 elem = &g_array_index (path->elems, GtkPathElement, i);
312 g_string_append_c (string, ' ');
314 g_string_append (string, g_type_name (elem->type));
318 g_string_append_c (string, '(');
319 g_string_append (string, g_quark_to_string (elem->name));
320 g_string_append_c (string, ')');
325 for (j = 0; j < elem->classes->len; j++)
327 g_string_append_c (string, '.');
328 g_string_append (string, g_quark_to_string (g_array_index (elem->classes, GQuark, j)));
337 g_hash_table_iter_init (&iter, elem->regions);
338 while (g_hash_table_iter_next (&iter, &key, &value))
340 GtkRegionFlags flags = GPOINTER_TO_UINT (value);
341 static const char *flag_names[] = {
349 g_string_append_c (string, ' ');
350 g_string_append (string, g_quark_to_string (GPOINTER_TO_UINT (key)));
351 for (j = 0; j < G_N_ELEMENTS(flag_names); j++)
353 if (flags & (1 << j))
355 g_string_append_c (string, ':');
356 g_string_append (string, flag_names[j]);
363 return g_string_free (string, FALSE);
367 * gtk_widget_path_prepend_type:
368 * @path: a #GtkWidgetPath
369 * @type: widget type to prepend
371 * Prepends a widget type to the widget hierachy represented by @path.
376 gtk_widget_path_prepend_type (GtkWidgetPath *path,
379 GtkPathElement new = { 0 };
381 g_return_if_fail (path != NULL);
384 g_array_prepend_val (path->elems, new);
388 * gtk_widget_path_append_type:
389 * @path: a #GtkWidgetPath
390 * @type: widget type to append
392 * Appends a widget type to the widget hierarchy represented by @path.
394 * Returns: the position where the element was inserted
399 gtk_widget_path_append_type (GtkWidgetPath *path,
402 GtkPathElement new = { 0 };
404 g_return_val_if_fail (path != NULL, 0);
407 g_array_append_val (path->elems, new);
409 return path->elems->len - 1;
413 * gtk_widget_path_iter_get_object_type:
414 * @path: a #GtkWidgetPath
415 * @pos: position to get the object type for, -1 for the path head
417 * Returns the object #GType that is at position @pos in the widget
418 * hierarchy defined in @path.
420 * Returns: a widget type
425 gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path,
428 GtkPathElement *elem;
430 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
431 g_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID);
433 if (pos < 0 || pos >= path->elems->len)
434 pos = path->elems->len - 1;
436 elem = &g_array_index (path->elems, GtkPathElement, pos);
441 * gtk_widget_path_iter_set_object_type:
442 * @path: a #GtkWidgetPath
443 * @pos: position to modify, -1 for the path head
444 * @type: object type to set
446 * Sets the object type for a given position in the widget hierarchy
452 gtk_widget_path_iter_set_object_type (GtkWidgetPath *path,
456 GtkPathElement *elem;
458 g_return_if_fail (path != NULL);
459 g_return_if_fail (path->elems->len != 0);
461 if (pos < 0 || pos >= path->elems->len)
462 pos = path->elems->len - 1;
464 elem = &g_array_index (path->elems, GtkPathElement, pos);
469 * gtk_widget_path_iter_get_name:
470 * @path: a #GtkWidgetPath
471 * @pos: position to get the widget name for, -1 for the path head
473 * Returns the name corresponding to the widget found at
474 * the position @pos in the widget hierarchy defined by
477 * Returns: The widget name, or %NULL if none was set.
479 G_CONST_RETURN gchar *
480 gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
483 GtkPathElement *elem;
485 g_return_val_if_fail (path != NULL, NULL);
486 g_return_val_if_fail (path->elems->len != 0, NULL);
488 if (pos < 0 || pos >= path->elems->len)
489 pos = path->elems->len - 1;
491 elem = &g_array_index (path->elems, GtkPathElement, pos);
492 return g_quark_to_string (elem->name);
496 * gtk_widget_path_iter_set_name:
497 * @path: a #GtkWidgetPath
498 * @pos: position to modify, -1 for the path head
501 * Sets the widget name for the widget found at position @pos
502 * in the widget hierarchy defined by @path.
507 gtk_widget_path_iter_set_name (GtkWidgetPath *path,
511 GtkPathElement *elem;
513 g_return_if_fail (path != NULL);
514 g_return_if_fail (path->elems->len != 0);
515 g_return_if_fail (name != NULL);
517 if (pos < 0 || pos >= path->elems->len)
518 pos = path->elems->len - 1;
520 elem = &g_array_index (path->elems, GtkPathElement, pos);
522 elem->name = g_quark_from_string (name);
526 * gtk_widget_path_iter_has_qname:
527 * @path: a #GtkWidgetPath
528 * @pos: position to query, -1 for the path head
529 * @qname: widget name as a #GQuark
531 * See gtk_widget_path_iter_has_name(). This is a version
532 * that operates on #GQuark<!-- -->s.
534 * Returns: %TRUE if the widget at @pos has this name
539 gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
543 GtkPathElement *elem;
545 g_return_val_if_fail (path != NULL, FALSE);
546 g_return_val_if_fail (path->elems->len != 0, FALSE);
547 g_return_val_if_fail (qname != 0, FALSE);
549 if (pos < 0 || pos >= path->elems->len)
550 pos = path->elems->len - 1;
552 elem = &g_array_index (path->elems, GtkPathElement, pos);
554 return (elem->name == qname);
558 * gtk_widget_path_iter_has_name:
559 * @path: a #GtkWidgetPath
560 * @pos: position to query, -1 for the path head
561 * @name: a widget name
563 * Returns %TRUE if the widget at position @pos has the name @name,
566 * Returns: %TRUE if the widget at @pos has this name
571 gtk_widget_path_iter_has_name (const GtkWidgetPath *path,
577 g_return_val_if_fail (path != NULL, FALSE);
578 g_return_val_if_fail (path->elems->len != 0, FALSE);
580 if (pos < 0 || pos >= path->elems->len)
581 pos = path->elems->len - 1;
583 qname = g_quark_try_string (name);
588 return gtk_widget_path_iter_has_qname (path, pos, qname);
592 * gtk_widget_path_iter_add_class:
593 * @path: a #GtkWidget
594 * @pos: position to modify, -1 for the path head
595 * @name: a class name
597 * Adds the class @name to the widget at position @pos in
598 * the hierarchy defined in @path. See
599 * gtk_style_context_add_class().
604 gtk_widget_path_iter_add_class (GtkWidgetPath *path,
608 GtkPathElement *elem;
609 gboolean added = FALSE;
613 g_return_if_fail (path != NULL);
614 g_return_if_fail (path->elems->len != 0);
615 g_return_if_fail (name != NULL);
617 if (pos < 0 || pos >= path->elems->len)
618 pos = path->elems->len - 1;
620 elem = &g_array_index (path->elems, GtkPathElement, pos);
621 qname = g_quark_from_string (name);
624 elem->classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
626 for (i = 0; i < elem->classes->len; i++)
630 quark = g_array_index (elem->classes, GQuark, i);
640 g_array_insert_val (elem->classes, i, qname);
647 g_array_append_val (elem->classes, qname);
651 * gtk_widget_path_iter_remove_class:
652 * @path: a #GtkWidgetPath
653 * @pos: position to modify, -1 for the path head
656 * Removes the class @name from the widget at position @pos in
657 * the hierarchy defined in @path.
662 gtk_widget_path_iter_remove_class (GtkWidgetPath *path,
666 GtkPathElement *elem;
670 g_return_if_fail (path != NULL);
671 g_return_if_fail (path->elems->len != 0);
672 g_return_if_fail (name != NULL);
674 if (pos < 0 || pos >= path->elems->len)
675 pos = path->elems->len - 1;
677 qname = g_quark_try_string (name);
682 elem = &g_array_index (path->elems, GtkPathElement, pos);
687 for (i = 0; i < elem->classes->len; i++)
691 quark = g_array_index (elem->classes, GQuark, i);
695 else if (quark == qname)
697 g_array_remove_index (elem->classes, i);
704 * gtk_widget_path_iter_clear_classes:
705 * @path: a #GtkWidget
706 * @pos: position to modify, -1 for the path head
708 * Removes all classes from the widget at position @pos in the
709 * hierarchy defined in @path.
714 gtk_widget_path_iter_clear_classes (GtkWidgetPath *path,
717 GtkPathElement *elem;
719 g_return_if_fail (path != NULL);
720 g_return_if_fail (path->elems->len != 0);
722 if (pos < 0 || pos >= path->elems->len)
723 pos = path->elems->len - 1;
725 elem = &g_array_index (path->elems, GtkPathElement, pos);
730 if (elem->classes->len > 0)
731 g_array_remove_range (elem->classes, 0, elem->classes->len);
735 * gtk_widget_path_iter_list_classes:
736 * @path: a #GtkWidgetPath
737 * @pos: position to query, -1 for the path head
739 * Returns a list with all the class names defined for the widget
740 * at position @pos in the hierarchy defined in @path.
742 * Returns: (transfer container) (element-type utf8): The list of
743 * classes, This is a list of strings, the #GSList contents
744 * are owned by GTK+, but you should use g_slist_free() to
745 * free the list itself.
750 gtk_widget_path_iter_list_classes (const GtkWidgetPath *path,
753 GtkPathElement *elem;
757 g_return_val_if_fail (path != NULL, NULL);
758 g_return_val_if_fail (path->elems->len != 0, NULL);
760 if (pos < 0 || pos >= path->elems->len)
761 pos = path->elems->len - 1;
763 elem = &g_array_index (path->elems, GtkPathElement, pos);
768 for (i = 0; i < elem->classes->len; i++)
772 quark = g_array_index (elem->classes, GQuark, i);
773 list = g_slist_prepend (list, (gchar *) g_quark_to_string (quark));
776 return g_slist_reverse (list);
780 * gtk_widget_path_iter_has_qclass:
781 * @path: a #GtkWidgetPath
782 * @pos: position to query, -1 for the path head
783 * @qname: class name as a #GQuark
785 * See gtk_widget_path_iter_has_class(). This is a version that operates
786 * with GQuark<!-- -->s.
788 * Returns: %TRUE if the widget at @pos has the class defined.
793 gtk_widget_path_iter_has_qclass (const GtkWidgetPath *path,
797 GtkPathElement *elem;
800 g_return_val_if_fail (path != NULL, FALSE);
801 g_return_val_if_fail (path->elems->len != 0, FALSE);
802 g_return_val_if_fail (qname != 0, FALSE);
804 if (pos < 0 || pos >= path->elems->len)
805 pos = path->elems->len - 1;
807 elem = &g_array_index (path->elems, GtkPathElement, pos);
812 for (i = 0; i < elem->classes->len; i++)
816 quark = g_array_index (elem->classes, GQuark, i);
820 else if (quark > qname)
828 * gtk_widget_path_iter_has_class:
829 * @path: a #GtkWidgetPath
830 * @pos: position to query, -1 for the path head
833 * Returns %TRUE if the widget at position @pos has the class @name
834 * defined, %FALSE otherwise.
836 * Returns: %TRUE if the class @name is defined for the widget at @pos
841 gtk_widget_path_iter_has_class (const GtkWidgetPath *path,
847 g_return_val_if_fail (path != NULL, FALSE);
848 g_return_val_if_fail (path->elems->len != 0, FALSE);
849 g_return_val_if_fail (name != NULL, FALSE);
851 if (pos < 0 || pos >= path->elems->len)
852 pos = path->elems->len - 1;
854 qname = g_quark_try_string (name);
859 return gtk_widget_path_iter_has_qclass (path, pos, qname);
863 * gtk_widget_path_iter_add_region:
864 * @path: a #GtkWidgetPath
865 * @pos: position to modify, -1 for the path head
867 * @flags: flags affecting the region
869 * Adds the region @name to the widget at position @pos in
870 * the hierarchy defined in @path. See
871 * gtk_style_context_add_region().
873 * <note><para>Region names must only contain lowercase letters
874 * and '-', starting always with a lowercase letter.</para></note>
879 gtk_widget_path_iter_add_region (GtkWidgetPath *path,
882 GtkRegionFlags flags)
884 GtkPathElement *elem;
887 g_return_if_fail (path != NULL);
888 g_return_if_fail (path->elems->len != 0);
889 g_return_if_fail (name != NULL);
890 g_return_if_fail (_gtk_style_context_check_region_name (name));
892 if (pos < 0 || pos >= path->elems->len)
893 pos = path->elems->len - 1;
895 elem = &g_array_index (path->elems, GtkPathElement, pos);
896 qname = g_quark_from_string (name);
899 elem->regions = g_hash_table_new (NULL, NULL);
901 g_hash_table_insert (elem->regions,
902 GUINT_TO_POINTER (qname),
903 GUINT_TO_POINTER (flags));
907 * gtk_widget_path_iter_remove_region:
908 * @path: a #GtkWidgetPath
909 * @pos: position to modify, -1 for the path head
912 * Removes the region @name from the widget at position @pos in
913 * the hierarchy defined in @path.
918 gtk_widget_path_iter_remove_region (GtkWidgetPath *path,
922 GtkPathElement *elem;
925 g_return_if_fail (path != NULL);
926 g_return_if_fail (path->elems->len != 0);
927 g_return_if_fail (name != NULL);
929 if (pos < 0 || pos >= path->elems->len)
930 pos = path->elems->len - 1;
932 qname = g_quark_try_string (name);
937 elem = &g_array_index (path->elems, GtkPathElement, pos);
940 g_hash_table_remove (elem->regions, GUINT_TO_POINTER (qname));
944 * gtk_widget_path_iter_clear_regions:
945 * @path: a #GtkWidgetPath
946 * @pos: position to modify, -1 for the path head
948 * Removes all regions from the widget at position @pos in the
949 * hierarchy defined in @path.
954 gtk_widget_path_iter_clear_regions (GtkWidgetPath *path,
957 GtkPathElement *elem;
959 g_return_if_fail (path != NULL);
960 g_return_if_fail (path->elems->len != 0);
962 if (pos < 0 || pos >= path->elems->len)
963 pos = path->elems->len - 1;
965 elem = &g_array_index (path->elems, GtkPathElement, pos);
968 g_hash_table_remove_all (elem->regions);
972 * gtk_widget_path_iter_list_regions:
973 * @path: a #GtkWidgetPath
974 * @pos: position to query, -1 for the path head
976 * Returns a list with all the region names defined for the widget
977 * at position @pos in the hierarchy defined in @path.
979 * Returns: (transfer container) (element-type utf8): The list of
980 * regions, This is a list of strings, the #GSList contents
981 * are owned by GTK+, but you should use g_slist_free() to
982 * free the list itself.
987 gtk_widget_path_iter_list_regions (const GtkWidgetPath *path,
990 GtkPathElement *elem;
995 g_return_val_if_fail (path != NULL, NULL);
996 g_return_val_if_fail (path->elems->len != 0, NULL);
998 if (pos < 0 || pos >= path->elems->len)
999 pos = path->elems->len - 1;
1001 elem = &g_array_index (path->elems, GtkPathElement, pos);
1006 g_hash_table_iter_init (&iter, elem->regions);
1008 while (g_hash_table_iter_next (&iter, &key, NULL))
1012 qname = GPOINTER_TO_UINT (key);
1013 list = g_slist_prepend (list, (gchar *) g_quark_to_string (qname));
1020 * gtk_widget_path_iter_has_qregion:
1021 * @path: a #GtkWidgetPath
1022 * @pos: position to query, -1 for the path head
1023 * @qname: region name as a #GQuark
1024 * @flags: (out): return location for the region flags
1026 * See gtk_widget_path_iter_has_region(). This is a version that operates
1027 * with GQuark<!-- -->s.
1029 * Returns: %TRUE if the widget at @pos has the region defined.
1034 gtk_widget_path_iter_has_qregion (const GtkWidgetPath *path,
1037 GtkRegionFlags *flags)
1039 GtkPathElement *elem;
1042 g_return_val_if_fail (path != NULL, FALSE);
1043 g_return_val_if_fail (path->elems->len != 0, FALSE);
1044 g_return_val_if_fail (qname != 0, FALSE);
1046 if (pos < 0 || pos >= path->elems->len)
1047 pos = path->elems->len - 1;
1049 elem = &g_array_index (path->elems, GtkPathElement, pos);
1054 if (!g_hash_table_lookup_extended (elem->regions,
1055 GUINT_TO_POINTER (qname),
1060 *flags = GPOINTER_TO_UINT (value);
1066 * gtk_widget_path_iter_has_region:
1067 * @path: a #GtkWidgetPath
1068 * @pos: position to query, -1 for the path head
1069 * @name: region name
1070 * @flags: (out): return location for the region flags
1072 * Returns %TRUE if the widget at position @pos has the class @name
1073 * defined, %FALSE otherwise.
1075 * Returns: %TRUE if the class @name is defined for the widget at @pos
1080 gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
1083 GtkRegionFlags *flags)
1087 g_return_val_if_fail (path != NULL, FALSE);
1088 g_return_val_if_fail (path->elems->len != 0, FALSE);
1089 g_return_val_if_fail (name != NULL, FALSE);
1091 if (pos < 0 || pos >= path->elems->len)
1092 pos = path->elems->len - 1;
1094 qname = g_quark_try_string (name);
1099 return gtk_widget_path_iter_has_qregion (path, pos, qname, flags);
1103 * gtk_widget_path_get_object_type:
1104 * @path: a #GtkWidget
1106 * Returns the topmost object type, that is, the object type this path
1109 * Returns: The object type
1114 gtk_widget_path_get_object_type (const GtkWidgetPath *path)
1116 GtkPathElement *elem;
1118 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
1120 elem = &g_array_index (path->elems, GtkPathElement,
1121 path->elems->len - 1);
1126 * gtk_widget_path_is_type:
1127 * @path: a #GtkWidgetPath
1128 * @type: widget type to match
1130 * Returns %TRUE if the widget type represented by this path
1131 * is @type, or a subtype of it.
1133 * Returns: %TRUE if the widget represented by @path is of type @type
1138 gtk_widget_path_is_type (const GtkWidgetPath *path,
1141 GtkPathElement *elem;
1143 g_return_val_if_fail (path != NULL, FALSE);
1145 elem = &g_array_index (path->elems, GtkPathElement,
1146 path->elems->len - 1);
1148 if (elem->type == type ||
1149 g_type_is_a (elem->type, type))
1156 * gtk_widget_path_has_parent:
1157 * @path: a #GtkWidgetPath
1158 * @type: widget type to check in parents
1160 * Returns %TRUE if any of the parents of the widget represented
1161 * in @path is of type @type, or any subtype of it.
1163 * Returns: %TRUE if any parent is of type @type
1168 gtk_widget_path_has_parent (const GtkWidgetPath *path,
1173 g_return_val_if_fail (path != NULL, FALSE);
1175 for (i = 0; i < path->elems->len - 1; i++)
1177 GtkPathElement *elem;
1179 elem = &g_array_index (path->elems, GtkPathElement, i);
1181 if (elem->type == type ||
1182 g_type_is_a (elem->type, type))