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 (NULL, NULL);
79 while (g_hash_table_iter_next (&iter, &key, &value))
80 g_hash_table_insert (new.regions, key, value);
83 g_array_append_val (new_path->elems, new);
90 gtk_widget_path_free (GtkWidgetPath *path)
94 g_return_if_fail (path != NULL);
96 for (i = 0; i < path->elems->len; i++)
100 elem = &g_array_index (path->elems, GtkPathElement, i);
104 g_hash_table_destroy (elem->regions);
107 g_array_free (path->elems, TRUE);
108 g_slice_free (GtkWidgetPath, path);
112 gtk_widget_path_length (const GtkWidgetPath *path)
114 g_return_val_if_fail (path != NULL, 0);
116 return path->elems->len;
120 gtk_widget_path_prepend_type (GtkWidgetPath *path,
123 GtkPathElement new = { 0 };
125 g_return_val_if_fail (path != NULL, 0);
126 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), 0);
129 g_array_append_val (path->elems, new);
131 return path->elems->len - 1;
135 gtk_widget_path_iter_get_widget_type (const GtkWidgetPath *path,
138 GtkPathElement *elem;
140 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
141 g_return_val_if_fail (pos < path->elems->len, G_TYPE_INVALID);
143 elem = &g_array_index (path->elems, GtkPathElement, pos);
148 gtk_widget_path_iter_set_widget_type (GtkWidgetPath *path,
152 GtkPathElement *elem;
154 g_return_if_fail (path != NULL);
155 g_return_if_fail (pos < path->elems->len);
156 g_return_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET));
158 elem = &g_array_index (path->elems, GtkPathElement, pos);
162 G_CONST_RETURN gchar *
163 gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
166 GtkPathElement *elem;
168 g_return_val_if_fail (path != NULL, NULL);
169 g_return_val_if_fail (pos < path->elems->len, NULL);
171 elem = &g_array_index (path->elems, GtkPathElement, pos);
176 gtk_widget_path_iter_set_name (GtkWidgetPath *path,
180 GtkPathElement *elem;
182 g_return_if_fail (path != NULL);
183 g_return_if_fail (pos < path->elems->len);
184 g_return_if_fail (name != NULL);
186 elem = &g_array_index (path->elems, GtkPathElement, pos);
191 elem->name = g_strdup (name);
195 gtk_widget_path_iter_add_region (GtkWidgetPath *path,
198 GtkChildClassFlags flags)
200 GtkPathElement *elem;
203 g_return_if_fail (path != NULL);
204 g_return_if_fail (pos < path->elems->len);
205 g_return_if_fail (name != NULL);
207 elem = &g_array_index (path->elems, GtkPathElement, pos);
208 qname = g_quark_from_string (name);
211 elem->regions = g_hash_table_new (NULL, NULL);
213 g_hash_table_insert (elem->regions,
214 GUINT_TO_POINTER (qname),
215 GUINT_TO_POINTER (flags));
219 gtk_widget_path_iter_remove_region (GtkWidgetPath *path,
223 GtkPathElement *elem;
226 g_return_if_fail (path != NULL);
227 g_return_if_fail (pos < path->elems->len);
228 g_return_if_fail (name != NULL);
230 qname = g_quark_try_string (name);
235 elem = &g_array_index (path->elems, GtkPathElement, pos);
238 g_hash_table_remove (elem->regions, GUINT_TO_POINTER (qname));
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))
279 qname = GPOINTER_TO_UINT (key);
280 list = g_slist_prepend (list, (gchar *) g_quark_to_string (qname));
287 gtk_widget_path_iter_has_qregion (const GtkWidgetPath *path,
290 GtkChildClassFlags *flags)
292 GtkPathElement *elem;
295 g_return_val_if_fail (path != NULL, FALSE);
296 g_return_val_if_fail (pos < path->elems->len, FALSE);
297 g_return_val_if_fail (qname != 0, FALSE);
299 elem = &g_array_index (path->elems, GtkPathElement, pos);
304 if (!g_hash_table_lookup_extended (elem->regions,
305 GUINT_TO_POINTER (qname),
310 *flags = GPOINTER_TO_UINT (value);
316 gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
319 GtkChildClassFlags *flags)
323 g_return_val_if_fail (path != NULL, FALSE);
324 g_return_val_if_fail (pos < path->elems->len, FALSE);
325 g_return_val_if_fail (name != NULL, FALSE);
327 qname = g_quark_try_string (name);
332 return gtk_widget_path_iter_has_qregion (path, pos, qname, flags);
336 gtk_widget_path_get_widget_type (const GtkWidgetPath *path)
338 GtkPathElement *elem;
340 g_return_val_if_fail (path != NULL, G_TYPE_INVALID);
342 elem = &g_array_index (path->elems, GtkPathElement, 0);
347 gtk_widget_path_is_type (const GtkWidgetPath *path,
350 GtkPathElement *elem;
352 g_return_val_if_fail (path != NULL, FALSE);
353 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), FALSE);
355 elem = &g_array_index (path->elems, GtkPathElement, 0);
357 if (elem->type == type ||
358 g_type_is_a (elem->type, type))
365 gtk_widget_path_has_parent (const GtkWidgetPath *path,
370 g_return_val_if_fail (path != NULL, FALSE);
371 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), FALSE);
373 for (i = 1; i < path->elems->len; i++)
375 GtkPathElement *elem;
377 elem = &g_array_index (path->elems, GtkPathElement, i);
379 if (elem->type == type ||
380 g_type_is_a (elem->type, type))
387 #define __GTK_WIDGET_PATH_C__
388 #include "gtkaliasdef.c"