]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailimagecell.c
Include <config.h>. Bug #504720.
[~andy/gtk] / modules / other / gail / gailimagecell.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 "gailimagecell.h"
24
25 static void      gail_image_cell_class_init          (GailImageCellClass *klass);
26 static void      gail_image_cell_init                (GailImageCell      *image_cell);
27
28 static void      gail_image_cell_finalize            (GObject            *object);
29
30 /* AtkImage */
31 static void      atk_image_interface_init              (AtkImageIface  *iface);
32 static G_CONST_RETURN gchar *
33                  gail_image_cell_get_image_description (AtkImage       *image);
34 static gboolean  gail_image_cell_set_image_description (AtkImage       *image,
35                                                         const gchar    *description);
36 static void      gail_image_cell_get_image_position    (AtkImage       *image,
37                                                         gint           *x,
38                                                         gint           *y,
39                                                         AtkCoordType   coord_type);
40 static void      gail_image_cell_get_image_size        (AtkImage       *image,
41                                                         gint           *width,
42                                                         gint           *height);
43
44 /* Misc */
45
46 static gboolean  gail_image_cell_update_cache          (GailRendererCell *cell,
47                                                         gboolean         emit_change_signal);
48
49 // FIXMEchpe static!!!
50 gchar *gail_image_cell_property_list[] = {
51   "pixbuf",
52   NULL
53 };
54
55 G_DEFINE_TYPE_WITH_CODE (GailImageCell, gail_image_cell, GAIL_TYPE_RENDERER_CELL,
56                          G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
57
58 static void 
59 gail_image_cell_class_init (GailImageCellClass *klass)
60 {
61   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
62   GailRendererCellClass *renderer_cell_class = GAIL_RENDERER_CELL_CLASS(klass);
63
64   gobject_class->finalize = gail_image_cell_finalize;
65
66   renderer_cell_class->update_cache = gail_image_cell_update_cache;
67   renderer_cell_class->property_list = gail_image_cell_property_list;
68 }
69
70 AtkObject* 
71 gail_image_cell_new (void)
72 {
73   GObject *object;
74   AtkObject *atk_object;
75   GailRendererCell *cell;
76
77   object = g_object_new (GAIL_TYPE_IMAGE_CELL, NULL);
78
79   g_return_val_if_fail (object != NULL, NULL);
80
81   atk_object = ATK_OBJECT (object);
82   atk_object->role = ATK_ROLE_TABLE_CELL;
83
84   cell = GAIL_RENDERER_CELL(object);
85
86   cell->renderer = gtk_cell_renderer_pixbuf_new ();
87   g_object_ref (cell->renderer);
88   gtk_object_sink (GTK_OBJECT (cell->renderer));
89   return atk_object;
90 }
91
92 static void
93 gail_image_cell_init (GailImageCell *image_cell)
94 {
95   image_cell->image_description = NULL;
96 }
97
98
99 static void
100 gail_image_cell_finalize (GObject *object)
101 {
102   GailImageCell *image_cell = GAIL_IMAGE_CELL (object);
103
104   g_free (image_cell->image_description);
105   G_OBJECT_CLASS (gail_image_cell_parent_class)->finalize (object);
106 }
107
108 static gboolean
109 gail_image_cell_update_cache (GailRendererCell *cell, 
110                               gboolean         emit_change_signal)
111 {
112   return FALSE;
113 }
114
115 static void
116 atk_image_interface_init (AtkImageIface  *iface)
117 {
118   iface->get_image_description = gail_image_cell_get_image_description;
119   iface->set_image_description = gail_image_cell_set_image_description;
120   iface->get_image_position = gail_image_cell_get_image_position;
121   iface->get_image_size = gail_image_cell_get_image_size;
122 }
123
124 static G_CONST_RETURN gchar *
125 gail_image_cell_get_image_description (AtkImage     *image)
126 {
127   GailImageCell *image_cell;
128
129   image_cell = GAIL_IMAGE_CELL (image);
130   return image_cell->image_description;
131 }
132
133 static gboolean
134 gail_image_cell_set_image_description (AtkImage     *image,
135                                        const gchar  *description)
136 {
137   GailImageCell *image_cell;
138
139   image_cell = GAIL_IMAGE_CELL (image);
140   g_free (image_cell->image_description);
141   image_cell->image_description = g_strdup (description);
142   if (image_cell->image_description)
143     return TRUE;
144   else
145     return FALSE;
146 }
147
148 static void
149 gail_image_cell_get_image_position (AtkImage     *image,
150                                     gint         *x,
151                                     gint         *y,
152                                     AtkCoordType coord_type)
153 {
154   atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
155 }
156
157 static void
158 gail_image_cell_get_image_size (AtkImage *image,
159                                 gint     *width,
160                                 gint     *height)
161 {
162   GailImageCell *cell = GAIL_IMAGE_CELL (image);
163   GtkCellRenderer *cell_renderer;
164   GdkPixbuf *pixbuf;
165
166   cell_renderer  = GAIL_RENDERER_CELL (cell)->renderer;
167   pixbuf = GTK_CELL_RENDERER_PIXBUF (cell_renderer)->pixbuf;
168
169   *width = gdk_pixbuf_get_width (pixbuf);
170   *height = gdk_pixbuf_get_height (pixbuf);
171 }