GtkWidgetPath: Add methods to include class info in paths.

This commit is contained in:
Carlos Garnacho 2010-08-06 11:59:35 +02:00
parent a3637ec60d
commit 8a1b6e8224
2 changed files with 198 additions and 1 deletions

View File

@ -31,6 +31,7 @@ struct GtkPathElement
GType type; GType type;
GQuark name; GQuark name;
GHashTable *regions; GHashTable *regions;
GArray *classes;
}; };
struct GtkWidgetPath struct GtkWidgetPath
@ -222,6 +223,185 @@ gtk_widget_path_iter_has_name (const GtkWidgetPath *path,
return gtk_widget_path_iter_has_qname (path, pos, qname); return gtk_widget_path_iter_has_qname (path, pos, qname);
} }
void
gtk_widget_path_iter_add_class (GtkWidgetPath *path,
guint pos,
const gchar *name)
{
GtkPathElement *elem;
gboolean added = FALSE;
GQuark qname;
guint i;
g_return_if_fail (path != NULL);
g_return_if_fail (pos < path->elems->len);
g_return_if_fail (name != NULL);
elem = &g_array_index (path->elems, GtkPathElement, pos);
qname = g_quark_from_string (name);
if (!elem->classes)
elem->classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
for (i = 0; i < elem->classes->len; i++)
{
GQuark quark;
quark = g_array_index (elem->classes, GQuark, i);
if (qname == quark)
{
/* Already there */
added = TRUE;
break;
}
if (qname < quark)
{
g_array_insert_val (elem->classes, i, qname);
added = TRUE;
break;
}
}
if (!added)
g_array_append_val (elem->classes, qname);
}
void
gtk_widget_path_iter_remove_class (GtkWidgetPath *path,
guint pos,
const gchar *name)
{
GtkPathElement *elem;
GQuark qname;
guint i;
g_return_if_fail (path != NULL);
g_return_if_fail (pos < path->elems->len);
g_return_if_fail (name != NULL);
qname = g_quark_try_string (name);
if (qname == 0)
return;
elem = &g_array_index (path->elems, GtkPathElement, pos);
if (!elem->classes)
return;
for (i = 0; i < elem->classes->len; i++)
{
GQuark quark;
quark = g_array_index (elem->classes, GQuark, i);
if (quark > qname)
break;
else if (quark == qname)
{
g_array_remove_index (elem->classes, i);
break;
}
}
}
void
gtk_widget_path_iter_clear_classes (GtkWidgetPath *path,
guint pos)
{
GtkPathElement *elem;
g_return_if_fail (path != NULL);
g_return_if_fail (pos < path->elems->len);
elem = &g_array_index (path->elems, GtkPathElement, pos);
if (!elem->classes)
return;
if (elem->classes->len > 0)
g_array_remove_range (elem->classes, 0, elem->classes->len);
}
GSList *
gtk_widget_path_iter_list_classes (const GtkWidgetPath *path,
guint pos)
{
GtkPathElement *elem;
GSList *list = NULL;
guint i;
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (pos < path->elems->len, NULL);
elem = &g_array_index (path->elems, GtkPathElement, pos);
if (!elem->classes)
return NULL;
for (i = 0; i < elem->classes->len; i++)
{
GQuark quark;
quark = g_array_index (elem->classes, GQuark, i);
list = g_slist_prepend (list, (gchar *) g_quark_to_string (quark));
}
return g_slist_reverse (list);
}
gboolean
gtk_widget_path_iter_has_qclass (const GtkWidgetPath *path,
guint pos,
GQuark qname)
{
GtkPathElement *elem;
guint i;
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (pos < path->elems->len, FALSE);
g_return_val_if_fail (qname != 0, FALSE);
elem = &g_array_index (path->elems, GtkPathElement, pos);
if (!elem->classes)
return FALSE;
for (i = 0; i < elem->classes->len; i++)
{
GQuark quark;
quark = g_array_index (elem->classes, GQuark, i);
if (quark == qname)
return TRUE;
else if (quark > qname)
break;
}
return FALSE;
}
gboolean
gtk_widget_path_iter_has_class (const GtkWidgetPath *path,
guint pos,
const gchar *name)
{
GQuark qname;
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (pos < path->elems->len, FALSE);
g_return_val_if_fail (name != NULL, FALSE);
qname = g_quark_try_string (name);
if (qname == 0)
return FALSE;
return gtk_widget_path_iter_has_qclass (path, pos, qname);
}
void void
gtk_widget_path_iter_add_region (GtkWidgetPath *path, gtk_widget_path_iter_add_region (GtkWidgetPath *path,
guint pos, guint pos,

View File

@ -56,6 +56,23 @@ gboolean gtk_widget_path_iter_has_qname (const GtkWidgetPath *path
guint pos, guint pos,
GQuark qname); GQuark qname);
void gtk_widget_path_iter_add_class (GtkWidgetPath *path,
guint pos,
const gchar *name);
void gtk_widget_path_iter_remove_class (GtkWidgetPath *path,
guint pos,
const gchar *name);
void gtk_widget_path_iter_clear_classes (GtkWidgetPath *path,
guint pos);
GSList * gtk_widget_path_iter_list_classes (const GtkWidgetPath *path,
guint pos);
gboolean gtk_widget_path_iter_has_class (const GtkWidgetPath *path,
guint pos,
const gchar *name);
gboolean gtk_widget_path_iter_has_qclass (const GtkWidgetPath *path,
guint pos,
GQuark qname);
void gtk_widget_path_iter_add_region (GtkWidgetPath *path, void gtk_widget_path_iter_add_region (GtkWidgetPath *path,
guint pos, guint pos,
const gchar *name, const gchar *name,
@ -66,7 +83,7 @@ void gtk_widget_path_iter_remove_region (GtkWidgetPath *path,
void gtk_widget_path_iter_clear_regions (GtkWidgetPath *path, void gtk_widget_path_iter_clear_regions (GtkWidgetPath *path,
guint pos); guint pos);
GSList * gtk_widget_path_iter_list_regions (cosnt GtkWidgetPath *path, GSList * gtk_widget_path_iter_list_regions (const GtkWidgetPath *path,
guint pos); guint pos);
gboolean gtk_widget_path_iter_has_region (const GtkWidgetPath *path, gboolean gtk_widget_path_iter_has_region (const GtkWidgetPath *path,