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);
264 g_object_notify (object, "mode");
267 cell->visible = g_value_get_boolean (value);
268 g_object_notify (object, "visible");
271 cell->xalign = g_value_get_float (value);
272 g_object_notify (object, "xalign");
275 cell->yalign = g_value_get_float (value);
276 g_object_notify (object, "yalign");
279 cell->xpad = g_value_get_uint (value);
280 g_object_notify (object, "xpad");
283 cell->ypad = g_value_get_uint (value);
284 g_object_notify (object, "ypad");
287 cell->width = g_value_get_int (value);
288 g_object_notify (object, "width");
291 cell->height = g_value_get_int (value);
292 g_object_notify (object, "height");
294 case PROP_IS_EXPANDER:
295 cell->is_expander = g_value_get_boolean (value);
296 g_object_notify (object, "is_expander");
298 case PROP_IS_EXPANDED:
299 cell->is_expanded = g_value_get_boolean (value);
300 g_object_notify (object, "is_expanded");
303 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
309 * gtk_cell_renderer_get_size:
310 * @cell: a #GtkCellRenderer
311 * @widget: the widget the renderer is rendering to
312 * @cell_area: The area a cell will be allocated, or %NULL
313 * @x_offset: location to return x offset of cell relative to @cell_area, or %NULL
314 * @y_offset: location to return y offset of cell relative to @cell_area, or %NULL
315 * @width: location to return width needed to render a cell, or %NULL
316 * @height: location to return height needed to render a cell, or %NULL
318 * Obtains the width and height needed to render the cell. Used by view widgets
319 * to determine the appropriate size for the cell_area passed to
320 * gtk_cell_renderer_render(). If @cell_area is not %NULL, fills in the x and y
321 * offsets (if set) of the cell relative to this location.
324 gtk_cell_renderer_get_size (GtkCellRenderer *cell,
326 GdkRectangle *cell_area,
332 gint *real_width = NULL;
333 gint *real_height = NULL;
335 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
336 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size != NULL);
340 if (cell->width == -1)
343 *width = cell->width;
347 if (cell->height == -1)
348 real_height = height;
350 *height = cell->height;
353 if (real_width || real_height)
354 GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (cell, widget, cell_area, x_offset, y_offset, real_width, real_height);
358 * gtk_cell_renderer_render:
359 * @cell: a #GtkCellRenderer
360 * @window: a #GdkDrawable to draw to
361 * @widget: the widget owning @window
362 * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
363 * @cell_area: area normally rendered by a cell renderer
364 * @expose_area: area that actually needs updating
365 * @flags: flags that affect rendering
367 * Invokes the virtual render function of the #GtkCellRenderer. The
368 * three passed-in rectangles are areas of @window. Most renderers
369 * will draw to @cell_area; the xalign, yalign, xpad, and ypad fields
370 * of the #GtkCellRenderer should be honored with respect to
371 * @cell_area. @background_area includes the blank space around the
372 * cell, and also the area containing the tree expander; so the
373 * @background_area rectangles for all cells tile to cover the entire
374 * @window. Cell renderers can use the @background_area to draw custom expanders, for
375 * example. @expose_area is a clip rectangle.
379 gtk_cell_renderer_render (GtkCellRenderer *cell,
382 GdkRectangle *background_area,
383 GdkRectangle *cell_area,
384 GdkRectangle *expose_area,
385 GtkCellRendererState flags)
387 /* It's actually okay to pass in a NULL cell, as we run into that
392 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
393 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
395 GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
405 * gtk_cell_renderer_activate:
406 * @cell: a #GtkCellRenderer
407 * @event: a #GdkEvent
408 * @widget: widget that received the event
409 * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
410 * @background_area: background area as passed to gtk_cell_renderer_render()
411 * @cell_area: cell area as passed to gtk_cell_renderer_render()
412 * @flags: render flags
414 * Passes an activate event to the cell renderer for possible processing. Some
415 * cell renderers may use events; for example, #GtkCellRendererToggle toggles
416 * when it gets a mouse click.
418 * Return value: %TRUE if the event was consumed/handled
421 gtk_cell_renderer_activate (GtkCellRenderer *cell,
425 GdkRectangle *background_area,
426 GdkRectangle *cell_area,
427 GtkCellRendererState flags)
429 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
431 if (cell->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
434 if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
437 return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
448 * gtk_cell_renderer_start_editing:
449 * @cell: a #GtkCellRenderer
450 * @event: a #GdkEvent
451 * @widget: widget that received the event
452 * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
453 * @background_area: background area as passed to gtk_cell_renderer_render()
454 * @cell_area: cell area as passed to gtk_cell_renderer_render()
455 * @flags: render flags
457 * Passes an activate event to the cell renderer for possible processing.
459 * Return value: A new #GtkCellEditable, or %NULL
462 gtk_cell_renderer_start_editing (GtkCellRenderer *cell,
466 GdkRectangle *background_area,
467 GdkRectangle *cell_area,
468 GtkCellRendererState flags)
471 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
473 if (cell->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
476 if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
480 return GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
490 * gtk_cell_renderer_set_fixed_size:
491 * @cell: A #GtkCellRenderer
492 * @width: the width of the cell renderer, or -1
493 * @height: the height of the cell renderer, or -1
495 * Sets the renderer size to be explicit, independent of the properties set.
498 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
502 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
503 g_return_if_fail (width >= -1 && height >= -1);
505 if ((width != cell->width) || (height != cell->height))
507 g_object_freeze_notify (G_OBJECT (cell));
509 if (width != cell->width)
512 g_object_notify (G_OBJECT (cell), "width");
515 if (height != cell->height)
517 cell->height = height;
518 g_object_notify (G_OBJECT (cell), "height");
521 g_object_thaw_notify (G_OBJECT (cell));
526 * gtk_cell_renderer_get_fixed_size:
527 * @cell: A #GtkCellRenderer
528 * @width: location to fill in with the fixed width of the widget, or %NULL
529 * @height: location to fill in with the fixed height of the widget, or %NULL
531 * Fills in @width and @height with the appropriate size of @cell.
534 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
538 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
541 (* width) = cell->width;
543 (* height) = cell->height;