1 /* GTK+ - accessibility implementations
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;
103 g_type_class_add_private (klass, sizeof (GtkImageAccessiblePrivate));
107 gtk_image_accessible_init (GtkImageAccessible *image)
109 image->priv = G_TYPE_INSTANCE_GET_PRIVATE (image,
110 GTK_TYPE_IMAGE_ACCESSIBLE,
111 GtkImageAccessiblePrivate);
115 gtk_image_accessible_get_image_description (AtkImage *image)
117 GtkImageAccessible *accessible = GTK_IMAGE_ACCESSIBLE (image);
119 return accessible->priv->image_description;
123 gtk_image_accessible_get_image_position (AtkImage *image,
126 AtkCoordType coord_type)
128 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
132 gtk_image_accessible_get_image_size (AtkImage *image,
138 GtkImageType image_type;
140 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
148 gtk_image = GTK_IMAGE (widget);
150 image_type = gtk_image_get_storage_type (gtk_image);
153 case GTK_IMAGE_PIXBUF:
157 pixbuf = gtk_image_get_pixbuf (gtk_image);
158 *height = gdk_pixbuf_get_height (pixbuf);
159 *width = gdk_pixbuf_get_width (pixbuf);
162 case GTK_IMAGE_STOCK:
163 case GTK_IMAGE_ICON_SET:
164 case GTK_IMAGE_ICON_NAME:
165 case GTK_IMAGE_GICON:
168 GtkSettings *settings;
170 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
172 g_object_get (gtk_image, "icon-size", &size, NULL);
173 gtk_icon_size_lookup_for_settings (settings, size, width, height);
176 case GTK_IMAGE_ANIMATION:
178 GdkPixbufAnimation *animation;
180 animation = gtk_image_get_animation (gtk_image);
181 *height = gdk_pixbuf_animation_get_height (animation);
182 *width = gdk_pixbuf_animation_get_width (animation);
195 gtk_image_accessible_set_image_description (AtkImage *image,
196 const gchar *description)
198 GtkImageAccessible* accessible = GTK_IMAGE_ACCESSIBLE (image);
200 g_free (accessible->priv->image_description);
201 accessible->priv->image_description = g_strdup (description);
207 atk_image_interface_init (AtkImageIface *iface)
209 iface->get_image_description = gtk_image_accessible_get_image_description;
210 iface->get_image_position = gtk_image_accessible_get_image_position;
211 iface->get_image_size = gtk_image_accessible_get_image_size;
212 iface->set_image_description = gtk_image_accessible_set_image_description;