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