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"
27 #define DEBUG_CELL_SIZE_REQUEST 0
29 static void gtk_cell_renderer_init (GtkCellRenderer *cell);
30 static void gtk_cell_renderer_class_init (GtkCellRendererClass *class);
31 static void gtk_cell_renderer_get_property (GObject *object,
35 static void gtk_cell_renderer_set_property (GObject *object,
39 static void set_cell_bg_color (GtkCellRenderer *cell,
42 /* Fallback GtkCellRenderer implementation to use remaining ->get_size() implementations */
43 static void gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
47 static void gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
51 static void gtk_cell_renderer_real_get_preferred_height_for_width(GtkCellRenderer *cell,
55 gint *natural_height);
56 static void gtk_cell_renderer_real_get_preferred_width_for_height(GtkCellRenderer *cell,
64 struct _GtkCellRendererPrivate
77 guint is_expander : 1;
78 guint is_expanded : 1;
79 guint cell_background_set : 1;
83 GdkRGBA cell_background;
100 PROP_CELL_BACKGROUND,
101 PROP_CELL_BACKGROUND_GDK,
102 PROP_CELL_BACKGROUND_RGBA,
103 PROP_CELL_BACKGROUND_SET,
114 static guint cell_renderer_signals[LAST_SIGNAL] = { 0 };
116 G_DEFINE_ABSTRACT_TYPE(GtkCellRenderer, gtk_cell_renderer, G_TYPE_INITIALLY_UNOWNED)
119 gtk_cell_renderer_init (GtkCellRenderer *cell)
121 GtkCellRendererPrivate *priv;
123 cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
124 GTK_TYPE_CELL_RENDERER,
125 GtkCellRendererPrivate);
128 priv->mode = GTK_CELL_RENDERER_MODE_INERT;
129 priv->visible = TRUE;
136 priv->sensitive = TRUE;
137 priv->is_expander = FALSE;
138 priv->is_expanded = FALSE;
139 priv->editing = FALSE;
143 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
145 GObjectClass *object_class = G_OBJECT_CLASS (class);
147 object_class->get_property = gtk_cell_renderer_get_property;
148 object_class->set_property = gtk_cell_renderer_set_property;
150 class->render = NULL;
151 class->get_size = NULL;
152 class->get_preferred_width = gtk_cell_renderer_real_get_preferred_width;
153 class->get_preferred_height = gtk_cell_renderer_real_get_preferred_height;
154 class->get_preferred_width_for_height = gtk_cell_renderer_real_get_preferred_width_for_height;
155 class->get_preferred_height_for_width = gtk_cell_renderer_real_get_preferred_height_for_width;
158 * GtkCellRenderer::editing-canceled:
159 * @renderer: the object which received the signal
161 * This signal gets emitted when the user cancels the process of editing a
162 * cell. For example, an editable cell renderer could be written to cancel
163 * editing when the user presses Escape.
165 * See also: gtk_cell_renderer_stop_editing().
169 cell_renderer_signals[EDITING_CANCELED] =
170 g_signal_new (I_("editing-canceled"),
171 G_OBJECT_CLASS_TYPE (object_class),
173 G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
175 _gtk_marshal_VOID__VOID,
179 * GtkCellRenderer::editing-started:
180 * @renderer: the object which received the signal
181 * @editable: the #GtkCellEditable
182 * @path: the path identifying the edited cell
184 * This signal gets emitted when a cell starts to be edited.
185 * The intended use of this signal is to do special setup
186 * on @editable, e.g. adding a #GtkEntryCompletion or setting
187 * up additional columns in a #GtkComboBox.
189 * Note that GTK+ doesn't guarantee that cell renderers will
190 * continue to use the same kind of widget for editing in future
191 * releases, therefore you should check the type of @editable
192 * before doing any specific setup, as in the following example:
195 * text_editing_started (GtkCellRenderer *cell,
196 * GtkCellEditable *editable,
200 * if (GTK_IS_ENTRY (editable))
202 * GtkEntry *entry = GTK_ENTRY (editable);
204 * /* ... create a GtkEntryCompletion */
206 * gtk_entry_set_completion (entry, completion);
213 cell_renderer_signals[EDITING_STARTED] =
214 g_signal_new (I_("editing-started"),
215 G_OBJECT_CLASS_TYPE (object_class),
217 G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
219 _gtk_marshal_VOID__OBJECT_STRING,
221 GTK_TYPE_CELL_EDITABLE,
224 g_object_class_install_property (object_class,
226 g_param_spec_enum ("mode",
228 P_("Editable mode of the CellRenderer"),
229 GTK_TYPE_CELL_RENDERER_MODE,
230 GTK_CELL_RENDERER_MODE_INERT,
231 GTK_PARAM_READWRITE));
233 g_object_class_install_property (object_class,
235 g_param_spec_boolean ("visible",
237 P_("Display the cell"),
239 GTK_PARAM_READWRITE));
240 g_object_class_install_property (object_class,
242 g_param_spec_boolean ("sensitive",
244 P_("Display the cell sensitive"),
246 GTK_PARAM_READWRITE));
248 g_object_class_install_property (object_class,
250 g_param_spec_float ("xalign",
256 GTK_PARAM_READWRITE));
258 g_object_class_install_property (object_class,
260 g_param_spec_float ("yalign",
266 GTK_PARAM_READWRITE));
268 g_object_class_install_property (object_class,
270 g_param_spec_uint ("xpad",
276 GTK_PARAM_READWRITE));
278 g_object_class_install_property (object_class,
280 g_param_spec_uint ("ypad",
286 GTK_PARAM_READWRITE));
288 g_object_class_install_property (object_class,
290 g_param_spec_int ("width",
292 P_("The fixed width"),
296 GTK_PARAM_READWRITE));
298 g_object_class_install_property (object_class,
300 g_param_spec_int ("height",
302 P_("The fixed height"),
306 GTK_PARAM_READWRITE));
308 g_object_class_install_property (object_class,
310 g_param_spec_boolean ("is-expander",
312 P_("Row has children"),
314 GTK_PARAM_READWRITE));
317 g_object_class_install_property (object_class,
319 g_param_spec_boolean ("is-expanded",
321 P_("Row is an expander row, and is expanded"),
323 GTK_PARAM_READWRITE));
325 g_object_class_install_property (object_class,
326 PROP_CELL_BACKGROUND,
327 g_param_spec_string ("cell-background",
328 P_("Cell background color name"),
329 P_("Cell background color as a string"),
331 GTK_PARAM_WRITABLE));
333 g_object_class_install_property (object_class,
334 PROP_CELL_BACKGROUND_GDK,
335 g_param_spec_boxed ("cell-background-gdk",
336 P_("Cell background color"),
337 P_("Cell background color as a GdkColor"),
339 GTK_PARAM_READWRITE));
341 * GtkCellRenderer:cell-background-rgba:
343 * Cell background as a #GdkRGBA
347 g_object_class_install_property (object_class,
348 PROP_CELL_BACKGROUND_RGBA,
349 g_param_spec_boxed ("cell-background-rgba",
350 P_("Cell background RGBA color"),
351 P_("Cell background color as a GdkRGBA"),
353 GTK_PARAM_READWRITE));
355 g_object_class_install_property (object_class,
357 g_param_spec_boolean ("editing",
359 P_("Whether the cell renderer is currently in editing mode"),
361 GTK_PARAM_READABLE));
364 #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))
366 ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
367 P_("Cell background set"),
368 P_("Whether this tag affects the cell background color"));
370 g_type_class_add_private (class, sizeof (GtkCellRendererPrivate));
374 gtk_cell_renderer_get_property (GObject *object,
379 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
380 GtkCellRendererPrivate *priv = cell->priv;
385 g_value_set_enum (value, priv->mode);
388 g_value_set_boolean (value, priv->visible);
391 g_value_set_boolean (value, priv->sensitive);
394 g_value_set_boolean (value, priv->editing);
397 g_value_set_float (value, priv->xalign);
400 g_value_set_float (value, priv->yalign);
403 g_value_set_uint (value, priv->xpad);
406 g_value_set_uint (value, priv->ypad);
409 g_value_set_int (value, priv->width);
412 g_value_set_int (value, priv->height);
414 case PROP_IS_EXPANDER:
415 g_value_set_boolean (value, priv->is_expander);
417 case PROP_IS_EXPANDED:
418 g_value_set_boolean (value, priv->is_expanded);
420 case PROP_CELL_BACKGROUND_GDK:
424 color.red = (guint16) (priv->cell_background.red * 65535);
425 color.green = (guint16) (priv->cell_background.green * 65535);
426 color.blue = (guint16) (priv->cell_background.blue * 65535);
428 g_value_set_boxed (value, &color);
431 case PROP_CELL_BACKGROUND_RGBA:
432 g_value_set_boxed (value, &priv->cell_background);
434 case PROP_CELL_BACKGROUND_SET:
435 g_value_set_boolean (value, priv->cell_background_set);
437 case PROP_CELL_BACKGROUND:
439 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
446 gtk_cell_renderer_set_property (GObject *object,
451 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
452 GtkCellRendererPrivate *priv = cell->priv;
457 priv->mode = g_value_get_enum (value);
460 priv->visible = g_value_get_boolean (value);
463 priv->sensitive = g_value_get_boolean (value);
466 priv->editing = g_value_get_boolean (value);
469 priv->xalign = g_value_get_float (value);
472 priv->yalign = g_value_get_float (value);
475 priv->xpad = g_value_get_uint (value);
478 priv->ypad = g_value_get_uint (value);
481 priv->width = g_value_get_int (value);
484 priv->height = g_value_get_int (value);
486 case PROP_IS_EXPANDER:
487 priv->is_expander = g_value_get_boolean (value);
489 case PROP_IS_EXPANDED:
490 priv->is_expanded = g_value_get_boolean (value);
492 case PROP_CELL_BACKGROUND:
496 if (!g_value_get_string (value))
497 set_cell_bg_color (cell, NULL);
498 else if (gdk_rgba_parse (g_value_get_string (value), &rgba))
499 set_cell_bg_color (cell, &rgba);
501 g_warning ("Don't know color `%s'", g_value_get_string (value));
503 g_object_notify (object, "cell-background-gdk");
506 case PROP_CELL_BACKGROUND_GDK:
510 color = g_value_get_boxed (value);
515 rgba.red = color->red / 65535.;
516 rgba.green = color->green / 65535.;
517 rgba.blue = color->blue / 65535.;
520 set_cell_bg_color (cell, &rgba);
524 set_cell_bg_color (cell, NULL);
528 case PROP_CELL_BACKGROUND_RGBA:
529 set_cell_bg_color (cell, g_value_get_boxed (value));
531 case PROP_CELL_BACKGROUND_SET:
532 priv->cell_background_set = g_value_get_boolean (value);
535 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
541 set_cell_bg_color (GtkCellRenderer *cell,
544 GtkCellRendererPrivate *priv = cell->priv;
548 if (!priv->cell_background_set)
550 priv->cell_background_set = TRUE;
551 g_object_notify (G_OBJECT (cell), "cell-background-set");
554 priv->cell_background = *rgba;
558 if (priv->cell_background_set)
560 priv->cell_background_set = FALSE;
561 g_object_notify (G_OBJECT (cell), "cell-background-set");
567 * gtk_cell_renderer_get_size:
568 * @cell: a #GtkCellRenderer
569 * @widget: the widget the renderer is rendering to
570 * @cell_area: (allow-none): The area a cell will be allocated, or %NULL
571 * @x_offset: (allow-none): location to return x offset of cell relative to @cell_area, or %NULL
572 * @y_offset: (allow-none): location to return y offset of cell relative to @cell_area, or %NULL
573 * @width: (allow-none): location to return width needed to render a cell, or %NULL
574 * @height: (allow-none): location to return height needed to render a cell, or %NULL
576 * Obtains the width and height needed to render the cell. Used by view
577 * widgets to determine the appropriate size for the cell_area passed to
578 * gtk_cell_renderer_render(). If @cell_area is not %NULL, fills in the
579 * x and y offsets (if set) of the cell relative to this location.
581 * Please note that the values set in @width and @height, as well as those
582 * in @x_offset and @y_offset are inclusive of the xpad and ypad properties.
585 * Deprecated: 3.0: Use gtk_cell_renderer_get_preferred_size() instead.
588 gtk_cell_renderer_get_size (GtkCellRenderer *cell,
590 const GdkRectangle *cell_area,
596 GtkRequisition request;
598 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
600 gtk_cell_renderer_get_preferred_size (cell, widget, &request, NULL);
603 *width = request.width;
606 *height = request.height;
609 _gtk_cell_renderer_calc_offset (cell, cell_area, gtk_widget_get_direction (widget),
610 request.width, request.height, x_offset, y_offset);
614 * gtk_cell_renderer_render:
615 * @cell: a #GtkCellRenderer
616 * @cr: a cairo context to draw to
617 * @widget: the widget owning @window
618 * @background_area: entire cell area (including tree expanders and maybe
619 * padding on the sides)
620 * @cell_area: area normally rendered by a cell renderer
621 * @flags: flags that affect rendering
623 * Invokes the virtual render function of the #GtkCellRenderer. The three
624 * passed-in rectangles are areas in @cr. Most renderers will draw within
625 * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
626 * should be honored with respect to @cell_area. @background_area includes the
627 * blank space around the cell, and also the area containing the tree expander;
628 * so the @background_area rectangles for all cells tile to cover the entire
632 gtk_cell_renderer_render (GtkCellRenderer *cell,
635 const GdkRectangle *background_area,
636 const GdkRectangle *cell_area,
637 GtkCellRendererState flags)
639 gboolean selected = FALSE;
640 GtkCellRendererPrivate *priv = cell->priv;
642 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
643 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
644 g_return_if_fail (cr != NULL);
646 selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
650 if (priv->cell_background_set && !selected)
652 gdk_cairo_rectangle (cr, background_area);
653 gdk_cairo_set_source_rgba (cr, &priv->cell_background);
657 GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
668 * gtk_cell_renderer_activate:
669 * @cell: a #GtkCellRenderer
670 * @event: a #GdkEvent
671 * @widget: widget that received the event
672 * @path: widget-dependent string representation of the event location;
673 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
674 * @background_area: background area as passed to gtk_cell_renderer_render()
675 * @cell_area: cell area as passed to gtk_cell_renderer_render()
676 * @flags: render flags
678 * Passes an activate event to the cell renderer for possible processing.
679 * Some cell renderers may use events; for example, #GtkCellRendererToggle
680 * toggles when it gets a mouse click.
682 * Return value: %TRUE if the event was consumed/handled
685 gtk_cell_renderer_activate (GtkCellRenderer *cell,
689 const GdkRectangle *background_area,
690 const GdkRectangle *cell_area,
691 GtkCellRendererState flags)
693 GtkCellRendererPrivate *priv;
695 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
699 if (priv->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
702 if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
705 return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
709 (GdkRectangle *) background_area,
710 (GdkRectangle *) cell_area,
715 * gtk_cell_renderer_start_editing:
716 * @cell: a #GtkCellRenderer
717 * @event: a #GdkEvent
718 * @widget: widget that received the event
719 * @path: widget-dependent string representation of the event location;
720 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
721 * @background_area: background area as passed to gtk_cell_renderer_render()
722 * @cell_area: cell area as passed to gtk_cell_renderer_render()
723 * @flags: render flags
725 * Passes an activate event to the cell renderer for possible processing.
727 * Return value: (transfer full): A new #GtkCellEditable, or %NULL
730 gtk_cell_renderer_start_editing (GtkCellRenderer *cell,
734 const GdkRectangle *background_area,
735 const GdkRectangle *cell_area,
736 GtkCellRendererState flags)
739 GtkCellRendererPrivate *priv;
740 GtkCellEditable *editable;
742 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
746 if (priv->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
749 if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
752 editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
756 (GdkRectangle *) background_area,
757 (GdkRectangle *) cell_area,
761 cell_renderer_signals[EDITING_STARTED], 0,
764 priv->editing = TRUE;
770 * gtk_cell_renderer_set_fixed_size:
771 * @cell: A #GtkCellRenderer
772 * @width: the width of the cell renderer, or -1
773 * @height: the height of the cell renderer, or -1
775 * Sets the renderer size to be explicit, independent of the properties set.
778 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
782 GtkCellRendererPrivate *priv;
784 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
785 g_return_if_fail (width >= -1 && height >= -1);
789 if ((width != priv->width) || (height != priv->height))
791 g_object_freeze_notify (G_OBJECT (cell));
793 if (width != priv->width)
796 g_object_notify (G_OBJECT (cell), "width");
799 if (height != priv->height)
801 priv->height = height;
802 g_object_notify (G_OBJECT (cell), "height");
805 g_object_thaw_notify (G_OBJECT (cell));
810 * gtk_cell_renderer_get_fixed_size:
811 * @cell: A #GtkCellRenderer
812 * @width: (allow-none): location to fill in with the fixed width of the cell, or %NULL
813 * @height: (allow-none): location to fill in with the fixed height of the cell, or %NULL
815 * Fills in @width and @height with the appropriate size of @cell.
818 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
822 GtkCellRendererPrivate *priv;
824 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
829 *width = priv->width;
831 *height = priv->height;
835 * gtk_cell_renderer_set_alignment:
836 * @cell: A #GtkCellRenderer
837 * @xalign: the x alignment of the cell renderer
838 * @yalign: the y alignment of the cell renderer
840 * Sets the renderer's alignment within its available space.
845 gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
849 GtkCellRendererPrivate *priv;
851 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
852 g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
853 g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
857 if ((xalign != priv->xalign) || (yalign != priv->yalign))
859 g_object_freeze_notify (G_OBJECT (cell));
861 if (xalign != priv->xalign)
863 priv->xalign = xalign;
864 g_object_notify (G_OBJECT (cell), "xalign");
867 if (yalign != priv->yalign)
869 priv->yalign = yalign;
870 g_object_notify (G_OBJECT (cell), "yalign");
873 g_object_thaw_notify (G_OBJECT (cell));
878 * gtk_cell_renderer_get_alignment:
879 * @cell: A #GtkCellRenderer
880 * @xalign: (allow-none): location to fill in with the x alignment of the cell, or %NULL
881 * @yalign: (allow-none): location to fill in with the y alignment of the cell, or %NULL
883 * Fills in @xalign and @yalign with the appropriate values of @cell.
888 gtk_cell_renderer_get_alignment (GtkCellRenderer *cell,
892 GtkCellRendererPrivate *priv;
894 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
899 *xalign = priv->xalign;
901 *yalign = priv->yalign;
905 * gtk_cell_renderer_set_padding:
906 * @cell: A #GtkCellRenderer
907 * @xpad: the x padding of the cell renderer
908 * @ypad: the y padding of the cell renderer
910 * Sets the renderer's padding.
915 gtk_cell_renderer_set_padding (GtkCellRenderer *cell,
919 GtkCellRendererPrivate *priv;
921 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
922 g_return_if_fail (xpad >= 0 && xpad >= 0);
926 if ((xpad != priv->xpad) || (ypad != priv->ypad))
928 g_object_freeze_notify (G_OBJECT (cell));
930 if (xpad != priv->xpad)
933 g_object_notify (G_OBJECT (cell), "xpad");
936 if (ypad != priv->ypad)
939 g_object_notify (G_OBJECT (cell), "ypad");
942 g_object_thaw_notify (G_OBJECT (cell));
947 * gtk_cell_renderer_get_padding:
948 * @cell: A #GtkCellRenderer
949 * @xpad: (allow-none): location to fill in with the x padding of the cell, or %NULL
950 * @ypad: (allow-none): location to fill in with the y padding of the cell, or %NULL
952 * Fills in @xpad and @ypad with the appropriate values of @cell.
957 gtk_cell_renderer_get_padding (GtkCellRenderer *cell,
961 GtkCellRendererPrivate *priv;
963 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
974 * gtk_cell_renderer_set_visible:
975 * @cell: A #GtkCellRenderer
976 * @visible: the visibility of the cell
978 * Sets the cell renderer's visibility.
983 gtk_cell_renderer_set_visible (GtkCellRenderer *cell,
986 GtkCellRendererPrivate *priv;
988 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
992 if (priv->visible != visible)
994 priv->visible = visible ? TRUE : FALSE;
995 g_object_notify (G_OBJECT (cell), "visible");
1000 * gtk_cell_renderer_get_visible:
1001 * @cell: A #GtkCellRenderer
1003 * Returns the cell renderer's visibility.
1005 * Returns: %TRUE if the cell renderer is visible
1010 gtk_cell_renderer_get_visible (GtkCellRenderer *cell)
1012 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1014 return cell->priv->visible;
1018 * gtk_cell_renderer_set_sensitive:
1019 * @cell: A #GtkCellRenderer
1020 * @sensitive: the sensitivity of the cell
1022 * Sets the cell renderer's sensitivity.
1027 gtk_cell_renderer_set_sensitive (GtkCellRenderer *cell,
1030 GtkCellRendererPrivate *priv;
1032 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1036 if (priv->sensitive != sensitive)
1038 priv->sensitive = sensitive ? TRUE : FALSE;
1039 g_object_notify (G_OBJECT (cell), "sensitive");
1044 * gtk_cell_renderer_get_sensitive:
1045 * @cell: A #GtkCellRenderer
1047 * Returns the cell renderer's sensitivity.
1049 * Returns: %TRUE if the cell renderer is sensitive
1054 gtk_cell_renderer_get_sensitive (GtkCellRenderer *cell)
1056 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1058 return cell->priv->sensitive;
1063 * gtk_cell_renderer_can_focus:
1064 * @cell: A #GtkCellRenderer
1066 * Checks whether the cell renderer can receive focus.
1068 * Returns: %TRUE if the cell renderer can do anything with keyboard focus
1073 gtk_cell_renderer_can_focus (GtkCellRenderer *cell)
1075 GtkCellRendererPrivate *priv;
1077 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1081 return (cell->priv->visible &&
1082 (cell->priv->mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1083 cell->priv->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE));
1088 * gtk_cell_renderer_stop_editing:
1089 * @cell: A #GtkCellRenderer
1090 * @canceled: %TRUE if the editing has been canceled
1092 * Informs the cell renderer that the editing is stopped.
1093 * If @canceled is %TRUE, the cell renderer will emit the
1094 * #GtkCellRenderer::editing-canceled signal.
1096 * This function should be called by cell renderer implementations
1097 * in response to the #GtkCellEditable::editing-done signal of
1103 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1106 GtkCellRendererPrivate *priv;
1108 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1114 priv->editing = FALSE;
1116 g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1121 gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer *cell,
1123 GtkOrientation orientation,
1127 GtkRequisition min_req;
1129 /* Fallback on the old API to get the size. */
1130 if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size)
1131 GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL,
1132 &min_req.width, &min_req.height);
1139 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1142 *minimum_size = min_req.width;
1145 *natural_size = min_req.width;
1150 *minimum_size = min_req.height;
1153 *natural_size = min_req.height;
1158 gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
1163 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL,
1164 minimum_size, natural_size);
1168 gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
1173 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL,
1174 minimum_size, natural_size);
1179 gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
1182 gint *minimum_height,
1183 gint *natural_height)
1185 /* Fall back on the height reported from ->get_size() */
1186 gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
1190 gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
1193 gint *minimum_width,
1194 gint *natural_width)
1196 /* Fall back on the width reported from ->get_size() */
1197 gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
1200 /* An internal convenience function for some containers to peek at the
1201 * cell alignment in a target allocation (used to draw focus and align
1202 * cells in the icon view).
1204 * Note this is only a trivial 'align * (allocation - request)' operation.
1207 _gtk_cell_renderer_calc_offset (GtkCellRenderer *cell,
1208 const GdkRectangle *cell_area,
1209 GtkTextDirection direction,
1215 GtkCellRendererPrivate *priv;
1217 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1218 g_return_if_fail (cell_area != NULL);
1219 g_return_if_fail (x_offset || y_offset);
1225 *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
1226 (1.0 - priv->xalign) : priv->xalign) *
1227 (cell_area->width - width));
1228 *x_offset = MAX (*x_offset, 0);
1232 *y_offset = (priv->yalign *
1233 (cell_area->height - height));
1234 *y_offset = MAX (*y_offset, 0);
1239 * gtk_cell_renderer_get_request_mode:
1240 * @cell: a #GtkCellRenderer instance
1242 * Gets whether the cell renderer prefers a height-for-width layout
1243 * or a width-for-height layout.
1245 * Returns: The #GtkSizeRequestMode preferred by this renderer.
1250 gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
1252 GtkCellRendererClass *klass;
1254 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1256 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1257 if (klass->get_request_mode)
1258 return klass->get_request_mode (cell);
1260 /* By default cell renderers are height-for-width. */
1261 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1265 * gtk_cell_renderer_get_preferred_width:
1266 * @cell: a #GtkCellRenderer instance
1267 * @widget: the #GtkWidget this cell will be rendering to
1268 * @minimum_size: location to store the minimum size, or %NULL
1269 * @natural_size: location to store the natural size, or %NULL
1271 * Retreives a renderer's natural size when rendered to @widget.
1276 gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
1281 GtkCellRendererClass *klass;
1284 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1285 g_return_if_fail (GTK_IS_WIDGET (widget));
1286 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1288 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1292 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1293 klass->get_preferred_width (cell, widget, minimum_size, natural_size);
1298 *minimum_size = width;
1300 *natural_size = width;
1303 #if DEBUG_CELL_SIZE_REQUEST
1304 g_message ("%s returning minimum width: %d and natural width: %d",
1305 G_OBJECT_TYPE_NAME (cell),
1306 minimum_size ? *minimum_size : 20000,
1307 natural_size ? *natural_size : 20000);
1313 * gtk_cell_renderer_get_preferred_height:
1314 * @cell: a #GtkCellRenderer instance
1315 * @widget: the #GtkWidget this cell will be rendering to
1316 * @minimum_size: location to store the minimum size, or %NULL
1317 * @natural_size: location to store the natural size, or %NULL
1319 * Retreives a renderer's natural size when rendered to @widget.
1324 gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
1329 GtkCellRendererClass *klass;
1332 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1333 g_return_if_fail (GTK_IS_WIDGET (widget));
1334 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1336 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1340 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1341 klass->get_preferred_height (cell, widget, minimum_size, natural_size);
1346 *minimum_size = height;
1348 *natural_size = height;
1351 #if DEBUG_CELL_SIZE_REQUEST
1352 g_message ("%s returning minimum height: %d and natural height: %d",
1353 G_OBJECT_TYPE_NAME (cell),
1354 minimum_size ? *minimum_size : 20000,
1355 natural_size ? *natural_size : 20000);
1361 * gtk_cell_renderer_get_preferred_width_for_height:
1362 * @cell: a #GtkCellRenderer instance
1363 * @widget: the #GtkWidget this cell will be rendering to
1364 * @height: the size which is available for allocation
1365 * @minimum_width: location for storing the minimum size, or %NULL
1366 * @natural_width: location for storing the preferred size, or %NULL
1368 * Retreives a cell renderers's minimum and natural width if it were rendered to
1369 * @widget with the specified @height.
1374 gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
1377 gint *minimum_width,
1378 gint *natural_width)
1380 GtkCellRendererClass *klass;
1383 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1384 g_return_if_fail (GTK_IS_WIDGET (widget));
1385 g_return_if_fail (NULL != minimum_width || NULL != natural_width);
1387 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1391 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1392 klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
1397 *minimum_width = width;
1399 *natural_width = width;
1402 #if DEBUG_CELL_SIZE_REQUEST
1403 g_message ("%s width for height: %d is minimum %d and natural: %d",
1404 G_OBJECT_TYPE_NAME (cell), height,
1405 minimum_width ? *minimum_width : 20000,
1406 natural_width ? *natural_width : 20000);
1411 * gtk_cell_renderer_get_preferred_height_for_width:
1412 * @cell: a #GtkCellRenderer instance
1413 * @widget: the #GtkWidget this cell will be rendering to
1414 * @width: the size which is available for allocation
1415 * @minimum_height: location for storing the minimum size, or %NULL
1416 * @natural_height: location for storing the preferred size, or %NULL
1418 * Retreives a cell renderers's minimum and natural height if it were rendered to
1419 * @widget with the specified @width.
1424 gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
1427 gint *minimum_height,
1428 gint *natural_height)
1430 GtkCellRendererClass *klass;
1433 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1434 g_return_if_fail (GTK_IS_WIDGET (widget));
1435 g_return_if_fail (NULL != minimum_height || NULL != natural_height);
1437 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1441 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1442 klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
1447 *minimum_height = height;
1449 *natural_height = height;
1452 #if DEBUG_CELL_SIZE_REQUEST
1453 g_message ("%s height for width: %d is minimum %d and natural: %d",
1454 G_OBJECT_TYPE_NAME (cell), width,
1455 minimum_height ? *minimum_height : 20000,
1456 natural_height ? *natural_height : 20000);
1461 * gtk_cell_renderer_get_preferred_size:
1462 * @cell: a #GtkCellRenderer instance
1463 * @widget: the #GtkWidget this cell will be rendering to
1464 * @request_natural: Whether to base the contextual request off of the
1465 * base natural or the base minimum
1466 * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
1467 * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
1469 * Retrieves the minimum and natural size of a cell taking
1470 * into account the widget's preference for height-for-width management.
1472 * If request_natural is specified, the non-contextual natural value will
1473 * be used to make the contextual request; otherwise the minimum will be used.
1478 gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
1480 GtkRequisition *minimum_size,
1481 GtkRequisition *natural_size)
1483 gint min_width, nat_width;
1484 gint min_height, nat_height;
1486 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1488 if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1490 gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
1494 minimum_size->width = min_width;
1495 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
1496 &minimum_size->height, NULL);
1501 natural_size->width = nat_width;
1502 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
1503 NULL, &natural_size->height);
1506 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1508 gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
1512 minimum_size->height = min_height;
1513 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
1514 &minimum_size->width, NULL);
1519 natural_size->height = nat_height;
1520 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
1521 NULL, &natural_size->width);