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,
103 struct _GtkCellRendererPrivate
116 guint is_expander : 1;
117 guint is_expanded : 1;
118 guint cell_background_set : 1;
122 GdkRGBA cell_background;
139 PROP_CELL_BACKGROUND,
140 PROP_CELL_BACKGROUND_GDK,
141 PROP_CELL_BACKGROUND_RGBA,
142 PROP_CELL_BACKGROUND_SET,
153 static guint cell_renderer_signals[LAST_SIGNAL] = { 0 };
155 G_DEFINE_ABSTRACT_TYPE(GtkCellRenderer, gtk_cell_renderer, G_TYPE_INITIALLY_UNOWNED)
158 gtk_cell_renderer_init (GtkCellRenderer *cell)
160 GtkCellRendererPrivate *priv;
162 cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
163 GTK_TYPE_CELL_RENDERER,
164 GtkCellRendererPrivate);
167 priv->mode = GTK_CELL_RENDERER_MODE_INERT;
168 priv->visible = TRUE;
175 priv->sensitive = TRUE;
176 priv->is_expander = FALSE;
177 priv->is_expanded = FALSE;
178 priv->editing = FALSE;
182 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
184 GObjectClass *object_class = G_OBJECT_CLASS (class);
186 object_class->get_property = gtk_cell_renderer_get_property;
187 object_class->set_property = gtk_cell_renderer_set_property;
189 class->render = NULL;
190 class->get_size = NULL;
191 class->get_preferred_width = gtk_cell_renderer_real_get_preferred_width;
192 class->get_preferred_height = gtk_cell_renderer_real_get_preferred_height;
193 class->get_preferred_width_for_height = gtk_cell_renderer_real_get_preferred_width_for_height;
194 class->get_preferred_height_for_width = gtk_cell_renderer_real_get_preferred_height_for_width;
197 * GtkCellRenderer::editing-canceled:
198 * @renderer: the object which received the signal
200 * This signal gets emitted when the user cancels the process of editing a
201 * cell. For example, an editable cell renderer could be written to cancel
202 * editing when the user presses Escape.
204 * See also: gtk_cell_renderer_stop_editing().
208 cell_renderer_signals[EDITING_CANCELED] =
209 g_signal_new (I_("editing-canceled"),
210 G_OBJECT_CLASS_TYPE (object_class),
212 G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
214 _gtk_marshal_VOID__VOID,
218 * GtkCellRenderer::editing-started:
219 * @renderer: the object which received the signal
220 * @editable: the #GtkCellEditable
221 * @path: the path identifying the edited cell
223 * This signal gets emitted when a cell starts to be edited.
224 * The intended use of this signal is to do special setup
225 * on @editable, e.g. adding a #GtkEntryCompletion or setting
226 * up additional columns in a #GtkComboBox.
228 * Note that GTK+ doesn't guarantee that cell renderers will
229 * continue to use the same kind of widget for editing in future
230 * releases, therefore you should check the type of @editable
231 * before doing any specific setup, as in the following example:
234 * text_editing_started (GtkCellRenderer *cell,
235 * GtkCellEditable *editable,
239 * if (GTK_IS_ENTRY (editable))
241 * GtkEntry *entry = GTK_ENTRY (editable);
243 * /* ... create a GtkEntryCompletion */
245 * gtk_entry_set_completion (entry, completion);
252 cell_renderer_signals[EDITING_STARTED] =
253 g_signal_new (I_("editing-started"),
254 G_OBJECT_CLASS_TYPE (object_class),
256 G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
258 _gtk_marshal_VOID__OBJECT_STRING,
260 GTK_TYPE_CELL_EDITABLE,
263 g_object_class_install_property (object_class,
265 g_param_spec_enum ("mode",
267 P_("Editable mode of the CellRenderer"),
268 GTK_TYPE_CELL_RENDERER_MODE,
269 GTK_CELL_RENDERER_MODE_INERT,
270 GTK_PARAM_READWRITE));
272 g_object_class_install_property (object_class,
274 g_param_spec_boolean ("visible",
276 P_("Display the cell"),
278 GTK_PARAM_READWRITE));
279 g_object_class_install_property (object_class,
281 g_param_spec_boolean ("sensitive",
283 P_("Display the cell sensitive"),
285 GTK_PARAM_READWRITE));
287 g_object_class_install_property (object_class,
289 g_param_spec_float ("xalign",
295 GTK_PARAM_READWRITE));
297 g_object_class_install_property (object_class,
299 g_param_spec_float ("yalign",
305 GTK_PARAM_READWRITE));
307 g_object_class_install_property (object_class,
309 g_param_spec_uint ("xpad",
315 GTK_PARAM_READWRITE));
317 g_object_class_install_property (object_class,
319 g_param_spec_uint ("ypad",
325 GTK_PARAM_READWRITE));
327 g_object_class_install_property (object_class,
329 g_param_spec_int ("width",
331 P_("The fixed width"),
335 GTK_PARAM_READWRITE));
337 g_object_class_install_property (object_class,
339 g_param_spec_int ("height",
341 P_("The fixed height"),
345 GTK_PARAM_READWRITE));
347 g_object_class_install_property (object_class,
349 g_param_spec_boolean ("is-expander",
351 P_("Row has children"),
353 GTK_PARAM_READWRITE));
356 g_object_class_install_property (object_class,
358 g_param_spec_boolean ("is-expanded",
360 P_("Row is an expander row, and is expanded"),
362 GTK_PARAM_READWRITE));
364 g_object_class_install_property (object_class,
365 PROP_CELL_BACKGROUND,
366 g_param_spec_string ("cell-background",
367 P_("Cell background color name"),
368 P_("Cell background color as a string"),
370 GTK_PARAM_WRITABLE));
372 g_object_class_install_property (object_class,
373 PROP_CELL_BACKGROUND_GDK,
374 g_param_spec_boxed ("cell-background-gdk",
375 P_("Cell background color"),
376 P_("Cell background color as a GdkColor"),
378 GTK_PARAM_READWRITE));
380 * GtkCellRenderer:cell-background-rgba:
382 * Cell background as a #GdkRGBA
386 g_object_class_install_property (object_class,
387 PROP_CELL_BACKGROUND_RGBA,
388 g_param_spec_boxed ("cell-background-rgba",
389 P_("Cell background RGBA color"),
390 P_("Cell background color as a GdkRGBA"),
392 GTK_PARAM_READWRITE));
394 g_object_class_install_property (object_class,
396 g_param_spec_boolean ("editing",
398 P_("Whether the cell renderer is currently in editing mode"),
400 GTK_PARAM_READABLE));
403 #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))
405 ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
406 P_("Cell background set"),
407 P_("Whether this tag affects the cell background color"));
409 g_type_class_add_private (class, sizeof (GtkCellRendererPrivate));
413 gtk_cell_renderer_get_property (GObject *object,
418 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
419 GtkCellRendererPrivate *priv = cell->priv;
424 g_value_set_enum (value, priv->mode);
427 g_value_set_boolean (value, priv->visible);
430 g_value_set_boolean (value, priv->sensitive);
433 g_value_set_boolean (value, priv->editing);
436 g_value_set_float (value, priv->xalign);
439 g_value_set_float (value, priv->yalign);
442 g_value_set_uint (value, priv->xpad);
445 g_value_set_uint (value, priv->ypad);
448 g_value_set_int (value, priv->width);
451 g_value_set_int (value, priv->height);
453 case PROP_IS_EXPANDER:
454 g_value_set_boolean (value, priv->is_expander);
456 case PROP_IS_EXPANDED:
457 g_value_set_boolean (value, priv->is_expanded);
459 case PROP_CELL_BACKGROUND_GDK:
463 color.red = (guint16) (priv->cell_background.red * 65535);
464 color.green = (guint16) (priv->cell_background.green * 65535);
465 color.blue = (guint16) (priv->cell_background.blue * 65535);
467 g_value_set_boxed (value, &color);
470 case PROP_CELL_BACKGROUND_RGBA:
471 g_value_set_boxed (value, &priv->cell_background);
473 case PROP_CELL_BACKGROUND_SET:
474 g_value_set_boolean (value, priv->cell_background_set);
476 case PROP_CELL_BACKGROUND:
478 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
485 gtk_cell_renderer_set_property (GObject *object,
490 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
491 GtkCellRendererPrivate *priv = cell->priv;
496 priv->mode = g_value_get_enum (value);
499 priv->visible = g_value_get_boolean (value);
502 priv->sensitive = g_value_get_boolean (value);
505 priv->editing = g_value_get_boolean (value);
508 priv->xalign = g_value_get_float (value);
511 priv->yalign = g_value_get_float (value);
514 priv->xpad = g_value_get_uint (value);
517 priv->ypad = g_value_get_uint (value);
520 priv->width = g_value_get_int (value);
523 priv->height = g_value_get_int (value);
525 case PROP_IS_EXPANDER:
526 priv->is_expander = g_value_get_boolean (value);
528 case PROP_IS_EXPANDED:
529 priv->is_expanded = g_value_get_boolean (value);
531 case PROP_CELL_BACKGROUND:
535 if (!g_value_get_string (value))
536 set_cell_bg_color (cell, NULL);
537 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
538 set_cell_bg_color (cell, &rgba);
540 g_warning ("Don't know color `%s'", g_value_get_string (value));
542 g_object_notify (object, "cell-background-gdk");
545 case PROP_CELL_BACKGROUND_GDK:
549 color = g_value_get_boxed (value);
554 rgba.red = color->red / 65535.;
555 rgba.green = color->green / 65535.;
556 rgba.blue = color->blue / 65535.;
559 set_cell_bg_color (cell, &rgba);
563 set_cell_bg_color (cell, NULL);
567 case PROP_CELL_BACKGROUND_RGBA:
568 set_cell_bg_color (cell, g_value_get_boxed (value));
570 case PROP_CELL_BACKGROUND_SET:
571 priv->cell_background_set = g_value_get_boolean (value);
574 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
580 set_cell_bg_color (GtkCellRenderer *cell,
583 GtkCellRendererPrivate *priv = cell->priv;
587 if (!priv->cell_background_set)
589 priv->cell_background_set = TRUE;
590 g_object_notify (G_OBJECT (cell), "cell-background-set");
593 priv->cell_background = *rgba;
597 if (priv->cell_background_set)
599 priv->cell_background_set = FALSE;
600 g_object_notify (G_OBJECT (cell), "cell-background-set");
606 * gtk_cell_renderer_get_size:
607 * @cell: a #GtkCellRenderer
608 * @widget: the widget the renderer is rendering to
609 * @cell_area: (allow-none): The area a cell will be allocated, or %NULL
610 * @x_offset: (allow-none): location to return x offset of cell relative to @cell_area, or %NULL
611 * @y_offset: (allow-none): location to return y offset of cell relative to @cell_area, or %NULL
612 * @width: (allow-none): location to return width needed to render a cell, or %NULL
613 * @height: (allow-none): location to return height needed to render a cell, or %NULL
615 * Obtains the width and height needed to render the cell. Used by view
616 * widgets to determine the appropriate size for the cell_area passed to
617 * gtk_cell_renderer_render(). If @cell_area is not %NULL, fills in the
618 * x and y offsets (if set) of the cell relative to this location.
620 * Please note that the values set in @width and @height, as well as those
621 * in @x_offset and @y_offset are inclusive of the xpad and ypad properties.
624 * Deprecated: 3.0: Use gtk_cell_renderer_get_preferred_size() instead.
627 gtk_cell_renderer_get_size (GtkCellRenderer *cell,
629 const GdkRectangle *cell_area,
635 GtkRequisition request;
637 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
639 gtk_cell_renderer_get_preferred_size (cell, widget, &request, NULL);
642 *width = request.width;
645 *height = request.height;
648 _gtk_cell_renderer_calc_offset (cell, cell_area, gtk_widget_get_direction (widget),
649 request.width, request.height, x_offset, y_offset);
653 * gtk_cell_renderer_render:
654 * @cell: a #GtkCellRenderer
655 * @cr: a cairo context to draw to
656 * @widget: the widget owning @window
657 * @background_area: entire cell area (including tree expanders and maybe
658 * padding on the sides)
659 * @cell_area: area normally rendered by a cell renderer
660 * @flags: flags that affect rendering
662 * Invokes the virtual render function of the #GtkCellRenderer. The three
663 * passed-in rectangles are areas in @cr. Most renderers will draw within
664 * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
665 * should be honored with respect to @cell_area. @background_area includes the
666 * blank space around the cell, and also the area containing the tree expander;
667 * so the @background_area rectangles for all cells tile to cover the entire
671 gtk_cell_renderer_render (GtkCellRenderer *cell,
674 const GdkRectangle *background_area,
675 const GdkRectangle *cell_area,
676 GtkCellRendererState flags)
678 gboolean selected = FALSE;
679 GtkCellRendererPrivate *priv = cell->priv;
681 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
682 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
683 g_return_if_fail (cr != NULL);
685 selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
689 if (priv->cell_background_set && !selected)
691 gdk_cairo_rectangle (cr, background_area);
692 gdk_cairo_set_source_rgba (cr, &priv->cell_background);
696 GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
707 * gtk_cell_renderer_activate:
708 * @cell: a #GtkCellRenderer
709 * @event: a #GdkEvent
710 * @widget: widget that received the event
711 * @path: widget-dependent string representation of the event location;
712 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
713 * @background_area: background area as passed to gtk_cell_renderer_render()
714 * @cell_area: cell area as passed to gtk_cell_renderer_render()
715 * @flags: render flags
717 * Passes an activate event to the cell renderer for possible processing.
718 * Some cell renderers may use events; for example, #GtkCellRendererToggle
719 * toggles when it gets a mouse click.
721 * Return value: %TRUE if the event was consumed/handled
724 gtk_cell_renderer_activate (GtkCellRenderer *cell,
728 const GdkRectangle *background_area,
729 const GdkRectangle *cell_area,
730 GtkCellRendererState flags)
732 GtkCellRendererPrivate *priv;
734 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
738 if (priv->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
741 if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
744 return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
748 (GdkRectangle *) background_area,
749 (GdkRectangle *) cell_area,
754 * gtk_cell_renderer_start_editing:
755 * @cell: a #GtkCellRenderer
756 * @event: a #GdkEvent
757 * @widget: widget that received the event
758 * @path: widget-dependent string representation of the event location;
759 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
760 * @background_area: background area as passed to gtk_cell_renderer_render()
761 * @cell_area: cell area as passed to gtk_cell_renderer_render()
762 * @flags: render flags
764 * Passes an activate event to the cell renderer for possible processing.
766 * Return value: (transfer full): A new #GtkCellEditable, or %NULL
769 gtk_cell_renderer_start_editing (GtkCellRenderer *cell,
773 const GdkRectangle *background_area,
774 const GdkRectangle *cell_area,
775 GtkCellRendererState flags)
778 GtkCellRendererPrivate *priv;
779 GtkCellEditable *editable;
781 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
785 if (priv->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
788 if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
791 editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
795 (GdkRectangle *) background_area,
796 (GdkRectangle *) cell_area,
800 cell_renderer_signals[EDITING_STARTED], 0,
803 priv->editing = TRUE;
809 * gtk_cell_renderer_set_fixed_size:
810 * @cell: A #GtkCellRenderer
811 * @width: the width of the cell renderer, or -1
812 * @height: the height of the cell renderer, or -1
814 * Sets the renderer size to be explicit, independent of the properties set.
817 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
821 GtkCellRendererPrivate *priv;
823 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
824 g_return_if_fail (width >= -1 && height >= -1);
828 if ((width != priv->width) || (height != priv->height))
830 g_object_freeze_notify (G_OBJECT (cell));
832 if (width != priv->width)
835 g_object_notify (G_OBJECT (cell), "width");
838 if (height != priv->height)
840 priv->height = height;
841 g_object_notify (G_OBJECT (cell), "height");
844 g_object_thaw_notify (G_OBJECT (cell));
849 * gtk_cell_renderer_get_fixed_size:
850 * @cell: A #GtkCellRenderer
851 * @width: (allow-none): location to fill in with the fixed width of the cell, or %NULL
852 * @height: (allow-none): location to fill in with the fixed height of the cell, or %NULL
854 * Fills in @width and @height with the appropriate size of @cell.
857 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
861 GtkCellRendererPrivate *priv;
863 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
868 *width = priv->width;
870 *height = priv->height;
874 * gtk_cell_renderer_set_alignment:
875 * @cell: A #GtkCellRenderer
876 * @xalign: the x alignment of the cell renderer
877 * @yalign: the y alignment of the cell renderer
879 * Sets the renderer's alignment within its available space.
884 gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
888 GtkCellRendererPrivate *priv;
890 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
891 g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
892 g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
896 if ((xalign != priv->xalign) || (yalign != priv->yalign))
898 g_object_freeze_notify (G_OBJECT (cell));
900 if (xalign != priv->xalign)
902 priv->xalign = xalign;
903 g_object_notify (G_OBJECT (cell), "xalign");
906 if (yalign != priv->yalign)
908 priv->yalign = yalign;
909 g_object_notify (G_OBJECT (cell), "yalign");
912 g_object_thaw_notify (G_OBJECT (cell));
917 * gtk_cell_renderer_get_alignment:
918 * @cell: A #GtkCellRenderer
919 * @xalign: (allow-none): location to fill in with the x alignment of the cell, or %NULL
920 * @yalign: (allow-none): location to fill in with the y alignment of the cell, or %NULL
922 * Fills in @xalign and @yalign with the appropriate values of @cell.
927 gtk_cell_renderer_get_alignment (GtkCellRenderer *cell,
931 GtkCellRendererPrivate *priv;
933 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
938 *xalign = priv->xalign;
940 *yalign = priv->yalign;
944 * gtk_cell_renderer_set_padding:
945 * @cell: A #GtkCellRenderer
946 * @xpad: the x padding of the cell renderer
947 * @ypad: the y padding of the cell renderer
949 * Sets the renderer's padding.
954 gtk_cell_renderer_set_padding (GtkCellRenderer *cell,
958 GtkCellRendererPrivate *priv;
960 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
961 g_return_if_fail (xpad >= 0 && xpad >= 0);
965 if ((xpad != priv->xpad) || (ypad != priv->ypad))
967 g_object_freeze_notify (G_OBJECT (cell));
969 if (xpad != priv->xpad)
972 g_object_notify (G_OBJECT (cell), "xpad");
975 if (ypad != priv->ypad)
978 g_object_notify (G_OBJECT (cell), "ypad");
981 g_object_thaw_notify (G_OBJECT (cell));
986 * gtk_cell_renderer_get_padding:
987 * @cell: A #GtkCellRenderer
988 * @xpad: (allow-none): location to fill in with the x padding of the cell, or %NULL
989 * @ypad: (allow-none): location to fill in with the y padding of the cell, or %NULL
991 * Fills in @xpad and @ypad with the appropriate values of @cell.
996 gtk_cell_renderer_get_padding (GtkCellRenderer *cell,
1000 GtkCellRendererPrivate *priv;
1002 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1013 * gtk_cell_renderer_set_visible:
1014 * @cell: A #GtkCellRenderer
1015 * @visible: the visibility of the cell
1017 * Sets the cell renderer's visibility.
1022 gtk_cell_renderer_set_visible (GtkCellRenderer *cell,
1025 GtkCellRendererPrivate *priv;
1027 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1031 if (priv->visible != visible)
1033 priv->visible = visible ? TRUE : FALSE;
1034 g_object_notify (G_OBJECT (cell), "visible");
1039 * gtk_cell_renderer_get_visible:
1040 * @cell: A #GtkCellRenderer
1042 * Returns the cell renderer's visibility.
1044 * Returns: %TRUE if the cell renderer is visible
1049 gtk_cell_renderer_get_visible (GtkCellRenderer *cell)
1051 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1053 return cell->priv->visible;
1057 * gtk_cell_renderer_set_sensitive:
1058 * @cell: A #GtkCellRenderer
1059 * @sensitive: the sensitivity of the cell
1061 * Sets the cell renderer's sensitivity.
1066 gtk_cell_renderer_set_sensitive (GtkCellRenderer *cell,
1069 GtkCellRendererPrivate *priv;
1071 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1075 if (priv->sensitive != sensitive)
1077 priv->sensitive = sensitive ? TRUE : FALSE;
1078 g_object_notify (G_OBJECT (cell), "sensitive");
1083 * gtk_cell_renderer_get_sensitive:
1084 * @cell: A #GtkCellRenderer
1086 * Returns the cell renderer's sensitivity.
1088 * Returns: %TRUE if the cell renderer is sensitive
1093 gtk_cell_renderer_get_sensitive (GtkCellRenderer *cell)
1095 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1097 return cell->priv->sensitive;
1101 * gtk_cell_renderer_stop_editing:
1102 * @cell: A #GtkCellRenderer
1103 * @canceled: %TRUE if the editing has been canceled
1105 * Informs the cell renderer that the editing is stopped.
1106 * If @canceled is %TRUE, the cell renderer will emit the
1107 * #GtkCellRenderer::editing-canceled signal.
1109 * This function should be called by cell renderer implementations
1110 * in response to the #GtkCellEditable::editing-done signal of
1116 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1119 GtkCellRendererPrivate *priv;
1121 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1127 priv->editing = FALSE;
1129 g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1134 gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer *cell,
1136 GtkOrientation orientation,
1140 GtkRequisition min_req;
1142 /* Fallback on the old API to get the size. */
1143 if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size)
1144 GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL,
1145 &min_req.width, &min_req.height);
1152 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1155 *minimum_size = min_req.width;
1158 *natural_size = min_req.width;
1163 *minimum_size = min_req.height;
1166 *natural_size = min_req.height;
1171 gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
1176 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL,
1177 minimum_size, natural_size);
1181 gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
1186 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL,
1187 minimum_size, natural_size);
1192 gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
1195 gint *minimum_height,
1196 gint *natural_height)
1198 /* Fall back on the height reported from ->get_size() */
1199 gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
1203 gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
1206 gint *minimum_width,
1207 gint *natural_width)
1209 /* Fall back on the width reported from ->get_size() */
1210 gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
1213 /* An internal convenience function for some containers to peek at the
1214 * cell alignment in a target allocation (used to draw focus and align
1215 * cells in the icon view).
1217 * Note this is only a trivial 'align * (allocation - request)' operation.
1220 _gtk_cell_renderer_calc_offset (GtkCellRenderer *cell,
1221 const GdkRectangle *cell_area,
1222 GtkTextDirection direction,
1228 GtkCellRendererPrivate *priv;
1230 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1231 g_return_if_fail (cell_area != NULL);
1232 g_return_if_fail (x_offset || y_offset);
1238 *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
1239 (1.0 - priv->xalign) : priv->xalign) *
1240 (cell_area->width - width));
1241 *x_offset = MAX (*x_offset, 0);
1245 *y_offset = (priv->yalign *
1246 (cell_area->height - height));
1247 *y_offset = MAX (*y_offset, 0);
1252 * gtk_cell_renderer_get_request_mode:
1253 * @cell: a #GtkCellRenderer instance
1255 * Gets whether the cell renderer prefers a height-for-width layout
1256 * or a width-for-height layout.
1258 * Returns: The #GtkSizeRequestMode preferred by this renderer.
1263 gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
1265 GtkCellRendererClass *klass;
1267 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1269 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1270 if (klass->get_request_mode)
1271 return klass->get_request_mode (cell);
1273 /* By default cell renderers are height-for-width. */
1274 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1278 * gtk_cell_renderer_get_preferred_width:
1279 * @cell: a #GtkCellRenderer instance
1280 * @widget: the #GtkWidget this cell will be rendering to
1281 * @minimum_size: location to store the minimum size, or %NULL
1282 * @natural_size: location to store the natural size, or %NULL
1284 * Retreives a renderer's natural size when rendered to @widget.
1289 gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
1294 GtkCellRendererClass *klass;
1297 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1298 g_return_if_fail (GTK_IS_WIDGET (widget));
1299 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1301 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1305 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1306 klass->get_preferred_width (cell, widget, minimum_size, natural_size);
1311 *minimum_size = width;
1313 *natural_size = width;
1316 #if DEBUG_CELL_SIZE_REQUEST
1317 g_message ("%s returning minimum width: %d and natural width: %d",
1318 G_OBJECT_TYPE_NAME (cell),
1319 minimum_size ? *minimum_size : 20000,
1320 natural_size ? *natural_size : 20000);
1326 * gtk_cell_renderer_get_preferred_height:
1327 * @cell: a #GtkCellRenderer instance
1328 * @widget: the #GtkWidget this cell will be rendering to
1329 * @minimum_size: location to store the minimum size, or %NULL
1330 * @natural_size: location to store the natural size, or %NULL
1332 * Retreives a renderer's natural size when rendered to @widget.
1337 gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
1342 GtkCellRendererClass *klass;
1345 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1346 g_return_if_fail (GTK_IS_WIDGET (widget));
1347 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1349 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1353 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1354 klass->get_preferred_height (cell, widget, minimum_size, natural_size);
1359 *minimum_size = height;
1361 *natural_size = height;
1364 #if DEBUG_CELL_SIZE_REQUEST
1365 g_message ("%s returning minimum height: %d and natural height: %d",
1366 G_OBJECT_TYPE_NAME (cell),
1367 minimum_size ? *minimum_size : 20000,
1368 natural_size ? *natural_size : 20000);
1374 * gtk_cell_renderer_get_preferred_width_for_height:
1375 * @cell: a #GtkCellRenderer instance
1376 * @widget: the #GtkWidget this cell will be rendering to
1377 * @height: the size which is available for allocation
1378 * @minimum_width: location for storing the minimum size, or %NULL
1379 * @natural_width: location for storing the preferred size, or %NULL
1381 * Retreives a cell renderers's minimum and natural width if it were rendered to
1382 * @widget with the specified @height.
1387 gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
1390 gint *minimum_width,
1391 gint *natural_width)
1393 GtkCellRendererClass *klass;
1396 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1397 g_return_if_fail (GTK_IS_WIDGET (widget));
1398 g_return_if_fail (NULL != minimum_width || NULL != natural_width);
1400 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1404 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1405 klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
1410 *minimum_width = width;
1412 *natural_width = width;
1415 #if DEBUG_CELL_SIZE_REQUEST
1416 g_message ("%s width for height: %d is minimum %d and natural: %d",
1417 G_OBJECT_TYPE_NAME (cell), height,
1418 minimum_width ? *minimum_width : 20000,
1419 natural_width ? *natural_width : 20000);
1424 * gtk_cell_renderer_get_preferred_height_for_width:
1425 * @cell: a #GtkCellRenderer instance
1426 * @widget: the #GtkWidget this cell will be rendering to
1427 * @width: the size which is available for allocation
1428 * @minimum_height: location for storing the minimum size, or %NULL
1429 * @natural_height: location for storing the preferred size, or %NULL
1431 * Retreives a cell renderers's minimum and natural height if it were rendered to
1432 * @widget with the specified @width.
1437 gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
1440 gint *minimum_height,
1441 gint *natural_height)
1443 GtkCellRendererClass *klass;
1446 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1447 g_return_if_fail (GTK_IS_WIDGET (widget));
1448 g_return_if_fail (NULL != minimum_height || NULL != natural_height);
1450 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1454 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1455 klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
1460 *minimum_height = height;
1462 *natural_height = height;
1465 #if DEBUG_CELL_SIZE_REQUEST
1466 g_message ("%s height for width: %d is minimum %d and natural: %d",
1467 G_OBJECT_TYPE_NAME (cell), width,
1468 minimum_height ? *minimum_height : 20000,
1469 natural_height ? *natural_height : 20000);
1474 * gtk_cell_renderer_get_preferred_size:
1475 * @cell: a #GtkCellRenderer instance
1476 * @widget: the #GtkWidget this cell will be rendering to
1477 * @request_natural: Whether to base the contextual request off of the
1478 * base natural or the base minimum
1479 * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
1480 * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
1482 * Retrieves the minimum and natural size of a cell taking
1483 * into account the widget's preference for height-for-width management.
1485 * If request_natural is specified, the non-contextual natural value will
1486 * be used to make the contextual request; otherwise the minimum will be used.
1491 gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
1493 GtkRequisition *minimum_size,
1494 GtkRequisition *natural_size)
1496 gint min_width, nat_width;
1497 gint min_height, nat_height;
1499 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1501 if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1503 gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
1507 minimum_size->width = min_width;
1508 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
1509 &minimum_size->height, NULL);
1514 natural_size->width = nat_width;
1515 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
1516 NULL, &natural_size->height);
1519 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1521 gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
1525 minimum_size->height = min_height;
1526 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
1527 &minimum_size->width, NULL);
1532 natural_size->height = nat_height;
1533 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
1534 NULL, &natural_size->width);