Debian Codegraph @

gtk/a11y/gtkimagecellaccessible.c

raw
1 /* GTK+ - accessibility implementations
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 struct _GtkImageCellAccessiblePrivate
24 {
25 gchar *image_description;
26 };
27
28 static void atk_image_interface_init (AtkImageIface *iface);
29
30 G_DEFINE_TYPE_WITH_CODE (GtkImageCellAccessible, gtk_image_cell_accessible, GTK_TYPE_RENDERER_CELL_ACCESSIBLE,
31 G_ADD_PRIVATE (GtkImageCellAccessible)
32 G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
33
34 static void
35 gtk_image_cell_accessible_finalize (GObject *object)
36 {
37 GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (object);
38
39 g_free (image_cell->priv->image_description);
40 G_OBJECT_CLASS (gtk_image_cell_accessible_parent_class)->finalize (object);
41 }
42
43 static void
44 gtk_image_cell_accessible_class_init (GtkImageCellAccessibleClass *klass)
45 {
46 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
47
48 gobject_class->finalize = gtk_image_cell_accessible_finalize;
49 }
50
51 static void
52 gtk_image_cell_accessible_init (GtkImageCellAccessible *image_cell)
53 {
54 image_cell->priv = gtk_image_cell_accessible_get_instance_private (image_cell);
55 }
56
57 static const gchar *
58 gtk_image_cell_accessible_get_image_description (AtkImage *image)
59 {
60 GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
61
62 return image_cell->priv->image_description;
63 }
64
65 static gboolean
66 gtk_image_cell_accessible_set_image_description (AtkImage *image,
67 const gchar *description)
68 {
69 GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
70
71 g_free (image_cell->priv->image_description);
72 image_cell->priv->image_description = g_strdup (description);
73
74 if (image_cell->priv->image_description)
75 return TRUE;
76 else
77 return FALSE;
78 }
79
80 static void
81 gtk_image_cell_accessible_get_image_position (AtkImage *image,
82 gint *x,
83 gint *y,
84 AtkCoordType coord_type)
85 {
86 atk_component_get_extents (ATK_COMPONENT (image), x, y, NULL, NULL,
87 coord_type);
88 }
89
90 static void
91 gtk_image_cell_accessible_get_image_size (AtkImage *image,
92 gint *width,
93 gint *height)
94 {
95 GtkImageCellAccessible *cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
96 GtkCellRenderer *cell_renderer;
97 GdkPixbuf *pixbuf = NULL;
98
99 *width = 0;
100 *height = 0;
101
102 g_object_get (cell, "renderer", &cell_renderer, NULL);
103 g_object_get (cell_renderer,
104 "pixbuf", &pixbuf,
105 NULL);
106 g_object_unref (cell_renderer);
107
108 if (pixbuf)
109 {
110 *width = gdk_pixbuf_get_width (pixbuf);
111 *height = gdk_pixbuf_get_height (pixbuf);
112 g_object_unref (pixbuf);
113 }
114 }
115
116 static void
117 atk_image_interface_init (AtkImageIface *iface)
118 {
119 iface->get_image_description = gtk_image_cell_accessible_get_image_description;
120 iface->set_image_description = gtk_image_cell_accessible_set_image_description;
121 iface->get_image_position = gtk_image_cell_accessible_get_image_position;
122 iface->get_image_size = gtk_image_cell_accessible_get_image_size;
123 }