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,
51 gtk_cell_renderer_get_type (void)
53 static GtkType cell_type = 0;
57 static const GTypeInfo cell_info =
59 sizeof (GtkCellRendererClass),
61 NULL, /* base_finalize */
62 (GClassInitFunc) gtk_cell_renderer_class_init,
63 NULL, /* class_finalize */
64 NULL, /* class_data */
65 sizeof (GtkCellRenderer),
67 (GInstanceInitFunc) gtk_cell_renderer_init,
70 cell_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkCellRenderer", &cell_info, 0);
77 gtk_cell_renderer_init (GtkCellRenderer *cell)
79 cell->mode = GTK_CELL_RENDERER_MODE_INERT;
90 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
92 GObjectClass *object_class = G_OBJECT_CLASS (class);
94 object_class->get_property = gtk_cell_renderer_get_property;
95 object_class->set_property = gtk_cell_renderer_set_property;
98 class->get_size = NULL;
100 g_object_class_install_property (object_class,
102 g_param_spec_enum ("mode",
104 _("Editable mode of the CellRenderer"),
105 GTK_TYPE_CELL_RENDERER_MODE,
106 GTK_CELL_RENDERER_MODE_INERT,
110 g_object_class_install_property (object_class,
112 g_param_spec_boolean ("visible",
114 _("Display the cell"),
119 g_object_class_install_property (object_class,
121 g_param_spec_float ("xalign",
130 g_object_class_install_property (object_class,
132 g_param_spec_float ("yalign",
141 g_object_class_install_property (object_class,
143 g_param_spec_uint ("xpad",
152 g_object_class_install_property (object_class,
154 g_param_spec_uint ("ypad",
163 g_object_class_install_property (object_class,
165 g_param_spec_int ("width",
167 _("The fixed width."),
174 g_object_class_install_property (object_class,
176 g_param_spec_int ("height",
178 _("The fixed height."),
185 g_object_class_install_property (object_class,
187 g_param_spec_boolean ("is_expander",
189 _("Row has children."),
195 g_object_class_install_property (object_class,
197 g_param_spec_boolean ("is_expanded",
199 _("Row is an expander row, and is expanded"),
206 gtk_cell_renderer_get_property (GObject *object,
211 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
216 g_value_set_enum (value, cell->mode);
219 g_value_set_boolean (value, cell->visible);
222 g_value_set_float (value, cell->xalign);
225 g_value_set_float (value, cell->yalign);
228 g_value_set_uint (value, cell->xpad);
231 g_value_set_uint (value, cell->ypad);
234 g_value_set_int (value, cell->width);
237 g_value_set_int (value, cell->height);
239 case PROP_IS_EXPANDER:
240 g_value_set_int (value, cell->is_expander);
242 case PROP_IS_EXPANDED:
243 g_value_set_int (value, cell->is_expanded);
246 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
253 gtk_cell_renderer_set_property (GObject *object,
258 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
263 cell->mode = g_value_get_enum (value);
266 cell->visible = g_value_get_boolean (value);
269 cell->xalign = g_value_get_float (value);
272 cell->yalign = g_value_get_float (value);
275 cell->xpad = g_value_get_uint (value);
278 cell->ypad = g_value_get_uint (value);
281 cell->width = g_value_get_int (value);
284 cell->height = g_value_get_int (value);
286 case PROP_IS_EXPANDER:
287 cell->is_expander = g_value_get_boolean (value);
289 case PROP_IS_EXPANDED:
290 cell->is_expanded = g_value_get_boolean (value);
293 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
299 * gtk_cell_renderer_get_size:
300 * @cell: a #GtkCellRenderer
301 * @widget: the widget the renderer is rendering to
302 * @cell_area: The area a cell will be allocated, or %NULL
303 * @x_offset: location to return x offset of cell relative to @cell_area, or %NULL
304 * @y_offset: location to return y offset of cell relative to @cell_area, or %NULL
305 * @width: location to return width needed to render a cell, or %NULL
306 * @height: location to return height needed to render a cell, or %NULL
308 * Obtains the width and height needed to render the cell. Used by view widgets
309 * to determine the appropriate size for the cell_area passed to
310 * gtk_cell_renderer_render(). If @cell_area is not %NULL, fills in the x and y
311 * offsets (if set) of the cell relative to this location. Please note that the
312 * values set in @width and @height, as well as those in @x_offset and @y_offset
313 * are inclusive of the xpad and ypad properties.
316 gtk_cell_renderer_get_size (GtkCellRenderer *cell,
318 GdkRectangle *cell_area,
324 gint *real_width = width;
325 gint *real_height = height;
327 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
328 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size != NULL);
330 if (width && cell->width != -1)
333 *width = cell->width;
335 if (height && cell->height != -1)
338 *height = cell->height;
341 GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (cell, widget, cell_area, x_offset, y_offset, real_width, real_height);
345 * gtk_cell_renderer_render:
346 * @cell: a #GtkCellRenderer
347 * @window: a #GdkDrawable to draw to
348 * @widget: the widget owning @window
349 * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
350 * @cell_area: area normally rendered by a cell renderer
351 * @expose_area: area that actually needs updating
352 * @flags: flags that affect rendering
354 * Invokes the virtual render function of the #GtkCellRenderer. The three
355 * passed-in rectangles are areas of @window. Most renderers will draw within
356 * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
357 * should be honored with respect to @cell_area. @background_area includes the
358 * blank space around the cell, and also the area containing the tree expander;
359 * so the @background_area rectangles for all cells tile to cover the entire
360 * @window. @expose_area is a clip rectangle.
364 gtk_cell_renderer_render (GtkCellRenderer *cell,
367 GdkRectangle *background_area,
368 GdkRectangle *cell_area,
369 GdkRectangle *expose_area,
370 GtkCellRendererState flags)
372 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
373 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
375 GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
385 * gtk_cell_renderer_activate:
386 * @cell: a #GtkCellRenderer
387 * @event: a #GdkEvent
388 * @widget: widget that received the event
389 * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
390 * @background_area: background area as passed to @gtk_cell_renderer_render
391 * @cell_area: cell area as passed to @gtk_cell_renderer_render
392 * @flags: render flags
394 * Passes an activate event to the cell renderer for possible processing. Some
395 * cell renderers may use events; for example, #GtkCellRendererToggle toggles
396 * when it gets a mouse click.
398 * Return value: %TRUE if the event was consumed/handled
401 gtk_cell_renderer_activate (GtkCellRenderer *cell,
405 GdkRectangle *background_area,
406 GdkRectangle *cell_area,
407 GtkCellRendererState flags)
409 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
411 if (cell->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
414 if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
417 return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
427 * gtk_cell_renderer_start_editing:
428 * @cell: a #GtkCellRenderer
429 * @event: a #GdkEvent
430 * @widget: widget that received the event
431 * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
432 * @background_area: background area as passed to @gtk_cell_renderer_render
433 * @cell_area: cell area as passed to @gtk_cell_renderer_render
434 * @flags: render flags
436 * Passes an activate event to the cell renderer for possible processing.
438 * Return value: A new #GtkCellEditable, or %NULL
441 gtk_cell_renderer_start_editing (GtkCellRenderer *cell,
445 GdkRectangle *background_area,
446 GdkRectangle *cell_area,
447 GtkCellRendererState flags)
450 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
452 if (cell->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
455 if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
459 return GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
469 * gtk_cell_renderer_set_fixed_size:
470 * @cell: A #GtkCellRenderer
471 * @width: the width of the cell renderer, or -1
472 * @height: the height of the cell renderer, or -1
474 * Sets the renderer size to be explicit, independent of the properties set.
477 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
481 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
482 g_return_if_fail (width >= -1 && height >= -1);
484 if ((width != cell->width) || (height != cell->height))
486 g_object_freeze_notify (G_OBJECT (cell));
488 if (width != cell->width)
491 g_object_notify (G_OBJECT (cell), "width");
494 if (height != cell->height)
496 cell->height = height;
497 g_object_notify (G_OBJECT (cell), "height");
500 g_object_thaw_notify (G_OBJECT (cell));
505 * gtk_cell_renderer_get_fixed_size:
506 * @cell: A #GtkCellRenderer
507 * @width: location to fill in with the fixed width of the widget, or %NULL
508 * @height: location to fill in with the fixed height of the widget, or %NULL
510 * Fills in @width and @height with the appropriate size of @cell.
513 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
517 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
520 (* width) = cell->width;
522 (* height) = cell->height;