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"
22 #include "gtkcellsizerequest.h"
24 #include "gtkmarshalers.h"
25 #include "gtkprivate.h"
26 #include "gtktreeprivate.h"
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 GtkCellSizeRequest implementation to use remaining ->get_size() implementations */
43 static void gtk_cell_renderer_cell_size_request_init (GtkCellSizeRequestIface *iface);
44 static void gtk_cell_renderer_get_width (GtkCellSizeRequest *cell,
48 static void gtk_cell_renderer_get_height (GtkCellSizeRequest *cell,
52 static void gtk_cell_renderer_get_height_for_width (GtkCellSizeRequest *cell,
56 gint *natural_height);
57 static void gtk_cell_renderer_get_width_for_height (GtkCellSizeRequest *cell,
65 struct _GtkCellRendererPrivate
78 guint is_expander : 1;
79 guint is_expanded : 1;
80 guint cell_background_set : 1;
84 GdkColor cell_background;
101 PROP_CELL_BACKGROUND,
102 PROP_CELL_BACKGROUND_GDK,
103 PROP_CELL_BACKGROUND_SET,
114 static guint cell_renderer_signals[LAST_SIGNAL] = { 0 };
117 /* Do a manual _get_type() here to avoid a deadlock implementing
118 * the interface which we are a prerequisite of.
121 gtk_cell_renderer_get_type (void)
123 static GType cell_renderer_type = 0;
125 if (G_UNLIKELY (cell_renderer_type == 0))
127 const GTypeInfo cell_renderer_info =
129 sizeof (GtkCellRendererClass),
130 NULL, /* base_init */
131 NULL, /* base_finalize */
132 (GClassInitFunc) gtk_cell_renderer_class_init,
133 NULL, /* class_finalize */
134 NULL, /* class_init */
135 sizeof (GtkCellRenderer),
137 (GInstanceInitFunc) gtk_cell_renderer_init,
138 NULL, /* value_table */
141 const GInterfaceInfo cell_size_request_info =
143 (GInterfaceInitFunc) gtk_cell_renderer_cell_size_request_init,
144 (GInterfaceFinalizeFunc) NULL,
145 NULL /* interface data */
148 cell_renderer_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkCellRenderer",
149 &cell_renderer_info, G_TYPE_FLAG_ABSTRACT);
151 g_type_add_interface_static (cell_renderer_type, GTK_TYPE_CELL_SIZE_REQUEST,
152 &cell_size_request_info) ;
155 return cell_renderer_type;
160 gtk_cell_renderer_init (GtkCellRenderer *cell)
162 GtkCellRendererPrivate *priv;
164 cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
165 GTK_TYPE_CELL_RENDERER,
166 GtkCellRendererPrivate);
169 priv->mode = GTK_CELL_RENDERER_MODE_INERT;
170 priv->visible = TRUE;
177 priv->sensitive = TRUE;
178 priv->is_expander = FALSE;
179 priv->is_expanded = FALSE;
180 priv->editing = FALSE;
184 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
186 GObjectClass *object_class = G_OBJECT_CLASS (class);
188 object_class->get_property = gtk_cell_renderer_get_property;
189 object_class->set_property = gtk_cell_renderer_set_property;
191 class->render = NULL;
192 class->get_size = NULL;
195 * GtkCellRenderer::editing-canceled:
196 * @renderer: the object which received the signal
198 * This signal gets emitted when the user cancels the process of editing a
199 * cell. For example, an editable cell renderer could be written to cancel
200 * editing when the user presses Escape.
202 * See also: gtk_cell_renderer_stop_editing().
206 cell_renderer_signals[EDITING_CANCELED] =
207 g_signal_new (I_("editing-canceled"),
208 G_OBJECT_CLASS_TYPE (object_class),
210 G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
212 _gtk_marshal_VOID__VOID,
216 * GtkCellRenderer::editing-started:
217 * @renderer: the object which received the signal
218 * @editable: the #GtkCellEditable
219 * @path: the path identifying the edited cell
221 * This signal gets emitted when a cell starts to be edited.
222 * The intended use of this signal is to do special setup
223 * on @editable, e.g. adding a #GtkEntryCompletion or setting
224 * up additional columns in a #GtkComboBox.
226 * Note that GTK+ doesn't guarantee that cell renderers will
227 * continue to use the same kind of widget for editing in future
228 * releases, therefore you should check the type of @editable
229 * before doing any specific setup, as in the following example:
232 * text_editing_started (GtkCellRenderer *cell,
233 * GtkCellEditable *editable,
237 * if (GTK_IS_ENTRY (editable))
239 * GtkEntry *entry = GTK_ENTRY (editable);
241 * /* ... create a GtkEntryCompletion */
243 * gtk_entry_set_completion (entry, completion);
250 cell_renderer_signals[EDITING_STARTED] =
251 g_signal_new (I_("editing-started"),
252 G_OBJECT_CLASS_TYPE (object_class),
254 G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
256 _gtk_marshal_VOID__OBJECT_STRING,
258 GTK_TYPE_CELL_EDITABLE,
261 g_object_class_install_property (object_class,
263 g_param_spec_enum ("mode",
265 P_("Editable mode of the CellRenderer"),
266 GTK_TYPE_CELL_RENDERER_MODE,
267 GTK_CELL_RENDERER_MODE_INERT,
268 GTK_PARAM_READWRITE));
270 g_object_class_install_property (object_class,
272 g_param_spec_boolean ("visible",
274 P_("Display the cell"),
276 GTK_PARAM_READWRITE));
277 g_object_class_install_property (object_class,
279 g_param_spec_boolean ("sensitive",
281 P_("Display the cell sensitive"),
283 GTK_PARAM_READWRITE));
285 g_object_class_install_property (object_class,
287 g_param_spec_float ("xalign",
293 GTK_PARAM_READWRITE));
295 g_object_class_install_property (object_class,
297 g_param_spec_float ("yalign",
303 GTK_PARAM_READWRITE));
305 g_object_class_install_property (object_class,
307 g_param_spec_uint ("xpad",
313 GTK_PARAM_READWRITE));
315 g_object_class_install_property (object_class,
317 g_param_spec_uint ("ypad",
323 GTK_PARAM_READWRITE));
325 g_object_class_install_property (object_class,
327 g_param_spec_int ("width",
329 P_("The fixed width"),
333 GTK_PARAM_READWRITE));
335 g_object_class_install_property (object_class,
337 g_param_spec_int ("height",
339 P_("The fixed height"),
343 GTK_PARAM_READWRITE));
345 g_object_class_install_property (object_class,
347 g_param_spec_boolean ("is-expander",
349 P_("Row has children"),
351 GTK_PARAM_READWRITE));
354 g_object_class_install_property (object_class,
356 g_param_spec_boolean ("is-expanded",
358 P_("Row is an expander row, and is expanded"),
360 GTK_PARAM_READWRITE));
362 g_object_class_install_property (object_class,
363 PROP_CELL_BACKGROUND,
364 g_param_spec_string ("cell-background",
365 P_("Cell background color name"),
366 P_("Cell background color as a string"),
368 GTK_PARAM_WRITABLE));
370 g_object_class_install_property (object_class,
371 PROP_CELL_BACKGROUND_GDK,
372 g_param_spec_boxed ("cell-background-gdk",
373 P_("Cell background color"),
374 P_("Cell background color as a GdkColor"),
376 GTK_PARAM_READWRITE));
378 g_object_class_install_property (object_class,
380 g_param_spec_boolean ("editing",
382 P_("Whether the cell renderer is currently in editing mode"),
384 GTK_PARAM_READABLE));
387 #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))
389 ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
390 P_("Cell background set"),
391 P_("Whether this tag affects the cell background color"));
393 g_type_class_add_private (class, sizeof (GtkCellRendererPrivate));
397 gtk_cell_renderer_get_property (GObject *object,
402 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
403 GtkCellRendererPrivate *priv = cell->priv;
408 g_value_set_enum (value, priv->mode);
411 g_value_set_boolean (value, priv->visible);
414 g_value_set_boolean (value, priv->sensitive);
417 g_value_set_boolean (value, priv->editing);
420 g_value_set_float (value, priv->xalign);
423 g_value_set_float (value, priv->yalign);
426 g_value_set_uint (value, priv->xpad);
429 g_value_set_uint (value, priv->ypad);
432 g_value_set_int (value, priv->width);
435 g_value_set_int (value, priv->height);
437 case PROP_IS_EXPANDER:
438 g_value_set_boolean (value, priv->is_expander);
440 case PROP_IS_EXPANDED:
441 g_value_set_boolean (value, priv->is_expanded);
443 case PROP_CELL_BACKGROUND_GDK:
447 color.red = priv->cell_background.red;
448 color.green = priv->cell_background.green;
449 color.blue = priv->cell_background.blue;
451 g_value_set_boxed (value, &color);
454 case PROP_CELL_BACKGROUND_SET:
455 g_value_set_boolean (value, priv->cell_background_set);
457 case PROP_CELL_BACKGROUND:
459 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
466 gtk_cell_renderer_set_property (GObject *object,
471 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
472 GtkCellRendererPrivate *priv = cell->priv;
477 priv->mode = g_value_get_enum (value);
480 priv->visible = g_value_get_boolean (value);
483 priv->sensitive = g_value_get_boolean (value);
486 priv->editing = g_value_get_boolean (value);
489 priv->xalign = g_value_get_float (value);
492 priv->yalign = g_value_get_float (value);
495 priv->xpad = g_value_get_uint (value);
498 priv->ypad = g_value_get_uint (value);
501 priv->width = g_value_get_int (value);
504 priv->height = g_value_get_int (value);
506 case PROP_IS_EXPANDER:
507 priv->is_expander = g_value_get_boolean (value);
509 case PROP_IS_EXPANDED:
510 priv->is_expanded = g_value_get_boolean (value);
512 case PROP_CELL_BACKGROUND:
516 if (!g_value_get_string (value))
517 set_cell_bg_color (cell, NULL);
518 else if (gdk_color_parse (g_value_get_string (value), &color))
519 set_cell_bg_color (cell, &color);
521 g_warning ("Don't know color `%s'", g_value_get_string (value));
523 g_object_notify (object, "cell-background-gdk");
526 case PROP_CELL_BACKGROUND_GDK:
527 set_cell_bg_color (cell, g_value_get_boxed (value));
529 case PROP_CELL_BACKGROUND_SET:
530 priv->cell_background_set = g_value_get_boolean (value);
533 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
539 set_cell_bg_color (GtkCellRenderer *cell,
542 GtkCellRendererPrivate *priv = cell->priv;
546 if (!priv->cell_background_set)
548 priv->cell_background_set = TRUE;
549 g_object_notify (G_OBJECT (cell), "cell-background-set");
552 priv->cell_background.red = color->red;
553 priv->cell_background.green = color->green;
554 priv->cell_background.blue = color->blue;
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_size_request_get_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_size_request_get_size (GTK_CELL_SIZE_REQUEST (cell),
601 widget, &request, NULL);
604 *width = request.width;
607 *height = request.height;
610 _gtk_cell_renderer_calc_offset (cell, cell_area, gtk_widget_get_direction (widget),
611 request.width, request.height, x_offset, y_offset);
615 * gtk_cell_renderer_render:
616 * @cell: a #GtkCellRenderer
617 * @window: a #GdkDrawable to draw to
618 * @widget: the widget owning @window
619 * @background_area: entire cell area (including tree expanders and maybe
620 * padding on the sides)
621 * @cell_area: area normally rendered by a cell renderer
622 * @expose_area: area that actually needs updating
623 * @flags: flags that affect rendering
625 * Invokes the virtual render function of the #GtkCellRenderer. The three
626 * passed-in rectangles are areas of @window. Most renderers will draw within
627 * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
628 * should be honored with respect to @cell_area. @background_area includes the
629 * blank space around the cell, and also the area containing the tree expander;
630 * so the @background_area rectangles for all cells tile to cover the entire
631 * @window. @expose_area is a clip rectangle.
634 gtk_cell_renderer_render (GtkCellRenderer *cell,
637 const GdkRectangle *background_area,
638 const GdkRectangle *cell_area,
639 const GdkRectangle *expose_area,
640 GtkCellRendererState flags)
642 gboolean selected = FALSE;
643 GtkCellRendererPrivate *priv = cell->priv;
646 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
647 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
649 selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
651 cr = gdk_cairo_create (window);
652 gdk_cairo_rectangle (cr, expose_area);
655 if (priv->cell_background_set && !selected)
657 gdk_cairo_rectangle (cr, background_area);
658 gdk_cairo_set_source_color (cr, &priv->cell_background);
662 GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
673 * gtk_cell_renderer_activate:
674 * @cell: a #GtkCellRenderer
675 * @event: a #GdkEvent
676 * @widget: widget that received the event
677 * @path: widget-dependent string representation of the event location;
678 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
679 * @background_area: background area as passed to gtk_cell_renderer_render()
680 * @cell_area: cell area as passed to gtk_cell_renderer_render()
681 * @flags: render flags
683 * Passes an activate event to the cell renderer for possible processing.
684 * Some cell renderers may use events; for example, #GtkCellRendererToggle
685 * toggles when it gets a mouse click.
687 * Return value: %TRUE if the event was consumed/handled
690 gtk_cell_renderer_activate (GtkCellRenderer *cell,
694 const GdkRectangle *background_area,
695 const GdkRectangle *cell_area,
696 GtkCellRendererState flags)
698 GtkCellRendererPrivate *priv;
700 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
704 if (priv->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
707 if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
710 return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
714 (GdkRectangle *) background_area,
715 (GdkRectangle *) cell_area,
720 * gtk_cell_renderer_start_editing:
721 * @cell: a #GtkCellRenderer
722 * @event: a #GdkEvent
723 * @widget: widget that received the event
724 * @path: widget-dependent string representation of the event location;
725 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
726 * @background_area: background area as passed to gtk_cell_renderer_render()
727 * @cell_area: cell area as passed to gtk_cell_renderer_render()
728 * @flags: render flags
730 * Passes an activate event to the cell renderer for possible processing.
732 * Return value: (transfer full): A new #GtkCellEditable, or %NULL
735 gtk_cell_renderer_start_editing (GtkCellRenderer *cell,
739 const GdkRectangle *background_area,
740 const GdkRectangle *cell_area,
741 GtkCellRendererState flags)
744 GtkCellRendererPrivate *priv;
745 GtkCellEditable *editable;
747 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
751 if (priv->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
754 if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
757 editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
761 (GdkRectangle *) background_area,
762 (GdkRectangle *) cell_area,
766 cell_renderer_signals[EDITING_STARTED], 0,
769 priv->editing = TRUE;
775 * gtk_cell_renderer_set_fixed_size:
776 * @cell: A #GtkCellRenderer
777 * @width: the width of the cell renderer, or -1
778 * @height: the height of the cell renderer, or -1
780 * Sets the renderer size to be explicit, independent of the properties set.
783 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
787 GtkCellRendererPrivate *priv;
789 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
790 g_return_if_fail (width >= -1 && height >= -1);
794 if ((width != priv->width) || (height != priv->height))
796 g_object_freeze_notify (G_OBJECT (cell));
798 if (width != priv->width)
801 g_object_notify (G_OBJECT (cell), "width");
804 if (height != priv->height)
806 priv->height = height;
807 g_object_notify (G_OBJECT (cell), "height");
810 g_object_thaw_notify (G_OBJECT (cell));
815 * gtk_cell_renderer_get_fixed_size:
816 * @cell: A #GtkCellRenderer
817 * @width: (allow-none): location to fill in with the fixed width of the cell, or %NULL
818 * @height: (allow-none): location to fill in with the fixed height of the cell, or %NULL
820 * Fills in @width and @height with the appropriate size of @cell.
823 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
827 GtkCellRendererPrivate *priv;
829 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
834 *width = priv->width;
836 *height = priv->height;
840 * gtk_cell_renderer_set_alignment:
841 * @cell: A #GtkCellRenderer
842 * @xalign: the x alignment of the cell renderer
843 * @yalign: the y alignment of the cell renderer
845 * Sets the renderer's alignment within its available space.
850 gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
854 GtkCellRendererPrivate *priv;
856 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
857 g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
858 g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
862 if ((xalign != priv->xalign) || (yalign != priv->yalign))
864 g_object_freeze_notify (G_OBJECT (cell));
866 if (xalign != priv->xalign)
868 priv->xalign = xalign;
869 g_object_notify (G_OBJECT (cell), "xalign");
872 if (yalign != priv->yalign)
874 priv->yalign = yalign;
875 g_object_notify (G_OBJECT (cell), "yalign");
878 g_object_thaw_notify (G_OBJECT (cell));
883 * gtk_cell_renderer_get_alignment:
884 * @cell: A #GtkCellRenderer
885 * @xalign: (allow-none): location to fill in with the x alignment of the cell, or %NULL
886 * @yalign: (allow-none): location to fill in with the y alignment of the cell, or %NULL
888 * Fills in @xalign and @yalign with the appropriate values of @cell.
893 gtk_cell_renderer_get_alignment (GtkCellRenderer *cell,
897 GtkCellRendererPrivate *priv;
899 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
904 *xalign = priv->xalign;
906 *yalign = priv->yalign;
910 * gtk_cell_renderer_set_padding:
911 * @cell: A #GtkCellRenderer
912 * @xpad: the x padding of the cell renderer
913 * @ypad: the y padding of the cell renderer
915 * Sets the renderer's padding.
920 gtk_cell_renderer_set_padding (GtkCellRenderer *cell,
924 GtkCellRendererPrivate *priv;
926 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
927 g_return_if_fail (xpad >= 0 && xpad >= 0);
931 if ((xpad != priv->xpad) || (ypad != priv->ypad))
933 g_object_freeze_notify (G_OBJECT (cell));
935 if (xpad != priv->xpad)
938 g_object_notify (G_OBJECT (cell), "xpad");
941 if (ypad != priv->ypad)
944 g_object_notify (G_OBJECT (cell), "ypad");
947 g_object_thaw_notify (G_OBJECT (cell));
952 * gtk_cell_renderer_get_padding:
953 * @cell: A #GtkCellRenderer
954 * @xpad: (allow-none): location to fill in with the x padding of the cell, or %NULL
955 * @ypad: (allow-none): location to fill in with the y padding of the cell, or %NULL
957 * Fills in @xpad and @ypad with the appropriate values of @cell.
962 gtk_cell_renderer_get_padding (GtkCellRenderer *cell,
966 GtkCellRendererPrivate *priv;
968 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
979 * gtk_cell_renderer_set_visible:
980 * @cell: A #GtkCellRenderer
981 * @visible: the visibility of the cell
983 * Sets the cell renderer's visibility.
988 gtk_cell_renderer_set_visible (GtkCellRenderer *cell,
991 GtkCellRendererPrivate *priv;
993 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
997 if (priv->visible != visible)
999 priv->visible = visible ? TRUE : FALSE;
1000 g_object_notify (G_OBJECT (cell), "visible");
1005 * gtk_cell_renderer_get_visible:
1006 * @cell: A #GtkCellRenderer
1008 * Returns the cell renderer's visibility.
1010 * Returns: %TRUE if the cell renderer is visible
1015 gtk_cell_renderer_get_visible (GtkCellRenderer *cell)
1017 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1019 return cell->priv->visible;
1023 * gtk_cell_renderer_set_sensitive:
1024 * @cell: A #GtkCellRenderer
1025 * @sensitive: the sensitivity of the cell
1027 * Sets the cell renderer's sensitivity.
1032 gtk_cell_renderer_set_sensitive (GtkCellRenderer *cell,
1035 GtkCellRendererPrivate *priv;
1037 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1041 if (priv->sensitive != sensitive)
1043 priv->sensitive = sensitive ? TRUE : FALSE;
1044 g_object_notify (G_OBJECT (cell), "sensitive");
1049 * gtk_cell_renderer_get_sensitive:
1050 * @cell: A #GtkCellRenderer
1052 * Returns the cell renderer's sensitivity.
1054 * Returns: %TRUE if the cell renderer is sensitive
1059 gtk_cell_renderer_get_sensitive (GtkCellRenderer *cell)
1061 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1063 return cell->priv->sensitive;
1067 * gtk_cell_renderer_stop_editing:
1068 * @cell: A #GtkCellRenderer
1069 * @canceled: %TRUE if the editing has been canceled
1071 * Informs the cell renderer that the editing is stopped.
1072 * If @canceled is %TRUE, the cell renderer will emit the
1073 * #GtkCellRenderer::editing-canceled signal.
1075 * This function should be called by cell renderer implementations
1076 * in response to the #GtkCellEditable::editing-done signal of
1082 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1085 GtkCellRendererPrivate *priv;
1087 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1093 priv->editing = FALSE;
1095 g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1100 gtk_cell_renderer_cell_size_request_init (GtkCellSizeRequestIface *iface)
1102 iface->get_width = gtk_cell_renderer_get_width;
1103 iface->get_height = gtk_cell_renderer_get_height;
1105 iface->get_width_for_height = gtk_cell_renderer_get_width_for_height;
1106 iface->get_height_for_width = gtk_cell_renderer_get_height_for_width;
1110 gtk_cell_renderer_get_desired_size (GtkCellSizeRequest *cell,
1112 GtkOrientation orientation,
1116 GtkRequisition min_req;
1118 /* Fallback on the old API to get the size. */
1119 if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size)
1120 GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL,
1121 &min_req.width, &min_req.height);
1128 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1131 *minimum_size = min_req.width;
1134 *natural_size = min_req.width;
1139 *minimum_size = min_req.height;
1142 *natural_size = min_req.height;
1147 gtk_cell_renderer_get_width (GtkCellSizeRequest *cell,
1152 gtk_cell_renderer_get_desired_size (cell, widget, GTK_ORIENTATION_HORIZONTAL,
1153 minimum_size, natural_size);
1157 gtk_cell_renderer_get_height (GtkCellSizeRequest *cell,
1162 gtk_cell_renderer_get_desired_size (cell, widget, GTK_ORIENTATION_VERTICAL,
1163 minimum_size, natural_size);
1168 gtk_cell_renderer_get_height_for_width (GtkCellSizeRequest *cell,
1171 gint *minimum_height,
1172 gint *natural_height)
1174 /* Fall back on the height reported from ->get_size() */
1175 gtk_cell_size_request_get_height (cell, widget, minimum_height, natural_height);
1179 gtk_cell_renderer_get_width_for_height (GtkCellSizeRequest *cell,
1182 gint *minimum_width,
1183 gint *natural_width)
1185 /* Fall back on the width reported from ->get_size() */
1186 gtk_cell_size_request_get_width (cell, widget, minimum_width, natural_width);
1189 /* An internal convenience function for some containers to peek at the
1190 * cell alignment in a target allocation (used to draw focus and align
1191 * cells in the icon view).
1193 * Note this is only a trivial 'align * (allocation - request)' operation.
1196 _gtk_cell_renderer_calc_offset (GtkCellRenderer *cell,
1197 const GdkRectangle *cell_area,
1198 GtkTextDirection direction,
1204 GtkCellRendererPrivate *priv;
1206 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1207 g_return_if_fail (cell_area != NULL);
1208 g_return_if_fail (x_offset || y_offset);
1214 *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
1215 (1.0 - priv->xalign) : priv->xalign) *
1216 (cell_area->width - width));
1217 *x_offset = MAX (*x_offset, 0);
1221 *y_offset = (priv->yalign *
1222 (cell_area->height - height));
1223 *y_offset = MAX (*y_offset, 0);