]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkimagecellaccessible.c
20105fa83c625568d59a99f2a01c72fa188dcaac
[~andy/gtk] / gtk / a11y / gtkimagecellaccessible.c
1 /* GAIL - The GNOME Accessibility Enabling 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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <gtk/gtk.h>
23 #include "gtkimagecellaccessible.h"
24
25 static void atk_image_interface_init (AtkImageIface *iface);
26
27 G_DEFINE_TYPE_WITH_CODE (GtkImageCellAccessible, _gtk_image_cell_accessible, GTK_TYPE_RENDERER_CELL_ACCESSIBLE,
28                          G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
29
30 static void
31 gtk_image_cell_accessible_finalize (GObject *object)
32 {
33   GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (object);
34
35   g_free (image_cell->image_description);
36   G_OBJECT_CLASS (_gtk_image_cell_accessible_parent_class)->finalize (object);
37 }
38
39 static void
40 _gtk_image_cell_accessible_class_init (GtkImageCellAccessibleClass *klass)
41 {
42   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
43
44   gobject_class->finalize = gtk_image_cell_accessible_finalize;
45 }
46
47 static void
48 _gtk_image_cell_accessible_init (GtkImageCellAccessible *image_cell)
49 {
50   image_cell->image_description = NULL;
51 }
52
53 static const gchar *
54 gtk_image_cell_accessible_get_image_description (AtkImage *image)
55 {
56   GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
57
58   return image_cell->image_description;
59 }
60
61 static gboolean
62 gtk_image_cell_accessible_set_image_description (AtkImage    *image,
63                                                  const gchar *description)
64 {
65   GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
66
67   g_free (image_cell->image_description);
68   image_cell->image_description = g_strdup (description);
69
70   if (image_cell->image_description)
71     return TRUE;
72   else
73     return FALSE;
74 }
75
76 static void
77 gtk_image_cell_accessible_get_image_position (AtkImage     *image,
78                                               gint         *x,
79                                               gint         *y,
80                                               AtkCoordType  coord_type)
81 {
82   atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
83 }
84
85 static void
86 gtk_image_cell_accessible_get_image_size (AtkImage *image,
87                                           gint     *width,
88                                           gint     *height)
89 {
90   GtkImageCellAccessible *cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
91   GtkCellRenderer *cell_renderer;
92   GdkPixbuf *pixbuf = NULL;
93
94   *width = 0;
95   *height = 0;
96
97   cell_renderer = GTK_RENDERER_CELL_ACCESSIBLE (cell)->renderer;
98   g_object_get (GTK_CELL_RENDERER_PIXBUF (cell_renderer),
99                 "pixbuf", &pixbuf,
100                 NULL);
101
102   if (pixbuf)
103     {
104       *width = gdk_pixbuf_get_width (pixbuf);
105       *height = gdk_pixbuf_get_height (pixbuf);
106       g_object_unref (pixbuf);
107     }
108 }
109
110 static void
111 atk_image_interface_init (AtkImageIface  *iface)
112 {
113   iface->get_image_description = gtk_image_cell_accessible_get_image_description;
114   iface->set_image_description = gtk_image_cell_accessible_set_image_description;
115   iface->get_image_position = gtk_image_cell_accessible_get_image_position;
116   iface->get_image_size = gtk_image_cell_accessible_get_image_size;
117 }