From 1164ceb4fcff7732aa94a69ab932f235c33a9760 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 24 Jun 2011 20:26:42 -0400 Subject: [PATCH] GtkStyleContext: add some aux. a11y api This function translates the fg/bg color into atk attributes. --- gtk/gtkstylecontext.c | 55 +++++++++++++++++++++++++++++++++++++++++++ gtk/gtkstylecontext.h | 6 +++++ 2 files changed, 61 insertions(+) diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index 93a3defb2f..d63d35bac4 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -4313,3 +4313,58 @@ gtk_render_icon (GtkStyleContext *context, cairo_restore (cr); } + +static AtkAttributeSet * +add_attribute (AtkAttributeSet *attributes, + AtkTextAttribute attr, + const gchar *value) +{ + AtkAttribute *at; + + at = g_new (AtkAttribute, 1); + at->name = g_strdup (atk_text_attribute_get_name (attr)); + at->value = g_strdup (value); + + return g_slist_prepend (attributes, at); +} + +/* + * _gtk_style_context_get_attributes: + * @attributes: a #AtkAttributeSet to add attributes to + * @context: the #GtkStyleContext to get attributes from + * @flags: the state to use with @context + * + * Adds the foreground and background color from @context to + * @attributes, after translating them to ATK attributes. + * + * This is a convenience function that can be used in + * implementing the #AtkText interface in widgets. + * + * Returns: the modified #AtkAttributeSet + */ +AtkAttributeSet * +_gtk_style_context_get_attributes (AtkAttributeSet *attributes, + GtkStyleContext *context, + GtkStateFlags flags) +{ + GdkRGBA color; + gchar *value; + + gtk_style_context_get_background_color (context, flags, &color); + value = g_strdup_printf ("%u,%u,%u", + (guint) ceil (color.red * 65536 - color.red), + (guint) ceil (color.green * 65536 - color.green), + (guint) ceil (color.blue * 65536 - color.blue)); + attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value); + g_free (value); + + gtk_style_context_get_color (context, flags, &color); + value = g_strdup_printf ("%u,%u,%u", + (guint) ceil (color.red * 65536 - color.red), + (guint) ceil (color.green * 65536 - color.green), + (guint) ceil (color.blue * 65536 - color.blue)); + attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value); + g_free (value); + + return attributes; +} diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h index 661edd0f76..dd1339508c 100644 --- a/gtk/gtkstylecontext.h +++ b/gtk/gtkstylecontext.h @@ -28,6 +28,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -858,6 +859,11 @@ void gtk_render_icon (GtkStyleContext *context, gdouble x, gdouble y); +/* Accessibility support */ +AtkAttributeSet *_gtk_style_context_get_attributes (AtkAttributeSet *attributes, + GtkStyleContext *context, + GtkStateFlags flags); + G_END_DECLS #endif /* __GTK_STYLE_CONTEXT_H__ */