]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkimagecellaccessible.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / a11y / gtkimagecellaccessible.c
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_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
32
33 static void
34 gtk_image_cell_accessible_finalize (GObject *object)
35 {
36   GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (object);
37
38   g_free (image_cell->priv->image_description);
39   G_OBJECT_CLASS (gtk_image_cell_accessible_parent_class)->finalize (object);
40 }
41
42 static void
43 gtk_image_cell_accessible_class_init (GtkImageCellAccessibleClass *klass)
44 {
45   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
46
47   gobject_class->finalize = gtk_image_cell_accessible_finalize;
48
49   g_type_class_add_private (klass, sizeof (GtkImageCellAccessiblePrivate));
50 }
51
52 static void
53 gtk_image_cell_accessible_init (GtkImageCellAccessible *image_cell)
54 {
55   image_cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (image_cell,
56                                                   GTK_TYPE_IMAGE_CELL_ACCESSIBLE,
57                                                   GtkImageCellAccessiblePrivate);
58 }
59
60 static const gchar *
61 gtk_image_cell_accessible_get_image_description (AtkImage *image)
62 {
63   GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
64
65   return image_cell->priv->image_description;
66 }
67
68 static gboolean
69 gtk_image_cell_accessible_set_image_description (AtkImage    *image,
70                                                  const gchar *description)
71 {
72   GtkImageCellAccessible *image_cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
73
74   g_free (image_cell->priv->image_description);
75   image_cell->priv->image_description = g_strdup (description);
76
77   if (image_cell->priv->image_description)
78     return TRUE;
79   else
80     return FALSE;
81 }
82
83 static void
84 gtk_image_cell_accessible_get_image_position (AtkImage     *image,
85                                               gint         *x,
86                                               gint         *y,
87                                               AtkCoordType  coord_type)
88 {
89   atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
90 }
91
92 static void
93 gtk_image_cell_accessible_get_image_size (AtkImage *image,
94                                           gint     *width,
95                                           gint     *height)
96 {
97   GtkImageCellAccessible *cell = GTK_IMAGE_CELL_ACCESSIBLE (image);
98   GtkCellRenderer *cell_renderer;
99   GdkPixbuf *pixbuf = NULL;
100
101   *width = 0;
102   *height = 0;
103
104   g_object_get (cell, "renderer", &cell_renderer, NULL);
105   g_object_get (cell_renderer,
106                 "pixbuf", &pixbuf,
107                 NULL);
108   g_object_unref (cell_renderer);
109
110   if (pixbuf)
111     {
112       *width = gdk_pixbuf_get_width (pixbuf);
113       *height = gdk_pixbuf_get_height (pixbuf);
114       g_object_unref (pixbuf);
115     }
116 }
117
118 static void
119 atk_image_interface_init (AtkImageIface  *iface)
120 {
121   iface->get_image_description = gtk_image_cell_accessible_get_image_description;
122   iface->set_image_description = gtk_image_cell_accessible_set_image_description;
123   iface->get_image_position = gtk_image_cell_accessible_get_image_position;
124   iface->get_image_size = gtk_image_cell_accessible_get_image_size;
125 }