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"
25 static void atk_image_interface_init (AtkImageIface *iface);
27 G_DEFINE_TYPE_WITH_CODE (GtkImageAccessible, _gtk_image_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
28 G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
31 gtk_image_accessible_initialize (AtkObject *accessible,
34 ATK_OBJECT_CLASS (_gtk_image_accessible_parent_class)->initialize (accessible, data);
36 accessible->role = ATK_ROLE_ICON;
40 gtk_image_accessible_finalize (GObject *object)
42 GtkImageAccessible *aimage = GTK_IMAGE_ACCESSIBLE (object);
44 g_free (aimage->image_description);
45 g_free (aimage->stock_name);
47 G_OBJECT_CLASS (_gtk_image_accessible_parent_class)->finalize (object);
51 gtk_image_accessible_get_name (AtkObject *accessible)
55 GtkImageAccessible *image_accessible;
56 GtkStockItem stock_item;
60 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
64 name = ATK_OBJECT_CLASS (_gtk_image_accessible_parent_class)->get_name (accessible);
68 image = GTK_IMAGE (widget);
69 image_accessible = GTK_IMAGE_ACCESSIBLE (accessible);
71 g_free (image_accessible->stock_name);
72 image_accessible->stock_name = NULL;
74 if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK)
77 gtk_image_get_stock (image, &stock_id, NULL);
81 if (!gtk_stock_lookup (stock_id, &stock_item))
84 image_accessible->stock_name = _gtk_toolbar_elide_underscores (stock_item.label);
85 return image_accessible->stock_name;
89 _gtk_image_accessible_class_init (GtkImageAccessibleClass *klass)
91 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
92 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
94 gobject_class->finalize = gtk_image_accessible_finalize;
95 class->initialize = gtk_image_accessible_initialize;
96 class->get_name = gtk_image_accessible_get_name;
100 _gtk_image_accessible_init (GtkImageAccessible *image)
105 gtk_image_accessible_get_image_description (AtkImage *image)
107 GtkImageAccessible *accessible = GTK_IMAGE_ACCESSIBLE (image);
109 return accessible->image_description;
113 gtk_image_accessible_get_image_position (AtkImage *image,
116 AtkCoordType coord_type)
118 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
122 gtk_image_accessible_get_image_size (AtkImage *image,
128 GtkImageType image_type;
130 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
138 gtk_image = GTK_IMAGE (widget);
140 image_type = gtk_image_get_storage_type (gtk_image);
143 case GTK_IMAGE_PIXBUF:
147 pixbuf = gtk_image_get_pixbuf (gtk_image);
148 *height = gdk_pixbuf_get_height (pixbuf);
149 *width = gdk_pixbuf_get_width (pixbuf);
152 case GTK_IMAGE_STOCK:
153 case GTK_IMAGE_ICON_SET:
154 case GTK_IMAGE_ICON_NAME:
155 case GTK_IMAGE_GICON:
158 GtkSettings *settings;
160 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
162 g_object_get (gtk_image, "icon-size", &size, NULL);
163 gtk_icon_size_lookup_for_settings (settings, size, width, height);
166 case GTK_IMAGE_ANIMATION:
168 GdkPixbufAnimation *animation;
170 animation = gtk_image_get_animation (gtk_image);
171 *height = gdk_pixbuf_animation_get_height (animation);
172 *width = gdk_pixbuf_animation_get_width (animation);
185 gtk_image_accessible_set_image_description (AtkImage *image,
186 const gchar *description)
188 GtkImageAccessible* accessible = GTK_IMAGE_ACCESSIBLE (image);
190 g_free (accessible->image_description);
191 accessible->image_description = g_strdup (description);
197 atk_image_interface_init (AtkImageIface *iface)
199 iface->get_image_description = gtk_image_accessible_get_image_description;
200 iface->get_image_position = gtk_image_accessible_get_image_position;
201 iface->get_image_size = gtk_image_accessible_get_image_size;
202 iface->set_image_description = gtk_image_accessible_set_image_description;