[gtk+/a11y] GtkStyleContext: add some aux. a11y api



commit 1701f7c000928ce74e10ad4064d684f013ddd971
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 24 20:26:42 2011 -0400

    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(+), 0 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 9ac9b47..a50ea22 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -4427,3 +4427,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 4e3d4d5..f73d18f 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -28,6 +28,7 @@
 #include <gtk/gtkstyleprovider.h>
 #include <gtk/gtkwidgetpath.h>
 #include <gtk/gtkborder.h>
+#include <atk/atk.h>
 
 G_BEGIN_DECLS
 
@@ -758,6 +759,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__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]