Commit 1d2aa614 authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

GtkStyleContext: Add child style classes.

Child style classes are like style classes, but with additional positional
information. This would be usually set by the parent container.
parent 9a76d1a3
......@@ -30,6 +30,13 @@
typedef struct GtkStyleContextPrivate GtkStyleContextPrivate;
typedef struct GtkStyleProviderData GtkStyleProviderData;
typedef struct GtkChildClass GtkChildClass;
struct GtkChildClass
{
GQuark class_quark;
GtkChildClassFlags flags;
};
struct GtkStyleProviderData
{
......@@ -45,6 +52,7 @@ struct GtkStyleContextPrivate
GtkStateFlags state_flags;
GList *style_classes;
GList *child_style_classes;
GtkThemingEngine *theming_engine;
};
......@@ -444,5 +452,136 @@ gtk_style_context_has_class (GtkStyleContext *context,
return FALSE;
}
static gint
child_style_class_compare (gconstpointer p1,
gconstpointer p2)
{
const GtkChildClass *c1, *c2;
c1 = p1;
c2 = p2;
return (gint) c1->class_quark - c2->class_quark;
}
void
gtk_style_context_set_child_class (GtkStyleContext *context,
const gchar *class_name,
GtkChildClassFlags flags)
{
GtkStyleContextPrivate *priv;
GtkChildClass *child_class;
GQuark class_quark;
GList *link;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (class_name != NULL);
priv = GTK_STYLE_CONTEXT_GET_PRIVATE (context);
class_quark = g_quark_from_string (class_name);
link = priv->style_classes;
while (link)
{
GtkChildClass *link_class;
link_class = link->data;
if (link_class->class_quark == class_quark)
{
link_class->flags = flags;
return;
}
else if (link_class->class_quark > class_quark)
break;
link = link->next;
}
child_class = g_slice_new0 (GtkChildClass);
child_class->class_quark = class_quark;
child_class->flags = flags;
if (link)
priv->style_classes = g_list_insert_before (priv->style_classes,
link, child_class);
else
priv->style_classes = g_list_append (priv->style_classes, child_class);
}
void
gtk_style_context_unset_child_class (GtkStyleContext *context,
const gchar *class_name)
{
GtkStyleContextPrivate *priv;
GtkChildClass child_class;
GQuark class_quark;
GList *link;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (class_name != NULL);
class_quark = g_quark_try_string (class_name);
if (!class_quark)
return;
priv = GTK_STYLE_CONTEXT_GET_PRIVATE (context);
child_class.class_quark = class_quark;
link = g_list_find_custom (priv->child_style_classes,
&child_class, child_style_class_compare);
if (link)
{
priv->child_style_classes = g_list_remove_link (priv->child_style_classes, link);
g_slice_free (GtkChildClass, link->data);
g_list_free1 (link);
}
}
gboolean
gtk_style_context_has_child_class (GtkStyleContext *context,
const gchar *class_name,
GtkChildClassFlags *flags_return)
{
GtkStyleContextPrivate *priv;
GtkChildClass child_class;
GQuark class_quark;
GList *link;
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
g_return_val_if_fail (class_name != NULL, FALSE);
if (flags_return)
*flags_return = 0;
class_quark = g_quark_try_string (class_name);
if (!class_quark)
return FALSE;
priv = GTK_STYLE_CONTEXT_GET_PRIVATE (context);
child_class.class_quark = class_quark;
link = g_list_find_custom (priv->child_style_classes,
&child_class, child_style_class_compare);
if (link)
{
if (*flags_return)
{
GtkChildClass *found_class;
found_class = link->data;
*flags_return = found_class->flags;
}
return TRUE;
}
return FALSE;
}
#define __GTK_STYLE_CONTEXT_C__
#include "gtkaliasdef.c"
......@@ -36,6 +36,15 @@ G_BEGIN_DECLS
typedef struct GtkStyleContext GtkStyleContext;
typedef struct GtkStyleContextClass GtkStyleContextClass;
typedef enum {
GTK_CHILD_CLASS_EVEN = 1 << 0,
GTK_CHILD_CLASS_ODD = 1 << 1,
GTK_CHILD_CLASS_FIRST = 1 << 2,
GTK_CHILD_CLASS_LAST = 1 << 3,
GTK_CHILD_CLASS_DEFAULT = 1 << 4,
GTK_CHILD_CLASS_SORTED = 1 << 5
} GtkChildClassFlags;
struct GtkStyleContext
{
GObject parent_object;
......@@ -84,6 +93,14 @@ void gtk_style_context_unset_class (GtkStyleContext *context,
gboolean gtk_style_context_has_class (GtkStyleContext *context,
const gchar *class_name);
void gtk_style_context_set_child_class (GtkStyleContext *context,
const gchar *class_name,
GtkChildClassFlags flags);
void gtk_style_context_unset_child_class (GtkStyleContext *context,
const gchar *class_name);
gboolean gtk_style_context_has_child_class (GtkStyleContext *context,
const gchar *class_name,
GtkChildClassFlags *flags_return);
G_END_DECLS
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment