[gtk+/drop-gail: 8/24] Move GailImage to GtkImageAccessible



commit f34c5294216f31977ec2bf1a4714a546424f1e6b
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Feb 21 03:02:57 2011 -0500

    Move GailImage to GtkImageAccessible

 gtk/Makefile.am           |    1 +
 gtk/gtkimage.c            |  199 +++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkimageaccessible.h  |   58 +++++++++++++
 modules/other/gail/gail.c |    5 +-
 4 files changed, 262 insertions(+), 1 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 81e7915..2a7918f 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -400,6 +400,7 @@ gtk_private_h_sources =		\
 	gtkfilesystem.h		\
 	gtkfilesystemmodel.h	\
 	gtkiconcache.h		\
+	gtkimageaccessible.h	\
 	gtkimageprivate.h	\
 	gtkimcontextsimpleseqs.h \
 	gtkintl.h		\
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index c6ba294..271bc02 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -38,6 +38,7 @@
 #include "gtkintl.h"
 #include "gtkprivate.h"
 #include "gtktypebuiltins.h"
+#include "gtktoolbar.h"
 
 /**
  * SECTION:gtkimage
@@ -2123,3 +2124,201 @@ gtk_image_get_pixel_size (GtkImage *image)
 
   return image->priv->pixel_size;
 }
+
+
+/* --- Accessibility --- */
+
+#include "gtkaccessibility.h"
+#include "gtkimageaccessible.h"
+
+static void atk_image_interface_init (AtkImageIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkImageAccessible, gtk_image_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
+
+static void
+gtk_image_accessible_initialize (AtkObject *accessible,
+                                 gpointer   data)
+{
+  ATK_OBJECT_CLASS (gtk_image_accessible_parent_class)->initialize (accessible, data);
+
+  atk_object_set_role (accessible, ATK_ROLE_ICON);
+}
+
+
+static void
+gtk_image_accessible_finalize (GObject *object)
+{
+  GtkImageAccessible *accessible = GTK_IMAGE_ACCESSIBLE (object);
+
+  g_free (accessible->image_description);
+  g_free (accessible->stock_name);
+
+  G_OBJECT_CLASS (gtk_image_accessible_parent_class)->finalize (object);
+}
+
+static const gchar*
+gtk_image_accessible_get_name (AtkObject *accessible)
+{
+  GtkWidget* widget;
+  GtkImage *image;
+  GtkImageAccessible *image_accessible;
+  GtkStockItem stock_item;
+  gchar *stock_id;
+  const gchar *name;
+
+  name = ATK_OBJECT_CLASS (gtk_image_accessible_parent_class)->get_name (accessible);
+  if (name)
+    return name;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+  if (widget == NULL)
+    return NULL;
+
+  image = GTK_IMAGE (widget);
+  image_accessible = GTK_IMAGE_ACCESSIBLE (accessible);
+
+  g_free (image_accessible->stock_name);
+  image_accessible->stock_name = NULL;
+
+  if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK)
+    return NULL;
+
+  gtk_image_get_stock (image, &stock_id, NULL);
+  if (stock_id == NULL)
+    return NULL;
+
+  if (!gtk_stock_lookup (stock_id, &stock_item))
+    return NULL;
+
+  image_accessible->stock_name = _gtk_toolbar_elide_underscores (stock_item.label);
+  return image_accessible->stock_name;
+}
+
+
+static void
+gtk_image_accessible_class_init (GtkImageAccessibleClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  AtkObjectClass *atkobject_class = ATK_OBJECT_CLASS (klass);
+
+  gobject_class->finalize = gtk_image_accessible_finalize;
+
+  atkobject_class->initialize = gtk_image_accessible_initialize;
+  atkobject_class->get_name = gtk_image_accessible_get_name;
+}
+
+static void
+gtk_image_accessible_init (GtkImageAccessible *image)
+{
+}
+
+static const gchar *
+gtk_image_accessible_get_image_description (AtkImage *image)
+{
+  GtkImageAccessible *accessible = GTK_IMAGE_ACCESSIBLE (image);
+
+  return accessible->image_description;
+}
+
+static gboolean
+gtk_image_accessible_set_image_description (AtkImage    *image,
+                                            const gchar *description)
+{
+  GtkImageAccessible *accessible = GTK_IMAGE_ACCESSIBLE (image);
+
+  g_free (accessible->image_description);
+  accessible->image_description = g_strdup (description);
+
+  return TRUE;
+}
+
+static void
+gtk_image_accessible_get_image_size (AtkImage *image,
+                                     gint     *width,
+                                     gint     *height)
+{
+  GtkWidget* widget;
+  GtkImage *gtk_image;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
+  if (!widget)
+    {
+      *height = -1;
+      *width = -1;
+       return;
+    }
+
+  gtk_image = GTK_IMAGE (widget);
+
+  switch (gtk_image_get_storage_type (gtk_image))
+    {
+    case GTK_IMAGE_PIXBUF:
+      {
+        GdkPixbuf *pixbuf;
+        pixbuf = gtk_image_get_pixbuf (gtk_image);
+        *height = gdk_pixbuf_get_height (pixbuf);
+        *width = gdk_pixbuf_get_width (pixbuf);
+        break;
+      }
+    case GTK_IMAGE_STOCK:
+    case GTK_IMAGE_ICON_SET:
+    case GTK_IMAGE_ICON_NAME:
+    case GTK_IMAGE_GICON:
+      {
+        GtkIconSize size;
+        GtkSettings *settings;
+
+        settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
+
+        g_object_get (gtk_image, "icon-size", &size, NULL);
+        gtk_icon_size_lookup_for_settings (settings, size, width, height);
+        break;
+      }
+    case GTK_IMAGE_ANIMATION:
+      {
+        GdkPixbufAnimation *animation;
+        animation = gtk_image_get_animation (gtk_image);
+        *height = gdk_pixbuf_animation_get_height (animation);
+        *width = gdk_pixbuf_animation_get_width (animation);
+        break;
+      }
+    default:
+      {
+        *height = -1;
+        *width = -1;
+        break;
+      }
+    }
+}
+
+static void
+gtk_image_accessible_get_image_position (AtkImage     *image,
+                                         gint         *x,
+                                         gint         *y,
+                                         AtkCoordType  coord_type)
+{
+  atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
+}
+
+static void
+atk_image_interface_init (AtkImageIface *iface)
+{
+  iface->get_image_description = gtk_image_accessible_get_image_description;
+  iface->set_image_description = gtk_image_accessible_set_image_description;
+  iface->get_image_size = gtk_image_accessible_get_image_size;
+  iface->get_image_position = gtk_image_accessible_get_image_position;
+}
+
+static AtkObject *
+gtk_image_accessible_new (GtkWidget *widget)
+{
+  AtkObject *accessible;
+
+  accessible = g_object_new (GTK_TYPE_IMAGE_ACCESSIBLE, NULL);
+  atk_object_initialize (accessible, widget);
+
+  return accessible;
+}
+
+GTK_ACCESSIBLE_FACTORY(GTK_TYPE_IMAGE_ACCESSIBLE, gtk_image_accessible, gtk_image_accessible_new)
diff --git a/gtk/gtkimageaccessible.h b/gtk/gtkimageaccessible.h
new file mode 100644
index 0000000..9b28b14
--- /dev/null
+++ b/gtk/gtkimageaccessible.h
@@ -0,0 +1,58 @@
+/* GTK - The GIMP Toolkit
+ * Copyright 2011 Red Hat, Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_IMAGE_ACCESSIBLE_H__
+#define __GTK_IMAGE_ACCESSIBLE_H__
+
+#include <gtk/gtkwidgetaccessible.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_IMAGE_ACCESSIBLE (gtk_image_accessible_get_type ())
+#define GTK_IMAGE_ACCESSIBLE(obj)(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_IMAGE_ACCESSIBLE, GtkImageAccessible))
+#define GTK_IMAGE_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_IMAGE_ACCESSIBLE, GtkImageAccessibleClass))
+
+typedef struct _GtkImageAccessible GtkImageAccessible;
+typedef struct _GtkImageAccessibleClass GtkImageAccessibleClass;
+
+struct _GtkImageAccessible
+{
+  GtkWidgetAccessible parent;
+
+  gchar *image_description;
+  gchar *stock_name;
+};
+
+struct _GtkImageAccessibleClass
+{
+  GtkWidgetAccessibleClass parent_class;
+};
+
+
+GType gtk_image_accessible_get_type (void) G_GNUC_CONST;
+GType gtk_image_accessible_factory_get_type (void) G_GNUC_CONST;
+
+
+G_END_DECLS
+
+#endif  /* __GTK_IMAGE_ACCESSIBLE_H__ */
diff --git a/modules/other/gail/gail.c b/modules/other/gail/gail.c
index 49e40a6..efef87e 100644
--- a/modules/other/gail/gail.c
+++ b/modules/other/gail/gail.c
@@ -861,6 +861,7 @@ extern void gnome_accessibility_module_shutdown (void);
  */
 extern GType gtk_widget_accessible_factory_get_type (void);
 extern GType gtk_container_accessible_factory_get_type (void);
+extern GType gtk_image_accessible_factory_get_type (void);
 
 static int gail_initialized = FALSE;
 
@@ -890,11 +891,13 @@ gail_accessibility_module_init (void)
   atk_registry_set_factory_type (atk_get_default_registry (),
                                  GTK_TYPE_CONTAINER,
                                  gtk_container_accessible_factory_get_type ());
+  atk_registry_set_factory_type (atk_get_default_registry (),
+                                 GTK_TYPE_IMAGE,
+                                 gtk_image_accessible_factory_get_type ());
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_BUTTON, gail_button);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_LINK_BUTTON, gail_link_button);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU_ITEM, gail_menu_item);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_TOGGLE_BUTTON, gail_toggle_button);
-  GAIL_WIDGET_SET_FACTORY (GTK_TYPE_IMAGE, gail_image);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_TEXT_VIEW, gail_text_view);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_COMBO_BOX, gail_combo_box);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_ENTRY, gail_entry);



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