]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gailimagecell.c
gail: No need to include modules/other in CFLAGS anymore
[~andy/gtk] / gtk / a11y / 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 const 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_sink (cell->renderer);
88   return atk_object;
89 }
90
91 static void
92 gail_image_cell_init (GailImageCell *image_cell)
93 {
94   image_cell->image_description = NULL;
95 }
96
97
98 static void
99 gail_image_cell_finalize (GObject *object)
100 {
101   GailImageCell *image_cell = GAIL_IMAGE_CELL (object);
102
103   g_free (image_cell->image_description);
104   G_OBJECT_CLASS (gail_image_cell_parent_class)->finalize (object);
105 }
106
107 static gboolean
108 gail_image_cell_update_cache (GailRendererCell *cell, 
109                               gboolean         emit_change_signal)
110 {
111   return FALSE;
112 }
113
114 static void
115 atk_image_interface_init (AtkImageIface  *iface)
116 {
117   iface->get_image_description = gail_image_cell_get_image_description;
118   iface->set_image_description = gail_image_cell_set_image_description;
119   iface->get_image_position = gail_image_cell_get_image_position;
120   iface->get_image_size = gail_image_cell_get_image_size;
121 }
122
123 static const gchar *
124 gail_image_cell_get_image_description (AtkImage     *image)
125 {
126   GailImageCell *image_cell;
127
128   image_cell = GAIL_IMAGE_CELL (image);
129   return image_cell->image_description;
130 }
131
132 static gboolean
133 gail_image_cell_set_image_description (AtkImage     *image,
134                                        const gchar  *description)
135 {
136   GailImageCell *image_cell;
137
138   image_cell = GAIL_IMAGE_CELL (image);
139   g_free (image_cell->image_description);
140   image_cell->image_description = g_strdup (description);
141   if (image_cell->image_description)
142     return TRUE;
143   else
144     return FALSE;
145 }
146
147 static void
148 gail_image_cell_get_image_position (AtkImage     *image,
149                                     gint         *x,
150                                     gint         *y,
151                                     AtkCoordType coord_type)
152 {
153   atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
154 }
155
156 static void
157 gail_image_cell_get_image_size (AtkImage *image,
158                                 gint     *width,
159                                 gint     *height)
160 {
161   GailImageCell *cell = GAIL_IMAGE_CELL (image);
162   GtkCellRenderer *cell_renderer;
163   GdkPixbuf *pixbuf;
164
165   cell_renderer  = GAIL_RENDERER_CELL (cell)->renderer;
166   g_object_get (GTK_CELL_RENDERER_PIXBUF (cell_renderer), "pixbuf", &pixbuf, NULL);
167
168   *width = gdk_pixbuf_get_width (pixbuf);
169   *height = gdk_pixbuf_get_height (pixbuf);
170 }