2 * Copyright (C) 2000 Red Hat, Inc. Jonathan Blandford
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library 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.
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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
20 #include "gtkcellrenderer.h"
23 static void gtk_cell_renderer_init (GtkCellRenderer *cell);
24 static void gtk_cell_renderer_class_init (GtkCellRendererClass *class);
25 static void gtk_cell_renderer_get_property (GObject *object,
29 static void gtk_cell_renderer_set_property (GObject *object,
46 gtk_cell_renderer_get_type (void)
48 static GtkType cell_type = 0;
52 static const GTypeInfo cell_info =
54 sizeof (GtkCellRendererClass),
56 NULL, /* base_finalize */
57 (GClassInitFunc) gtk_cell_renderer_class_init,
58 NULL, /* class_finalize */
59 NULL, /* class_data */
60 sizeof (GtkCellRenderer),
62 (GInstanceInitFunc) gtk_cell_renderer_init,
65 cell_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkCellRenderer", &cell_info, 0);
72 gtk_cell_renderer_init (GtkCellRenderer *cell)
74 /* FIXME remove on port to GtkObject */
75 gtk_object_ref (GTK_OBJECT (cell));
76 gtk_object_sink (GTK_OBJECT (cell));
86 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
88 GObjectClass *object_class = G_OBJECT_CLASS (class);
90 object_class->get_property = gtk_cell_renderer_get_property;
91 object_class->set_property = gtk_cell_renderer_set_property;
94 class->get_size = NULL;
96 g_object_class_install_property (object_class,
98 g_param_spec_boolean ("visible",
100 _("Display the cell"),
105 g_object_class_install_property (object_class,
107 g_param_spec_float ("xalign",
116 g_object_class_install_property (object_class,
118 g_param_spec_float ("yalign",
127 g_object_class_install_property (object_class,
129 g_param_spec_uint ("xpad",
138 g_object_class_install_property (object_class,
140 g_param_spec_uint ("ypad",
151 gtk_cell_renderer_get_property (GObject *object,
156 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
161 g_value_set_boolean (value, cell->visible);
164 g_value_set_float (value, cell->xalign);
167 g_value_set_float (value, cell->yalign);
170 g_value_set_float (value, cell->xpad);
173 g_value_set_float (value, cell->ypad);
176 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
183 gtk_cell_renderer_set_property (GObject *object,
188 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
193 cell->visible = g_value_get_boolean (value);
194 g_object_notify (object, "visible");
197 cell->xalign = g_value_get_float (value);
198 g_object_notify (object, "xalign");
201 cell->yalign = g_value_get_float (value);
202 g_object_notify (object, "yalign");
205 cell->xpad = g_value_get_int (value);
206 g_object_notify (object, "xpad");
209 cell->ypad = g_value_get_int (value);
210 g_object_notify (object, "ypad");
213 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
219 * gtk_cell_renderer_get_size:
220 * @cell: a #GtkCellRenderer
221 * @widget: the widget the renderer is rendering to
222 * @width: location to return width needed to render a cell, or %NULL
223 * @height: location to return height needed to render a cell, or %NULL
225 * Obtains the width and height needed to render the cell. Used by
226 * view widgets to determine the appropriate size for the cell_area
227 * passed to gtk_cell_renderer_render().
230 gtk_cell_renderer_get_size (GtkCellRenderer *cell,
235 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
236 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size != NULL);
238 GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (cell, widget, width, height);
242 * gtk_cell_renderer_render:
243 * @cell: a #GtkCellRenderer
244 * @window: a #GdkDrawable to draw to
245 * @widget: the widget owning @window
246 * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
247 * @cell_area: area normally rendered by a cell renderer
248 * @expose_area: area that actually needs updating
249 * @flags: flags that affect rendering
251 * Invokes the virtual render function of the #GtkCellRenderer. The
252 * three passed-in rectangles are areas of @window. Most renderers
253 * will draw to @cell_area; the xalign, yalign, xpad, and ypad fields
254 * of the #GtkCellRenderer should be honored with respect to
255 * @cell_area. @background_area includes the blank space around the
256 * cell, and also the area containing the tree expander; so the
257 * @background_area rectangles for all cells tile to cover the entire
258 * @window. Cell renderers can use the @background_area to draw custom expanders, for
259 * example. @expose_area is a clip rectangle.
263 gtk_cell_renderer_render (GtkCellRenderer *cell,
266 GdkRectangle *background_area,
267 GdkRectangle *cell_area,
268 GdkRectangle *expose_area,
269 GtkCellRendererState flags)
271 /* It's actually okay to pass in a NULL cell, as we run into that
276 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
277 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
279 GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
289 * gtk_cell_renderer_event:
290 * @cell: a #GtkCellRenderer
291 * @event: a #GdkEvent
292 * @widget: widget that received the event
293 * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
294 * @background_area: background area as passed to gtk_cell_renderer_render()
295 * @cell_area: cell area as passed to gtk_cell_renderer_render()
296 * @flags: render flags
298 * Passes an event to the cell renderer for possible processing. Some
299 * cell renderers may use events; for example, #GtkCellRendererToggle
300 * toggles when it gets a mouse click.
302 * Return value: %TRUE if the event was consumed/handled
305 gtk_cell_renderer_event (GtkCellRenderer *cell,
309 GdkRectangle *background_area,
310 GdkRectangle *cell_area,
311 GtkCellRendererState flags)
313 /* It's actually okay to pass in a NULL cell, as we run into that
318 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
319 if (GTK_CELL_RENDERER_GET_CLASS (cell)->event == NULL)
322 return GTK_CELL_RENDERER_GET_CLASS (cell)->event (cell,