]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkimageaccessible.c
a11y: Only care about GtkOrientable::orientation
[~andy/gtk] / gtk / a11y / gtkimageaccessible.c
1 /* GAIL - The GNOME Accessibility Implementation Library
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 #include "config.h"
19
20 #include <string.h>
21 #include <gtk/gtk.h>
22 #include "gtkimageaccessible.h"
23
24
25 static void atk_image_interface_init (AtkImageIface  *iface);
26
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))
29
30 static void
31 gtk_image_accessible_initialize (AtkObject *accessible,
32                                  gpointer   data)
33 {
34   ATK_OBJECT_CLASS (_gtk_image_accessible_parent_class)->initialize (accessible, data);
35
36   accessible->role = ATK_ROLE_ICON;
37 }
38
39 static void
40 gtk_image_accessible_finalize (GObject *object)
41 {
42   GtkImageAccessible *aimage = GTK_IMAGE_ACCESSIBLE (object);
43
44   g_free (aimage->image_description);
45   g_free (aimage->stock_name);
46
47   G_OBJECT_CLASS (_gtk_image_accessible_parent_class)->finalize (object);
48 }
49
50 static const gchar *
51 gtk_image_accessible_get_name (AtkObject *accessible)
52 {
53   GtkWidget* widget;
54   GtkImage *image;
55   GtkImageAccessible *image_accessible;
56   GtkStockItem stock_item;
57   gchar *stock_id;
58   const gchar *name;
59
60   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
61   if (widget == NULL)
62     return NULL;
63
64   name = ATK_OBJECT_CLASS (_gtk_image_accessible_parent_class)->get_name (accessible);
65   if (name)
66     return name;
67
68   image = GTK_IMAGE (widget);
69   image_accessible = GTK_IMAGE_ACCESSIBLE (accessible);
70
71   g_free (image_accessible->stock_name);
72   image_accessible->stock_name = NULL;
73
74   if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK)
75     return NULL;
76
77   gtk_image_get_stock (image, &stock_id, NULL);
78   if (stock_id == NULL)
79     return NULL;
80
81   if (!gtk_stock_lookup (stock_id, &stock_item))
82     return NULL;
83
84   image_accessible->stock_name = _gtk_toolbar_elide_underscores (stock_item.label);
85   return image_accessible->stock_name;
86 }
87
88 static void
89 _gtk_image_accessible_class_init (GtkImageAccessibleClass *klass)
90 {
91   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
92   AtkObjectClass  *class = ATK_OBJECT_CLASS (klass);
93
94   gobject_class->finalize = gtk_image_accessible_finalize;
95   class->initialize = gtk_image_accessible_initialize;
96   class->get_name = gtk_image_accessible_get_name;
97 }
98
99 static void
100 _gtk_image_accessible_init (GtkImageAccessible *image)
101 {
102 }
103
104 static const gchar *
105 gtk_image_accessible_get_image_description (AtkImage *image)
106 {
107   GtkImageAccessible *accessible = GTK_IMAGE_ACCESSIBLE (image);
108
109   return accessible->image_description;
110 }
111
112 static void
113 gtk_image_accessible_get_image_position (AtkImage     *image,
114                                          gint         *x,
115                                          gint         *y,
116                                          AtkCoordType  coord_type)
117 {
118   atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
119 }
120
121 static void
122 gtk_image_accessible_get_image_size (AtkImage *image,
123                                      gint     *width,
124                                      gint     *height)
125 {
126   GtkWidget* widget;
127   GtkImage *gtk_image;
128   GtkImageType image_type;
129
130   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
131   if (widget == NULL)
132     {
133       *height = -1;
134       *width = -1;
135       return;
136     }
137
138   gtk_image = GTK_IMAGE (widget);
139
140   image_type = gtk_image_get_storage_type (gtk_image);
141   switch (image_type)
142     {
143     case GTK_IMAGE_PIXBUF:
144       {
145         GdkPixbuf *pixbuf;
146
147         pixbuf = gtk_image_get_pixbuf (gtk_image);
148         *height = gdk_pixbuf_get_height (pixbuf);
149         *width = gdk_pixbuf_get_width (pixbuf);
150         break;
151       }
152     case GTK_IMAGE_STOCK:
153     case GTK_IMAGE_ICON_SET:
154     case GTK_IMAGE_ICON_NAME:
155     case GTK_IMAGE_GICON:
156       {
157         GtkIconSize size;
158         GtkSettings *settings;
159
160         settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
161
162         g_object_get (gtk_image, "icon-size", &size, NULL);
163         gtk_icon_size_lookup_for_settings (settings, size, width, height);
164         break;
165       }
166     case GTK_IMAGE_ANIMATION:
167       {
168         GdkPixbufAnimation *animation;
169
170         animation = gtk_image_get_animation (gtk_image);
171         *height = gdk_pixbuf_animation_get_height (animation);
172         *width = gdk_pixbuf_animation_get_width (animation);
173         break;
174       }
175     default:
176       {
177         *height = -1;
178         *width = -1;
179         break;
180       }
181     }
182 }
183
184 static gboolean
185 gtk_image_accessible_set_image_description (AtkImage    *image,
186                                             const gchar *description)
187 {
188   GtkImageAccessible* accessible = GTK_IMAGE_ACCESSIBLE (image);
189
190   g_free (accessible->image_description);
191   accessible->image_description = g_strdup (description);
192
193   return TRUE;
194 }
195
196 static void
197 atk_image_interface_init (AtkImageIface *iface)
198 {
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;
203 }