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 (g_value_get_string (value), &rgba))
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;
1102 * gtk_cell_renderer_can_focus:
1103 * @cell: A #GtkCellRenderer
1105 * Checks whether the cell renderer can receive focus.
1107 * Returns: %TRUE if the cell renderer can do anything with keyboard focus
1112 gtk_cell_renderer_can_focus (GtkCellRenderer *cell)
1114 GtkCellRendererPrivate *priv;
1116 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1120 return (cell->priv->visible &&
1121 (cell->priv->mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1122 cell->priv->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE));
1127 * gtk_cell_renderer_stop_editing:
1128 * @cell: A #GtkCellRenderer
1129 * @canceled: %TRUE if the editing has been canceled
1131 * Informs the cell renderer that the editing is stopped.
1132 * If @canceled is %TRUE, the cell renderer will emit the
1133 * #GtkCellRenderer::editing-canceled signal.
1135 * This function should be called by cell renderer implementations
1136 * in response to the #GtkCellEditable::editing-done signal of
1142 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1145 GtkCellRendererPrivate *priv;
1147 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1153 priv->editing = FALSE;
1155 g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1160 gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer *cell,
1162 GtkOrientation orientation,
1166 GtkRequisition min_req;
1168 /* Fallback on the old API to get the size. */
1169 if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size)
1170 GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL,
1171 &min_req.width, &min_req.height);
1178 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1181 *minimum_size = min_req.width;
1184 *natural_size = min_req.width;
1189 *minimum_size = min_req.height;
1192 *natural_size = min_req.height;
1197 gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
1202 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL,
1203 minimum_size, natural_size);
1207 gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
1212 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL,
1213 minimum_size, natural_size);
1218 gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
1221 gint *minimum_height,
1222 gint *natural_height)
1224 /* Fall back on the height reported from ->get_size() */
1225 gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
1229 gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
1232 gint *minimum_width,
1233 gint *natural_width)
1235 /* Fall back on the width reported from ->get_size() */
1236 gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
1239 /* An internal convenience function for some containers to peek at the
1240 * cell alignment in a target allocation (used to draw focus and align
1241 * cells in the icon view).
1243 * Note this is only a trivial 'align * (allocation - request)' operation.
1246 _gtk_cell_renderer_calc_offset (GtkCellRenderer *cell,
1247 const GdkRectangle *cell_area,
1248 GtkTextDirection direction,
1254 GtkCellRendererPrivate *priv;
1256 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1257 g_return_if_fail (cell_area != NULL);
1258 g_return_if_fail (x_offset || y_offset);
1264 *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
1265 (1.0 - priv->xalign) : priv->xalign) *
1266 (cell_area->width - width));
1267 *x_offset = MAX (*x_offset, 0);
1271 *y_offset = (priv->yalign *
1272 (cell_area->height - height));
1273 *y_offset = MAX (*y_offset, 0);
1278 * gtk_cell_renderer_get_request_mode:
1279 * @cell: a #GtkCellRenderer instance
1281 * Gets whether the cell renderer prefers a height-for-width layout
1282 * or a width-for-height layout.
1284 * Returns: The #GtkSizeRequestMode preferred by this renderer.
1289 gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
1291 GtkCellRendererClass *klass;
1293 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1295 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1296 if (klass->get_request_mode)
1297 return klass->get_request_mode (cell);
1299 /* By default cell renderers are height-for-width. */
1300 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1304 * gtk_cell_renderer_get_preferred_width:
1305 * @cell: a #GtkCellRenderer instance
1306 * @widget: the #GtkWidget this cell will be rendering to
1307 * @minimum_size: location to store the minimum size, or %NULL
1308 * @natural_size: location to store the natural size, or %NULL
1310 * Retreives a renderer's natural size when rendered to @widget.
1315 gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
1320 GtkCellRendererClass *klass;
1323 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1324 g_return_if_fail (GTK_IS_WIDGET (widget));
1325 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1327 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1331 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1332 klass->get_preferred_width (cell, widget, minimum_size, natural_size);
1337 *minimum_size = width;
1339 *natural_size = width;
1342 #if DEBUG_CELL_SIZE_REQUEST
1343 g_message ("%s returning minimum width: %d and natural width: %d",
1344 G_OBJECT_TYPE_NAME (cell),
1345 minimum_size ? *minimum_size : 20000,
1346 natural_size ? *natural_size : 20000);
1352 * gtk_cell_renderer_get_preferred_height:
1353 * @cell: a #GtkCellRenderer instance
1354 * @widget: the #GtkWidget this cell will be rendering to
1355 * @minimum_size: location to store the minimum size, or %NULL
1356 * @natural_size: location to store the natural size, or %NULL
1358 * Retreives a renderer's natural size when rendered to @widget.
1363 gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
1368 GtkCellRendererClass *klass;
1371 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1372 g_return_if_fail (GTK_IS_WIDGET (widget));
1373 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1375 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1379 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1380 klass->get_preferred_height (cell, widget, minimum_size, natural_size);
1385 *minimum_size = height;
1387 *natural_size = height;
1390 #if DEBUG_CELL_SIZE_REQUEST
1391 g_message ("%s returning minimum height: %d and natural height: %d",
1392 G_OBJECT_TYPE_NAME (cell),
1393 minimum_size ? *minimum_size : 20000,
1394 natural_size ? *natural_size : 20000);
1400 * gtk_cell_renderer_get_preferred_width_for_height:
1401 * @cell: a #GtkCellRenderer instance
1402 * @widget: the #GtkWidget this cell will be rendering to
1403 * @height: the size which is available for allocation
1404 * @minimum_width: location for storing the minimum size, or %NULL
1405 * @natural_width: location for storing the preferred size, or %NULL
1407 * Retreives a cell renderers's minimum and natural width if it were rendered to
1408 * @widget with the specified @height.
1413 gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
1416 gint *minimum_width,
1417 gint *natural_width)
1419 GtkCellRendererClass *klass;
1422 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1423 g_return_if_fail (GTK_IS_WIDGET (widget));
1424 g_return_if_fail (NULL != minimum_width || NULL != natural_width);
1426 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1430 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1431 klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
1436 *minimum_width = width;
1438 *natural_width = width;
1441 #if DEBUG_CELL_SIZE_REQUEST
1442 g_message ("%s width for height: %d is minimum %d and natural: %d",
1443 G_OBJECT_TYPE_NAME (cell), height,
1444 minimum_width ? *minimum_width : 20000,
1445 natural_width ? *natural_width : 20000);
1450 * gtk_cell_renderer_get_preferred_height_for_width:
1451 * @cell: a #GtkCellRenderer instance
1452 * @widget: the #GtkWidget this cell will be rendering to
1453 * @width: the size which is available for allocation
1454 * @minimum_height: location for storing the minimum size, or %NULL
1455 * @natural_height: location for storing the preferred size, or %NULL
1457 * Retreives a cell renderers's minimum and natural height if it were rendered to
1458 * @widget with the specified @width.
1463 gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
1466 gint *minimum_height,
1467 gint *natural_height)
1469 GtkCellRendererClass *klass;
1472 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1473 g_return_if_fail (GTK_IS_WIDGET (widget));
1474 g_return_if_fail (NULL != minimum_height || NULL != natural_height);
1476 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1480 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1481 klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
1486 *minimum_height = height;
1488 *natural_height = height;
1491 #if DEBUG_CELL_SIZE_REQUEST
1492 g_message ("%s height for width: %d is minimum %d and natural: %d",
1493 G_OBJECT_TYPE_NAME (cell), width,
1494 minimum_height ? *minimum_height : 20000,
1495 natural_height ? *natural_height : 20000);
1500 * gtk_cell_renderer_get_preferred_size:
1501 * @cell: a #GtkCellRenderer instance
1502 * @widget: the #GtkWidget this cell will be rendering to
1503 * @request_natural: Whether to base the contextual request off of the
1504 * base natural or the base minimum
1505 * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
1506 * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
1508 * Retrieves the minimum and natural size of a cell taking
1509 * into account the widget's preference for height-for-width management.
1511 * If request_natural is specified, the non-contextual natural value will
1512 * be used to make the contextual request; otherwise the minimum will be used.
1517 gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
1519 GtkRequisition *minimum_size,
1520 GtkRequisition *natural_size)
1522 gint min_width, nat_width;
1523 gint min_height, nat_height;
1525 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1527 if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1529 gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
1533 minimum_size->width = min_width;
1534 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
1535 &minimum_size->height, NULL);
1540 natural_size->width = nat_width;
1541 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
1542 NULL, &natural_size->height);
1545 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1547 gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
1551 minimum_size->height = min_height;
1552 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
1553 &minimum_size->width, NULL);
1558 natural_size->height = nat_height;
1559 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
1560 NULL, &natural_size->width);