GtkStyleContext: add some aux. a11y api

This function translates the fg/bg color into atk attributes.
This commit is contained in:
Matthias Clasen 2011-06-24 20:26:42 -04:00
parent 1f2b8a6545
commit 1164ceb4fc
2 changed files with 61 additions and 0 deletions

View File

@ -4313,3 +4313,58 @@ gtk_render_icon (GtkStyleContext *context,
cairo_restore (cr); 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;
}

View File

@ -28,6 +28,7 @@
#include <gtk/gtkstyleprovider.h> #include <gtk/gtkstyleprovider.h>
#include <gtk/gtkwidgetpath.h> #include <gtk/gtkwidgetpath.h>
#include <gtk/gtkborder.h> #include <gtk/gtkborder.h>
#include <atk/atk.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -858,6 +859,11 @@ void gtk_render_icon (GtkStyleContext *context,
gdouble x, gdouble x,
gdouble y); gdouble y);
/* Accessibility support */
AtkAttributeSet *_gtk_style_context_get_attributes (AtkAttributeSet *attributes,
GtkStyleContext *context,
GtkStateFlags flags);
G_END_DECLS G_END_DECLS
#endif /* __GTK_STYLE_CONTEXT_H__ */ #endif /* __GTK_STYLE_CONTEXT_H__ */