]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkimagecellaccessible.c
a11y: Use cell renderer creation funcs unconditionally
[~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 gchar *property_list[] = {
26   "pixbuf",
27   NULL
28 };
29
30 static void atk_image_interface_init (AtkImageIface *iface);
31
32 G_DEFINE_TYPE_WITH_CODE (GtkImageCellAccessible, _gtk_image_cell_accessible, GTK_TYPE_RENDERER_CELL_ACCESSIBLE,
33                          G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
34
35 static void
36 gtk_image_cell_accessible_finalize (GObject *object)
37 {
38   GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (object);
39
40   g_free (image_cell->image_description);
41   G_OBJECT_CLASS (_gtk_image_cell_accessible_parent_class)->finalize (object);
42 }
43
44 static gboolean
45 gtk_image_cell_accessible_update_cache (GtkRendererCellAccessible *cell,
46                                         gboolean                   emit_change_signal)
47 {
48   return FALSE;
49 }
50
51 static void
52 _gtk_image_cell_accessible_class_init (GtkImageCellAccessibleClass *klass)
53 {
54   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
55   GtkRendererCellAccessibleClass *renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_CLASS (klass);
56
57   gobject_class->finalize = gtk_image_cell_accessible_finalize;
58
59   renderer_cell_class->update_cache = gtk_image_cell_accessible_update_cache;
60   renderer_cell_class->property_list = property_list;
61 }
62
63 static void
64 _gtk_image_cell_accessible_init (GtkImageCellAccessible *image_cell)
65 {
66   image_cell->image_description = NULL;
67 }
68
69 static const gchar *
70 gtk_image_cell_accessible_get_image_description (AtkImage *image)
71 {
72   GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
73
74   return image_cell->image_description;
75 }
76
77 static gboolean
78 gtk_image_cell_accessible_set_image_description (AtkImage    *image,
79                                                  const gchar *description)
80 {
81   GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
82
83   g_free (image_cell->image_description);
84   image_cell->image_description = g_strdup (description);
85
86   if (image_cell->image_description)
87     return TRUE;
88   else
89     return FALSE;
90 }
91
92 static void
93 gtk_image_cell_accessible_get_image_position (AtkImage     *image,
94                                               gint         *x,
95                                               gint         *y,
96                                               AtkCoordType  coord_type)
97 {
98   atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
99 }
100
101 static void
102 gtk_image_cell_accessible_get_image_size (AtkImage *image,
103                                           gint     *width,
104                                           gint     *height)
105 {
106   GtkImageCellAccessible *cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
107   GtkCellRenderer *cell_renderer;
108   GdkPixbuf *pixbuf = NULL;
109
110   *width = 0;
111   *height = 0;
112
113   cell_renderer = GTK_RENDERER_CELL_ACCESSIBLE (cell)->renderer;
114   g_object_get (GTK_CELL_RENDERER_PIXBUF (cell_renderer),
115                 "pixbuf", &pixbuf,
116                 NULL);
117
118   if (pixbuf)
119     {
120       *width = gdk_pixbuf_get_width (pixbuf);
121       *height = gdk_pixbuf_get_height (pixbuf);
122       g_object_unref (pixbuf);
123     }
124 }
125
126 static void
127 atk_image_interface_init (AtkImageIface  *iface)
128 {
129   iface->get_image_description = gtk_image_cell_accessible_get_image_description;
130   iface->set_image_description = gtk_image_cell_accessible_set_image_description;
131   iface->get_image_position = gtk_image_cell_accessible_get_image_position;
132   iface->get_image_size = gtk_image_cell_accessible_get_image_size;
133 }