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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include "gtkimageaccessible.h"
27 static void atk_image_interface_init (AtkImageIface *iface);
29 G_DEFINE_TYPE_WITH_CODE (GtkImageAccessible, _gtk_image_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
30 G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
33 gtk_image_accessible_initialize (AtkObject *accessible,
36 ATK_OBJECT_CLASS (_gtk_image_accessible_parent_class)->initialize (accessible, data);
38 accessible->role = ATK_ROLE_ICON;
42 gtk_image_accessible_finalize (GObject *object)
44 GtkImageAccessible *aimage = GTK_IMAGE_ACCESSIBLE (object);
46 g_free (aimage->image_description);
47 g_free (aimage->stock_name);
49 G_OBJECT_CLASS (_gtk_image_accessible_parent_class)->finalize (object);
53 gtk_image_accessible_get_name (AtkObject *accessible)
57 GtkImageAccessible *image_accessible;
58 GtkStockItem stock_item;
62 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
66 name = ATK_OBJECT_CLASS (_gtk_image_accessible_parent_class)->get_name (accessible);
70 image = GTK_IMAGE (widget);
71 image_accessible = GTK_IMAGE_ACCESSIBLE (accessible);
73 g_free (image_accessible->stock_name);
74 image_accessible->stock_name = NULL;
76 if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK)
79 gtk_image_get_stock (image, &stock_id, NULL);
83 if (!gtk_stock_lookup (stock_id, &stock_item))
86 image_accessible->stock_name = _gtk_toolbar_elide_underscores (stock_item.label);
87 return image_accessible->stock_name;
91 _gtk_image_accessible_class_init (GtkImageAccessibleClass *klass)
93 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
94 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
96 gobject_class->finalize = gtk_image_accessible_finalize;
97 class->initialize = gtk_image_accessible_initialize;
98 class->get_name = gtk_image_accessible_get_name;
102 _gtk_image_accessible_init (GtkImageAccessible *image)
107 gtk_image_accessible_get_image_description (AtkImage *image)
109 GtkImageAccessible *accessible = GTK_IMAGE_ACCESSIBLE (image);
111 return accessible->image_description;
115 gtk_image_accessible_get_image_position (AtkImage *image,
118 AtkCoordType coord_type)
120 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
124 gtk_image_accessible_get_image_size (AtkImage *image,
130 GtkImageType image_type;
132 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
140 gtk_image = GTK_IMAGE (widget);
142 image_type = gtk_image_get_storage_type (gtk_image);
145 case GTK_IMAGE_PIXBUF:
149 pixbuf = gtk_image_get_pixbuf (gtk_image);
150 *height = gdk_pixbuf_get_height (pixbuf);
151 *width = gdk_pixbuf_get_width (pixbuf);
154 case GTK_IMAGE_STOCK:
155 case GTK_IMAGE_ICON_SET:
156 case GTK_IMAGE_ICON_NAME:
157 case GTK_IMAGE_GICON:
160 GtkSettings *settings;
162 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
164 g_object_get (gtk_image, "icon-size", &size, NULL);
165 gtk_icon_size_lookup_for_settings (settings, size, width, height);
168 case GTK_IMAGE_ANIMATION:
170 GdkPixbufAnimation *animation;
172 animation = gtk_image_get_animation (gtk_image);
173 *height = gdk_pixbuf_animation_get_height (animation);
174 *width = gdk_pixbuf_animation_get_width (animation);
187 gtk_image_accessible_set_image_description (AtkImage *image,
188 const gchar *description)
190 GtkImageAccessible* accessible = GTK_IMAGE_ACCESSIBLE (image);
192 g_free (accessible->image_description);
193 accessible->image_description = g_strdup (description);
199 atk_image_interface_init (AtkImageIface *iface)
201 iface->get_image_description = gtk_image_accessible_get_image_description;
202 iface->get_image_position = gtk_image_accessible_get_image_position;
203 iface->get_image_size = gtk_image_accessible_get_image_size;
204 iface->set_image_description = gtk_image_accessible_set_image_description;