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"
27 typedef struct GtkPathElement GtkPathElement;
38 GArray *elems; /* First element contains the described widget */
42 gtk_widget_path_new (void)
46 path = g_slice_new0 (GtkWidgetPath);
47 path->elems = g_array_new (FALSE, TRUE, sizeof (GtkPathElement));
53 gtk_widget_path_copy (const GtkWidgetPath *path)
55 GtkWidgetPath *new_path;
58 g_return_val_if_fail (path != NULL, NULL);
60 new_path = gtk_widget_path_new ();
62 for (i = 0; i < path->elems->len; i++)
64 GtkPathElement *elem, new = { 0 };
66 elem = &g_array_index (path->elems, GtkPathElement, i);
68 new.type = elem->type;
69 new.name = g_strdup (elem->name);
76 g_hash_table_iter_init (&iter, elem->regions);
77 new.regions = g_hash_table_new_full (g_str_hash,
79 (GDestroyNotify) g_free,
82 while (g_hash_table_iter_next (&iter, &key, &value))
83 g_hash_table_insert (new.regions,
84 g_strdup ((const gchar *) key),
88 g_array_append_val (new_path->elems, new);
95 gtk_widget_path_free (GtkWidgetPath *path)
99 g_return_if_fail (path != NULL);
101 for (i = 0; i < path->elems->len; i++)
103 GtkPathElement *elem;
105 elem = &g_array_index (path->elems, GtkPathElement, i);
109 g_hash_table_destroy (elem->regions);
112 g_array_free (path->elems, TRUE);
113 g_slice_free (GtkWidgetPath, path);
117 gtk_widget_path_length (const GtkWidgetPath *path)
119 g_return_val_if_fail (path != NULL, 0);
121 return path->elems->len;
125 gtk_widget_path_prepend_type (GtkWidgetPath *path,
128 GtkPathElement new = { 0 };
130 g_return_val_if_fail (path != NULL, 0);
131 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), 0);
134 g_array_append_val (path->elems, new);
136 return path->elems->len - 1;
140 gtk_widget_path_get_element_type (const GtkWidgetPath *path,
143 GtkPathElement *elem;
145 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
146 g_return_val_if_fail (pos < path->elems->len, G_TYPE_INVALID);
148 elem = &g_array_index (path->elems, GtkPathElement, pos);
153 gtk_widget_path_set_element_type (GtkWidgetPath *path,
157 GtkPathElement *elem;
159 g_return_if_fail (path != NULL);
160 g_return_if_fail (pos < path->elems->len);
161 g_return_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET));
163 elem = &g_array_index (path->elems, GtkPathElement, pos);
167 G_CONST_RETURN gchar *
168 gtk_widget_path_get_element_name (const GtkWidgetPath *path,
171 GtkPathElement *elem;
173 g_return_val_if_fail (path != NULL, NULL);
174 g_return_val_if_fail (pos < path->elems->len, NULL);
176 elem = &g_array_index (path->elems, GtkPathElement, pos);
181 gtk_widget_path_set_element_name (GtkWidgetPath *path,
185 GtkPathElement *elem;
187 g_return_if_fail (path != NULL);
188 g_return_if_fail (pos < path->elems->len);
189 g_return_if_fail (name != NULL);
191 elem = &g_array_index (path->elems, GtkPathElement, pos);
196 elem->name = g_strdup (name);
200 gtk_widget_path_iter_add_region (GtkWidgetPath *path,
203 GtkChildClassFlags flags)
205 GtkPathElement *elem;
207 g_return_if_fail (path != NULL);
208 g_return_if_fail (pos < path->elems->len);
209 g_return_if_fail (name != NULL);
211 elem = &g_array_index (path->elems, GtkPathElement, pos);
214 elem->regions = g_hash_table_new_full (g_str_hash,
216 (GDestroyNotify) g_free,
219 g_hash_table_insert (elem->regions,
221 GUINT_TO_POINTER (flags));
225 gtk_widget_path_iter_remove_region (GtkWidgetPath *path,
229 GtkPathElement *elem;
231 g_return_if_fail (path != NULL);
232 g_return_if_fail (pos < path->elems->len);
233 g_return_if_fail (name != NULL);
235 elem = &g_array_index (path->elems, GtkPathElement, pos);
238 g_hash_table_remove (elem->regions, name);
242 gtk_widget_path_iter_clear_regions (GtkWidgetPath *path,
245 GtkPathElement *elem;
247 g_return_if_fail (path != NULL);
248 g_return_if_fail (pos < path->elems->len);
250 elem = &g_array_index (path->elems, GtkPathElement, pos);
253 g_hash_table_remove_all (elem->regions);
257 gtk_widget_path_iter_list_regions (const GtkWidgetPath *path,
260 GtkPathElement *elem;
265 g_return_val_if_fail (path != NULL, NULL);
266 g_return_val_if_fail (pos < path->elems->len, NULL);
268 elem = &g_array_index (path->elems, GtkPathElement, pos);
273 g_hash_table_iter_init (&iter, elem->regions);
275 while (g_hash_table_iter_next (&iter, &key, NULL))
276 list = g_slist_prepend (list, key);
282 gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
285 GtkChildClassFlags *flags)
287 GtkPathElement *elem;
290 g_return_val_if_fail (path != NULL, FALSE);
291 g_return_val_if_fail (pos < path->elems->len, FALSE);
292 g_return_val_if_fail (name != NULL, FALSE);
294 elem = &g_array_index (path->elems, GtkPathElement, pos);
299 if (!g_hash_table_lookup_extended (elem->regions, name, NULL, &value))
303 *flags = GPOINTER_TO_UINT (value);
309 gtk_widget_path_get_widget_type (const GtkWidgetPath *path)
311 GtkPathElement *elem;
313 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
315 elem = &g_array_index (path->elems, GtkPathElement, 0);
320 gtk_widget_path_is_type (const GtkWidgetPath *path,
323 GtkPathElement *elem;
325 g_return_val_if_fail (path != NULL, FALSE);
326 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), FALSE);
328 elem = &g_array_index (path->elems, GtkPathElement, 0);
330 if (elem->type == type ||
331 g_type_is_a (elem->type, type))
338 gtk_widget_path_has_parent (const GtkWidgetPath *path,
343 g_return_val_if_fail (path != NULL, FALSE);
344 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), FALSE);
346 for (i = 1; i < path->elems->len; i++)
348 GtkPathElement *elem;
350 elem = &g_array_index (path->elems, GtkPathElement, i);
352 if (elem->type == type ||
353 g_type_is_a (elem->type, type))
360 #define __GTK_WIDGET_PATH_C__
361 #include "gtkaliasdef.c"