1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 #include "gtkimageaccessible.h"
24 struct _GtkImageAccessiblePrivate
26 gchar *image_description;
30 static void atk_image_interface_init (AtkImageIface *iface);
32 G_DEFINE_TYPE_WITH_CODE (GtkImageAccessible, _gtk_image_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
33 G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
36 gtk_image_accessible_initialize (AtkObject *accessible,
39 ATK_OBJECT_CLASS (_gtk_image_accessible_parent_class)->initialize (accessible, data);
41 accessible->role = ATK_ROLE_ICON;
45 gtk_image_accessible_finalize (GObject *object)
47 GtkImageAccessible *aimage = GTK_IMAGE_ACCESSIBLE (object);
49 g_free (aimage->priv->image_description);
50 g_free (aimage->priv->stock_name);
52 G_OBJECT_CLASS (_gtk_image_accessible_parent_class)->finalize (object);
56 gtk_image_accessible_get_name (AtkObject *accessible)
60 GtkImageAccessible *image_accessible;
61 GtkStockItem stock_item;
65 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
69 name = ATK_OBJECT_CLASS (_gtk_image_accessible_parent_class)->get_name (accessible);
73 image = GTK_IMAGE (widget);
74 image_accessible = GTK_IMAGE_ACCESSIBLE (accessible);
76 g_free (image_accessible->priv->stock_name);
77 image_accessible->priv->stock_name = NULL;
79 if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK)
82 gtk_image_get_stock (image, &stock_id, NULL);
86 if (!gtk_stock_lookup (stock_id, &stock_item))
89 image_accessible->priv->stock_name = _gtk_toolbar_elide_underscores (stock_item.label);
90 return image_accessible->priv->stock_name;
94 _gtk_image_accessible_class_init (GtkImageAccessibleClass *klass)
96 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
97 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
99 gobject_class->finalize = gtk_image_accessible_finalize;
100 class->initialize = gtk_image_accessible_initialize;
101 class->get_name = gtk_image_accessible_get_name;
105 _gtk_image_accessible_init (GtkImageAccessible *image)
107 image->priv = G_TYPE_INSTANCE_GET_PRIVATE (image,
108 GTK_TYPE_IMAGE_ACCESSIBLE,
109 GtkImageAccessiblePrivate);
113 gtk_image_accessible_get_image_description (AtkImage *image)
115 GtkImageAccessible *accessible = GTK_IMAGE_ACCESSIBLE (image);
117 return accessible->priv->image_description;
121 gtk_image_accessible_get_image_position (AtkImage *image,
124 AtkCoordType coord_type)
126 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
130 gtk_image_accessible_get_image_size (AtkImage *image,
136 GtkImageType image_type;
138 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
146 gtk_image = GTK_IMAGE (widget);
148 image_type = gtk_image_get_storage_type (gtk_image);
151 case GTK_IMAGE_PIXBUF:
155 pixbuf = gtk_image_get_pixbuf (gtk_image);
156 *height = gdk_pixbuf_get_height (pixbuf);
157 *width = gdk_pixbuf_get_width (pixbuf);
160 case GTK_IMAGE_STOCK:
161 case GTK_IMAGE_ICON_SET:
162 case GTK_IMAGE_ICON_NAME:
163 case GTK_IMAGE_GICON:
166 GtkSettings *settings;
168 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
170 g_object_get (gtk_image, "icon-size", &size, NULL);
171 gtk_icon_size_lookup_for_settings (settings, size, width, height);
174 case GTK_IMAGE_ANIMATION:
176 GdkPixbufAnimation *animation;
178 animation = gtk_image_get_animation (gtk_image);
179 *height = gdk_pixbuf_animation_get_height (animation);
180 *width = gdk_pixbuf_animation_get_width (animation);
193 gtk_image_accessible_set_image_description (AtkImage *image,
194 const gchar *description)
196 GtkImageAccessible* accessible = GTK_IMAGE_ACCESSIBLE (image);
198 g_free (accessible->priv->image_description);
199 accessible->priv->image_description = g_strdup (description);
205 atk_image_interface_init (AtkImageIface *iface)
207 iface->get_image_description = gtk_image_accessible_get_image_description;
208 iface->get_image_position = gtk_image_accessible_get_image_position;
209 iface->get_image_size = gtk_image_accessible_get_image_size;
210 iface->set_image_description = gtk_image_accessible_set_image_description;