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.
21 #include "gtkcellrenderer.h"
23 #include "gtkmarshalers.h"
24 #include "gtkprivate.h"
25 #include "gtktreeprivate.h"
29 * SECTION:gtkcellrenderer
30 * @Short_description: An object for rendering a single cell on a GdkDrawable
31 * @Title: GtkCellRenderer
32 * @See_also: #GtkCellRendererText, #GtkCellRendererPixbuf, #GtkCellRendererToggle
34 * The #GtkCellRenderer is a base class of a set of objects used for
35 * rendering a cell to a #GdkDrawable. These objects are used primarily by
36 * the #GtkTreeView widget, though they aren't tied to them in any
37 * specific way. It is worth noting that #GtkCellRenderer is not a
38 * #GtkWidget and cannot be treated as such.
40 * The primary use of a #GtkCellRenderer is for drawing a certain graphical
41 * elements on a #GdkDrawable. Typically, one cell renderer is used to
42 * draw many cells on the screen. To this extent, it isn't expected that a
43 * CellRenderer keep any permanent state around. Instead, any state is set
44 * just prior to use using #GObject<!-- -->s property system. Then, the
45 * cell is measured using gtk_cell_renderer_get_size(). Finally, the cell
46 * is rendered in the correct location using gtk_cell_renderer_render().
48 * There are a number of rules that must be followed when writing a new
49 * #GtkCellRenderer. First and formost, it's important that a certain set
50 * of properties will always yield a cell renderer of the same size,
51 * barring a #GtkStyle change. The #GtkCellRenderer also has a number of
52 * generic properties that are expected to be honored by all children.
54 * Beyond merely rendering a cell, cell renderers can optionally
55 * provide active user interface elements. A cell renderer can be
56 * <firstterm>activatable</firstterm> like #GtkCellRendererToggle,
57 * which toggles when it gets activated by a mouse click, or it can be
58 * <firstterm>editable</firstterm> like #GtkCellRendererText, which
59 * allows the user to edit the text using a #GtkEntry.
60 * To make a cell renderer activatable or editable, you have to
61 * implement the #GtkCellRendererClass.activate or
62 * #GtkCellRendererClass.start_editing virtual functions, respectively.
66 #define DEBUG_CELL_SIZE_REQUEST 0
68 static void gtk_cell_renderer_init (GtkCellRenderer *cell);
69 static void gtk_cell_renderer_class_init (GtkCellRendererClass *class);
70 static void gtk_cell_renderer_get_property (GObject *object,
74 static void gtk_cell_renderer_set_property (GObject *object,
78 static void set_cell_bg_color (GtkCellRenderer *cell,
81 /* Fallback GtkCellRenderer implementation to use remaining ->get_size() implementations */
82 static void gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
86 static void gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
90 static void gtk_cell_renderer_real_get_preferred_height_for_width(GtkCellRenderer *cell,
94 gint *natural_height);
95 static void gtk_cell_renderer_real_get_preferred_width_for_height(GtkCellRenderer *cell,
100 static void gtk_cell_renderer_real_get_aligned_area (GtkCellRenderer *cell,
102 GtkCellRendererState flags,
103 const GdkRectangle *cell_area,
104 GdkRectangle *aligned_area);
107 struct _GtkCellRendererPrivate
120 guint is_expander : 1;
121 guint is_expanded : 1;
122 guint cell_background_set : 1;
126 GdkRGBA cell_background;
143 PROP_CELL_BACKGROUND,
144 PROP_CELL_BACKGROUND_GDK,
145 PROP_CELL_BACKGROUND_RGBA,
146 PROP_CELL_BACKGROUND_SET,
157 static guint cell_renderer_signals[LAST_SIGNAL] = { 0 };
159 G_DEFINE_ABSTRACT_TYPE(GtkCellRenderer, gtk_cell_renderer, G_TYPE_INITIALLY_UNOWNED)
162 gtk_cell_renderer_init (GtkCellRenderer *cell)
164 GtkCellRendererPrivate *priv;
166 cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
167 GTK_TYPE_CELL_RENDERER,
168 GtkCellRendererPrivate);
171 priv->mode = GTK_CELL_RENDERER_MODE_INERT;
172 priv->visible = TRUE;
179 priv->sensitive = TRUE;
180 priv->is_expander = FALSE;
181 priv->is_expanded = FALSE;
182 priv->editing = FALSE;
186 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
188 GObjectClass *object_class = G_OBJECT_CLASS (class);
190 object_class->get_property = gtk_cell_renderer_get_property;
191 object_class->set_property = gtk_cell_renderer_set_property;
193 class->render = NULL;
194 class->get_size = NULL;
195 class->get_preferred_width = gtk_cell_renderer_real_get_preferred_width;
196 class->get_preferred_height = gtk_cell_renderer_real_get_preferred_height;
197 class->get_preferred_width_for_height = gtk_cell_renderer_real_get_preferred_width_for_height;
198 class->get_preferred_height_for_width = gtk_cell_renderer_real_get_preferred_height_for_width;
199 class->get_aligned_area = gtk_cell_renderer_real_get_aligned_area;
202 * GtkCellRenderer::editing-canceled:
203 * @renderer: the object which received the signal
205 * This signal gets emitted when the user cancels the process of editing a
206 * cell. For example, an editable cell renderer could be written to cancel
207 * editing when the user presses Escape.
209 * See also: gtk_cell_renderer_stop_editing().
213 cell_renderer_signals[EDITING_CANCELED] =
214 g_signal_new (I_("editing-canceled"),
215 G_OBJECT_CLASS_TYPE (object_class),
217 G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
219 _gtk_marshal_VOID__VOID,
223 * GtkCellRenderer::editing-started:
224 * @renderer: the object which received the signal
225 * @editable: the #GtkCellEditable
226 * @path: the path identifying the edited cell
228 * This signal gets emitted when a cell starts to be edited.
229 * The intended use of this signal is to do special setup
230 * on @editable, e.g. adding a #GtkEntryCompletion or setting
231 * up additional columns in a #GtkComboBox.
233 * Note that GTK+ doesn't guarantee that cell renderers will
234 * continue to use the same kind of widget for editing in future
235 * releases, therefore you should check the type of @editable
236 * before doing any specific setup, as in the following example:
239 * text_editing_started (GtkCellRenderer *cell,
240 * GtkCellEditable *editable,
244 * if (GTK_IS_ENTRY (editable))
246 * GtkEntry *entry = GTK_ENTRY (editable);
248 * /* ... create a GtkEntryCompletion */
250 * gtk_entry_set_completion (entry, completion);
257 cell_renderer_signals[EDITING_STARTED] =
258 g_signal_new (I_("editing-started"),
259 G_OBJECT_CLASS_TYPE (object_class),
261 G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
263 _gtk_marshal_VOID__OBJECT_STRING,
265 GTK_TYPE_CELL_EDITABLE,
268 g_object_class_install_property (object_class,
270 g_param_spec_enum ("mode",
272 P_("Editable mode of the CellRenderer"),
273 GTK_TYPE_CELL_RENDERER_MODE,
274 GTK_CELL_RENDERER_MODE_INERT,
275 GTK_PARAM_READWRITE));
277 g_object_class_install_property (object_class,
279 g_param_spec_boolean ("visible",
281 P_("Display the cell"),
283 GTK_PARAM_READWRITE));
284 g_object_class_install_property (object_class,
286 g_param_spec_boolean ("sensitive",
288 P_("Display the cell sensitive"),
290 GTK_PARAM_READWRITE));
292 g_object_class_install_property (object_class,
294 g_param_spec_float ("xalign",
300 GTK_PARAM_READWRITE));
302 g_object_class_install_property (object_class,
304 g_param_spec_float ("yalign",
310 GTK_PARAM_READWRITE));
312 g_object_class_install_property (object_class,
314 g_param_spec_uint ("xpad",
320 GTK_PARAM_READWRITE));
322 g_object_class_install_property (object_class,
324 g_param_spec_uint ("ypad",
330 GTK_PARAM_READWRITE));
332 g_object_class_install_property (object_class,
334 g_param_spec_int ("width",
336 P_("The fixed width"),
340 GTK_PARAM_READWRITE));
342 g_object_class_install_property (object_class,
344 g_param_spec_int ("height",
346 P_("The fixed height"),
350 GTK_PARAM_READWRITE));
352 g_object_class_install_property (object_class,
354 g_param_spec_boolean ("is-expander",
356 P_("Row has children"),
358 GTK_PARAM_READWRITE));
361 g_object_class_install_property (object_class,
363 g_param_spec_boolean ("is-expanded",
365 P_("Row is an expander row, and is expanded"),
367 GTK_PARAM_READWRITE));
369 g_object_class_install_property (object_class,
370 PROP_CELL_BACKGROUND,
371 g_param_spec_string ("cell-background",
372 P_("Cell background color name"),
373 P_("Cell background color as a string"),
375 GTK_PARAM_WRITABLE));
377 g_object_class_install_property (object_class,
378 PROP_CELL_BACKGROUND_GDK,
379 g_param_spec_boxed ("cell-background-gdk",
380 P_("Cell background color"),
381 P_("Cell background color as a GdkColor"),
383 GTK_PARAM_READWRITE));
385 * GtkCellRenderer:cell-background-rgba:
387 * Cell background as a #GdkRGBA
391 g_object_class_install_property (object_class,
392 PROP_CELL_BACKGROUND_RGBA,
393 g_param_spec_boxed ("cell-background-rgba",
394 P_("Cell background RGBA color"),
395 P_("Cell background color as a GdkRGBA"),
397 GTK_PARAM_READWRITE));
399 g_object_class_install_property (object_class,
401 g_param_spec_boolean ("editing",
403 P_("Whether the cell renderer is currently in editing mode"),
405 GTK_PARAM_READABLE));
408 #define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, GTK_PARAM_READWRITE))
410 ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
411 P_("Cell background set"),
412 P_("Whether this tag affects the cell background color"));
414 g_type_class_add_private (class, sizeof (GtkCellRendererPrivate));
418 gtk_cell_renderer_get_property (GObject *object,
423 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
424 GtkCellRendererPrivate *priv = cell->priv;
429 g_value_set_enum (value, priv->mode);
432 g_value_set_boolean (value, priv->visible);
435 g_value_set_boolean (value, priv->sensitive);
438 g_value_set_boolean (value, priv->editing);
441 g_value_set_float (value, priv->xalign);
444 g_value_set_float (value, priv->yalign);
447 g_value_set_uint (value, priv->xpad);
450 g_value_set_uint (value, priv->ypad);
453 g_value_set_int (value, priv->width);
456 g_value_set_int (value, priv->height);
458 case PROP_IS_EXPANDER:
459 g_value_set_boolean (value, priv->is_expander);
461 case PROP_IS_EXPANDED:
462 g_value_set_boolean (value, priv->is_expanded);
464 case PROP_CELL_BACKGROUND_GDK:
468 color.red = (guint16) (priv->cell_background.red * 65535);
469 color.green = (guint16) (priv->cell_background.green * 65535);
470 color.blue = (guint16) (priv->cell_background.blue * 65535);
472 g_value_set_boxed (value, &color);
475 case PROP_CELL_BACKGROUND_RGBA:
476 g_value_set_boxed (value, &priv->cell_background);
478 case PROP_CELL_BACKGROUND_SET:
479 g_value_set_boolean (value, priv->cell_background_set);
481 case PROP_CELL_BACKGROUND:
483 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
490 gtk_cell_renderer_set_property (GObject *object,
495 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
496 GtkCellRendererPrivate *priv = cell->priv;
501 priv->mode = g_value_get_enum (value);
504 priv->visible = g_value_get_boolean (value);
507 priv->sensitive = g_value_get_boolean (value);
510 priv->editing = g_value_get_boolean (value);
513 priv->xalign = g_value_get_float (value);
516 priv->yalign = g_value_get_float (value);
519 priv->xpad = g_value_get_uint (value);
522 priv->ypad = g_value_get_uint (value);
525 priv->width = g_value_get_int (value);
528 priv->height = g_value_get_int (value);
530 case PROP_IS_EXPANDER:
531 priv->is_expander = g_value_get_boolean (value);
533 case PROP_IS_EXPANDED:
534 priv->is_expanded = g_value_get_boolean (value);
536 case PROP_CELL_BACKGROUND:
540 if (!g_value_get_string (value))
541 set_cell_bg_color (cell, NULL);
542 else if (gdk_rgba_parse (g_value_get_string (value), &rgba))
543 set_cell_bg_color (cell, &rgba);
545 g_warning ("Don't know color `%s'", g_value_get_string (value));
547 g_object_notify (object, "cell-background-gdk");
550 case PROP_CELL_BACKGROUND_GDK:
554 color = g_value_get_boxed (value);
559 rgba.red = color->red / 65535.;
560 rgba.green = color->green / 65535.;
561 rgba.blue = color->blue / 65535.;
564 set_cell_bg_color (cell, &rgba);
568 set_cell_bg_color (cell, NULL);
572 case PROP_CELL_BACKGROUND_RGBA:
573 set_cell_bg_color (cell, g_value_get_boxed (value));
575 case PROP_CELL_BACKGROUND_SET:
576 priv->cell_background_set = g_value_get_boolean (value);
579 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
585 set_cell_bg_color (GtkCellRenderer *cell,
588 GtkCellRendererPrivate *priv = cell->priv;
592 if (!priv->cell_background_set)
594 priv->cell_background_set = TRUE;
595 g_object_notify (G_OBJECT (cell), "cell-background-set");
598 priv->cell_background = *rgba;
602 if (priv->cell_background_set)
604 priv->cell_background_set = FALSE;
605 g_object_notify (G_OBJECT (cell), "cell-background-set");
611 * gtk_cell_renderer_get_size:
612 * @cell: a #GtkCellRenderer
613 * @widget: the widget the renderer is rendering to
614 * @cell_area: (allow-none): The area a cell will be allocated, or %NULL
615 * @x_offset: (allow-none): location to return x offset of cell relative to @cell_area, or %NULL
616 * @y_offset: (allow-none): location to return y offset of cell relative to @cell_area, or %NULL
617 * @width: (allow-none): location to return width needed to render a cell, or %NULL
618 * @height: (allow-none): location to return height needed to render a cell, or %NULL
620 * Obtains the width and height needed to render the cell. Used by view
621 * widgets to determine the appropriate size for the cell_area passed to
622 * gtk_cell_renderer_render(). If @cell_area is not %NULL, fills in the
623 * x and y offsets (if set) of the cell relative to this location.
625 * Please note that the values set in @width and @height, as well as those
626 * in @x_offset and @y_offset are inclusive of the xpad and ypad properties.
629 * Deprecated: 3.0: Use gtk_cell_renderer_get_preferred_size() instead.
632 gtk_cell_renderer_get_size (GtkCellRenderer *cell,
634 const GdkRectangle *cell_area,
640 GtkRequisition request;
642 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
644 gtk_cell_renderer_get_preferred_size (cell, widget, &request, NULL);
647 *width = request.width;
650 *height = request.height;
653 _gtk_cell_renderer_calc_offset (cell, cell_area, gtk_widget_get_direction (widget),
654 request.width, request.height, x_offset, y_offset);
658 * gtk_cell_renderer_render:
659 * @cell: a #GtkCellRenderer
660 * @cr: a cairo context to draw to
661 * @widget: the widget owning @window
662 * @background_area: entire cell area (including tree expanders and maybe
663 * padding on the sides)
664 * @cell_area: area normally rendered by a cell renderer
665 * @flags: flags that affect rendering
667 * Invokes the virtual render function of the #GtkCellRenderer. The three
668 * passed-in rectangles are areas in @cr. Most renderers will draw within
669 * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
670 * should be honored with respect to @cell_area. @background_area includes the
671 * blank space around the cell, and also the area containing the tree expander;
672 * so the @background_area rectangles for all cells tile to cover the entire
676 gtk_cell_renderer_render (GtkCellRenderer *cell,
679 const GdkRectangle *background_area,
680 const GdkRectangle *cell_area,
681 GtkCellRendererState flags)
683 gboolean selected = FALSE;
684 GtkCellRendererPrivate *priv = cell->priv;
686 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
687 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
688 g_return_if_fail (cr != NULL);
690 selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
694 if (priv->cell_background_set && !selected)
696 gdk_cairo_rectangle (cr, background_area);
697 gdk_cairo_set_source_rgba (cr, &priv->cell_background);
701 GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
712 * gtk_cell_renderer_activate:
713 * @cell: a #GtkCellRenderer
714 * @event: a #GdkEvent
715 * @widget: widget that received the event
716 * @path: widget-dependent string representation of the event location;
717 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
718 * @background_area: background area as passed to gtk_cell_renderer_render()
719 * @cell_area: cell area as passed to gtk_cell_renderer_render()
720 * @flags: render flags
722 * Passes an activate event to the cell renderer for possible processing.
723 * Some cell renderers may use events; for example, #GtkCellRendererToggle
724 * toggles when it gets a mouse click.
726 * Return value: %TRUE if the event was consumed/handled
729 gtk_cell_renderer_activate (GtkCellRenderer *cell,
733 const GdkRectangle *background_area,
734 const GdkRectangle *cell_area,
735 GtkCellRendererState flags)
737 GtkCellRendererPrivate *priv;
739 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
743 if (priv->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
746 if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
749 return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
753 (GdkRectangle *) background_area,
754 (GdkRectangle *) cell_area,
759 * gtk_cell_renderer_start_editing:
760 * @cell: a #GtkCellRenderer
761 * @event: a #GdkEvent
762 * @widget: widget that received the event
763 * @path: widget-dependent string representation of the event location;
764 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
765 * @background_area: background area as passed to gtk_cell_renderer_render()
766 * @cell_area: cell area as passed to gtk_cell_renderer_render()
767 * @flags: render flags
769 * Passes an activate event to the cell renderer for possible processing.
771 * Return value: (transfer full): A new #GtkCellEditable, or %NULL
774 gtk_cell_renderer_start_editing (GtkCellRenderer *cell,
778 const GdkRectangle *background_area,
779 const GdkRectangle *cell_area,
780 GtkCellRendererState flags)
783 GtkCellRendererPrivate *priv;
784 GtkCellEditable *editable;
786 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
790 if (priv->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
793 if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
796 editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
800 (GdkRectangle *) background_area,
801 (GdkRectangle *) cell_area,
805 cell_renderer_signals[EDITING_STARTED], 0,
808 priv->editing = TRUE;
814 * gtk_cell_renderer_set_fixed_size:
815 * @cell: A #GtkCellRenderer
816 * @width: the width of the cell renderer, or -1
817 * @height: the height of the cell renderer, or -1
819 * Sets the renderer size to be explicit, independent of the properties set.
822 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
826 GtkCellRendererPrivate *priv;
828 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
829 g_return_if_fail (width >= -1 && height >= -1);
833 if ((width != priv->width) || (height != priv->height))
835 g_object_freeze_notify (G_OBJECT (cell));
837 if (width != priv->width)
840 g_object_notify (G_OBJECT (cell), "width");
843 if (height != priv->height)
845 priv->height = height;
846 g_object_notify (G_OBJECT (cell), "height");
849 g_object_thaw_notify (G_OBJECT (cell));
854 * gtk_cell_renderer_get_fixed_size:
855 * @cell: A #GtkCellRenderer
856 * @width: (allow-none): location to fill in with the fixed width of the cell, or %NULL
857 * @height: (allow-none): location to fill in with the fixed height of the cell, or %NULL
859 * Fills in @width and @height with the appropriate size of @cell.
862 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
866 GtkCellRendererPrivate *priv;
868 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
873 *width = priv->width;
875 *height = priv->height;
879 * gtk_cell_renderer_set_alignment:
880 * @cell: A #GtkCellRenderer
881 * @xalign: the x alignment of the cell renderer
882 * @yalign: the y alignment of the cell renderer
884 * Sets the renderer's alignment within its available space.
889 gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
893 GtkCellRendererPrivate *priv;
895 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
896 g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
897 g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
901 if ((xalign != priv->xalign) || (yalign != priv->yalign))
903 g_object_freeze_notify (G_OBJECT (cell));
905 if (xalign != priv->xalign)
907 priv->xalign = xalign;
908 g_object_notify (G_OBJECT (cell), "xalign");
911 if (yalign != priv->yalign)
913 priv->yalign = yalign;
914 g_object_notify (G_OBJECT (cell), "yalign");
917 g_object_thaw_notify (G_OBJECT (cell));
922 * gtk_cell_renderer_get_alignment:
923 * @cell: A #GtkCellRenderer
924 * @xalign: (allow-none): location to fill in with the x alignment of the cell, or %NULL
925 * @yalign: (allow-none): location to fill in with the y alignment of the cell, or %NULL
927 * Fills in @xalign and @yalign with the appropriate values of @cell.
932 gtk_cell_renderer_get_alignment (GtkCellRenderer *cell,
936 GtkCellRendererPrivate *priv;
938 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
943 *xalign = priv->xalign;
945 *yalign = priv->yalign;
949 * gtk_cell_renderer_set_padding:
950 * @cell: A #GtkCellRenderer
951 * @xpad: the x padding of the cell renderer
952 * @ypad: the y padding of the cell renderer
954 * Sets the renderer's padding.
959 gtk_cell_renderer_set_padding (GtkCellRenderer *cell,
963 GtkCellRendererPrivate *priv;
965 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
966 g_return_if_fail (xpad >= 0 && xpad >= 0);
970 if ((xpad != priv->xpad) || (ypad != priv->ypad))
972 g_object_freeze_notify (G_OBJECT (cell));
974 if (xpad != priv->xpad)
977 g_object_notify (G_OBJECT (cell), "xpad");
980 if (ypad != priv->ypad)
983 g_object_notify (G_OBJECT (cell), "ypad");
986 g_object_thaw_notify (G_OBJECT (cell));
991 * gtk_cell_renderer_get_padding:
992 * @cell: A #GtkCellRenderer
993 * @xpad: (allow-none): location to fill in with the x padding of the cell, or %NULL
994 * @ypad: (allow-none): location to fill in with the y padding of the cell, or %NULL
996 * Fills in @xpad and @ypad with the appropriate values of @cell.
1001 gtk_cell_renderer_get_padding (GtkCellRenderer *cell,
1005 GtkCellRendererPrivate *priv;
1007 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1018 * gtk_cell_renderer_set_visible:
1019 * @cell: A #GtkCellRenderer
1020 * @visible: the visibility of the cell
1022 * Sets the cell renderer's visibility.
1027 gtk_cell_renderer_set_visible (GtkCellRenderer *cell,
1030 GtkCellRendererPrivate *priv;
1032 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1036 if (priv->visible != visible)
1038 priv->visible = visible ? TRUE : FALSE;
1039 g_object_notify (G_OBJECT (cell), "visible");
1044 * gtk_cell_renderer_get_visible:
1045 * @cell: A #GtkCellRenderer
1047 * Returns the cell renderer's visibility.
1049 * Returns: %TRUE if the cell renderer is visible
1054 gtk_cell_renderer_get_visible (GtkCellRenderer *cell)
1056 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1058 return cell->priv->visible;
1062 * gtk_cell_renderer_set_sensitive:
1063 * @cell: A #GtkCellRenderer
1064 * @sensitive: the sensitivity of the cell
1066 * Sets the cell renderer's sensitivity.
1071 gtk_cell_renderer_set_sensitive (GtkCellRenderer *cell,
1074 GtkCellRendererPrivate *priv;
1076 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1080 if (priv->sensitive != sensitive)
1082 priv->sensitive = sensitive ? TRUE : FALSE;
1083 g_object_notify (G_OBJECT (cell), "sensitive");
1088 * gtk_cell_renderer_get_sensitive:
1089 * @cell: A #GtkCellRenderer
1091 * Returns the cell renderer's sensitivity.
1093 * Returns: %TRUE if the cell renderer is sensitive
1098 gtk_cell_renderer_get_sensitive (GtkCellRenderer *cell)
1100 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1102 return cell->priv->sensitive;
1107 * gtk_cell_renderer_is_activatable:
1108 * @cell: A #GtkCellRenderer
1110 * Checks whether the cell renderer can do something when activated.
1112 * Returns: %TRUE if the cell renderer can do anything when activated.
1117 gtk_cell_renderer_is_activatable (GtkCellRenderer *cell)
1119 GtkCellRendererPrivate *priv;
1121 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1125 return (cell->priv->visible &&
1126 (cell->priv->mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1127 cell->priv->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE));
1132 * gtk_cell_renderer_stop_editing:
1133 * @cell: A #GtkCellRenderer
1134 * @canceled: %TRUE if the editing has been canceled
1136 * Informs the cell renderer that the editing is stopped.
1137 * If @canceled is %TRUE, the cell renderer will emit the
1138 * #GtkCellRenderer::editing-canceled signal.
1140 * This function should be called by cell renderer implementations
1141 * in response to the #GtkCellEditable::editing-done signal of
1147 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1150 GtkCellRendererPrivate *priv;
1152 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1158 priv->editing = FALSE;
1160 g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1165 gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer *cell,
1167 GtkOrientation orientation,
1171 GtkRequisition min_req;
1173 /* Fallback on the old API to get the size. */
1174 if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size)
1175 GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL,
1176 &min_req.width, &min_req.height);
1183 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1186 *minimum_size = min_req.width;
1189 *natural_size = min_req.width;
1194 *minimum_size = min_req.height;
1197 *natural_size = min_req.height;
1202 gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
1207 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL,
1208 minimum_size, natural_size);
1212 gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
1217 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL,
1218 minimum_size, natural_size);
1223 gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
1226 gint *minimum_height,
1227 gint *natural_height)
1229 /* Fall back on the height reported from ->get_size() */
1230 gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
1234 gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
1237 gint *minimum_width,
1238 gint *natural_width)
1240 /* Fall back on the width reported from ->get_size() */
1241 gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
1245 /* Default implementation assumes that a cell renderer will never use more
1246 * space than it's natural size (this is fine for toggles and pixbufs etc
1247 * but needs to be overridden from wrapping/ellipsizing text renderers) */
1249 gtk_cell_renderer_real_get_aligned_area (GtkCellRenderer *cell,
1251 GtkCellRendererState flags,
1252 const GdkRectangle *cell_area,
1253 GdkRectangle *aligned_area)
1255 gint opposite_size, x_offset, y_offset;
1258 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1259 g_return_if_fail (GTK_IS_WIDGET (widget));
1260 g_return_if_fail (cell_area != NULL);
1261 g_return_if_fail (aligned_area != NULL);
1263 *aligned_area = *cell_area;
1265 /* Trim up the aligned size */
1266 if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1268 gtk_cell_renderer_get_preferred_width (cell, widget,
1269 NULL, &natural_size);
1271 aligned_area->width = MIN (aligned_area->width, natural_size);
1273 gtk_cell_renderer_get_preferred_height_for_width (cell, widget,
1274 aligned_area->width,
1275 NULL, &opposite_size);
1277 aligned_area->height = MIN (opposite_size, aligned_area->height);
1281 gtk_cell_renderer_get_preferred_height (cell, widget,
1282 NULL, &natural_size);
1284 aligned_area->height = MIN (aligned_area->width, natural_size);
1286 gtk_cell_renderer_get_preferred_width_for_height (cell, widget,
1287 aligned_area->height,
1288 NULL, &opposite_size);
1290 aligned_area->width = MIN (opposite_size, aligned_area->width);
1293 /* offset the cell position */
1294 _gtk_cell_renderer_calc_offset (cell, cell_area,
1295 gtk_widget_get_direction (widget),
1296 aligned_area->width,
1297 aligned_area->height,
1298 &x_offset, &y_offset);
1300 aligned_area->x += x_offset;
1301 aligned_area->y += y_offset;
1305 /* An internal convenience function for some containers to peek at the
1306 * cell alignment in a target allocation (used to draw focus and align
1307 * cells in the icon view).
1309 * Note this is only a trivial 'align * (allocation - request)' operation.
1312 _gtk_cell_renderer_calc_offset (GtkCellRenderer *cell,
1313 const GdkRectangle *cell_area,
1314 GtkTextDirection direction,
1320 GtkCellRendererPrivate *priv;
1322 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1323 g_return_if_fail (cell_area != NULL);
1324 g_return_if_fail (x_offset || y_offset);
1330 *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
1331 (1.0 - priv->xalign) : priv->xalign) *
1332 (cell_area->width - width));
1333 *x_offset = MAX (*x_offset, 0);
1337 *y_offset = (priv->yalign *
1338 (cell_area->height - height));
1339 *y_offset = MAX (*y_offset, 0);
1344 * gtk_cell_renderer_get_request_mode:
1345 * @cell: a #GtkCellRenderer instance
1347 * Gets whether the cell renderer prefers a height-for-width layout
1348 * or a width-for-height layout.
1350 * Returns: The #GtkSizeRequestMode preferred by this renderer.
1355 gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
1357 GtkCellRendererClass *klass;
1359 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1361 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1362 if (klass->get_request_mode)
1363 return klass->get_request_mode (cell);
1365 /* By default cell renderers are height-for-width. */
1366 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1370 * gtk_cell_renderer_get_preferred_width:
1371 * @cell: a #GtkCellRenderer instance
1372 * @widget: the #GtkWidget this cell will be rendering to
1373 * @minimum_size: location to store the minimum size, or %NULL
1374 * @natural_size: location to store the natural size, or %NULL
1376 * Retreives a renderer's natural size when rendered to @widget.
1381 gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
1386 GtkCellRendererClass *klass;
1389 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1390 g_return_if_fail (GTK_IS_WIDGET (widget));
1391 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1393 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1397 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1398 klass->get_preferred_width (cell, widget, minimum_size, natural_size);
1403 *minimum_size = width;
1405 *natural_size = width;
1408 #if DEBUG_CELL_SIZE_REQUEST
1409 g_message ("%s returning minimum width: %d and natural width: %d",
1410 G_OBJECT_TYPE_NAME (cell),
1411 minimum_size ? *minimum_size : 20000,
1412 natural_size ? *natural_size : 20000);
1418 * gtk_cell_renderer_get_preferred_height:
1419 * @cell: a #GtkCellRenderer instance
1420 * @widget: the #GtkWidget this cell will be rendering to
1421 * @minimum_size: location to store the minimum size, or %NULL
1422 * @natural_size: location to store the natural size, or %NULL
1424 * Retreives a renderer's natural size when rendered to @widget.
1429 gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
1434 GtkCellRendererClass *klass;
1437 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1438 g_return_if_fail (GTK_IS_WIDGET (widget));
1439 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1441 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1445 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1446 klass->get_preferred_height (cell, widget, minimum_size, natural_size);
1451 *minimum_size = height;
1453 *natural_size = height;
1456 #if DEBUG_CELL_SIZE_REQUEST
1457 g_message ("%s returning minimum height: %d and natural height: %d",
1458 G_OBJECT_TYPE_NAME (cell),
1459 minimum_size ? *minimum_size : 20000,
1460 natural_size ? *natural_size : 20000);
1466 * gtk_cell_renderer_get_preferred_width_for_height:
1467 * @cell: a #GtkCellRenderer instance
1468 * @widget: the #GtkWidget this cell will be rendering to
1469 * @height: the size which is available for allocation
1470 * @minimum_width: location for storing the minimum size, or %NULL
1471 * @natural_width: location for storing the preferred size, or %NULL
1473 * Retreives a cell renderers's minimum and natural width if it were rendered to
1474 * @widget with the specified @height.
1479 gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
1482 gint *minimum_width,
1483 gint *natural_width)
1485 GtkCellRendererClass *klass;
1488 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1489 g_return_if_fail (GTK_IS_WIDGET (widget));
1490 g_return_if_fail (NULL != minimum_width || NULL != natural_width);
1492 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1496 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1497 klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
1502 *minimum_width = width;
1504 *natural_width = width;
1507 #if DEBUG_CELL_SIZE_REQUEST
1508 g_message ("%s width for height: %d is minimum %d and natural: %d",
1509 G_OBJECT_TYPE_NAME (cell), height,
1510 minimum_width ? *minimum_width : 20000,
1511 natural_width ? *natural_width : 20000);
1516 * gtk_cell_renderer_get_preferred_height_for_width:
1517 * @cell: a #GtkCellRenderer instance
1518 * @widget: the #GtkWidget this cell will be rendering to
1519 * @width: the size which is available for allocation
1520 * @minimum_height: location for storing the minimum size, or %NULL
1521 * @natural_height: location for storing the preferred size, or %NULL
1523 * Retreives a cell renderers's minimum and natural height if it were rendered to
1524 * @widget with the specified @width.
1529 gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
1532 gint *minimum_height,
1533 gint *natural_height)
1535 GtkCellRendererClass *klass;
1538 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1539 g_return_if_fail (GTK_IS_WIDGET (widget));
1540 g_return_if_fail (NULL != minimum_height || NULL != natural_height);
1542 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1546 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1547 klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
1552 *minimum_height = height;
1554 *natural_height = height;
1557 #if DEBUG_CELL_SIZE_REQUEST
1558 g_message ("%s height for width: %d is minimum %d and natural: %d",
1559 G_OBJECT_TYPE_NAME (cell), width,
1560 minimum_height ? *minimum_height : 20000,
1561 natural_height ? *natural_height : 20000);
1566 * gtk_cell_renderer_get_preferred_size:
1567 * @cell: a #GtkCellRenderer instance
1568 * @widget: the #GtkWidget this cell will be rendering to
1569 * @request_natural: Whether to base the contextual request off of the
1570 * base natural or the base minimum
1571 * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
1572 * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
1574 * Retrieves the minimum and natural size of a cell taking
1575 * into account the widget's preference for height-for-width management.
1577 * If request_natural is specified, the non-contextual natural value will
1578 * be used to make the contextual request; otherwise the minimum will be used.
1583 gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
1585 GtkRequisition *minimum_size,
1586 GtkRequisition *natural_size)
1588 gint min_width, nat_width;
1589 gint min_height, nat_height;
1591 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1593 if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1595 gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
1599 minimum_size->width = min_width;
1600 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
1601 &minimum_size->height, NULL);
1606 natural_size->width = nat_width;
1607 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
1608 NULL, &natural_size->height);
1611 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1613 gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
1617 minimum_size->height = min_height;
1618 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
1619 &minimum_size->width, NULL);
1624 natural_size->height = nat_height;
1625 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
1626 NULL, &natural_size->width);
1632 * gtk_cell_renderer_get_aligned_area:
1633 * @cell: a #GtkCellRenderer instance
1634 * @widget: the #GtkWidget this cell will be rendering to
1635 * @flags: render flags
1636 * @cell_area: cell area which would be passed to gtk_cell_renderer_render()
1637 * @aligned_area: the return location for the space inside @cell_area that
1638 * would acually be used to render.
1640 * Gets the aligned area used by @cell inside @cell_area. Used for finding
1641 * the appropriate edit and focus rectangle.
1646 gtk_cell_renderer_get_aligned_area (GtkCellRenderer *cell,
1648 GtkCellRendererState flags,
1649 const GdkRectangle *cell_area,
1650 GdkRectangle *aligned_area)
1652 GtkCellRendererClass *klass;
1654 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1655 g_return_if_fail (GTK_IS_WIDGET (widget));
1656 g_return_if_fail (cell_area != NULL);
1657 g_return_if_fail (aligned_area != NULL);
1659 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1660 klass->get_aligned_area (cell, widget, flags, cell_area, aligned_area);