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 GdkColor cell_background;
100 PROP_CELL_BACKGROUND,
101 PROP_CELL_BACKGROUND_GDK,
102 PROP_CELL_BACKGROUND_SET,
113 static guint cell_renderer_signals[LAST_SIGNAL] = { 0 };
115 G_DEFINE_ABSTRACT_TYPE(GtkCellRenderer, gtk_cell_renderer, G_TYPE_INITIALLY_UNOWNED)
118 gtk_cell_renderer_init (GtkCellRenderer *cell)
120 GtkCellRendererPrivate *priv;
122 cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
123 GTK_TYPE_CELL_RENDERER,
124 GtkCellRendererPrivate);
127 priv->mode = GTK_CELL_RENDERER_MODE_INERT;
128 priv->visible = TRUE;
135 priv->sensitive = TRUE;
136 priv->is_expander = FALSE;
137 priv->is_expanded = FALSE;
138 priv->editing = FALSE;
142 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
144 GObjectClass *object_class = G_OBJECT_CLASS (class);
146 object_class->get_property = gtk_cell_renderer_get_property;
147 object_class->set_property = gtk_cell_renderer_set_property;
149 class->render = NULL;
150 class->get_size = NULL;
151 class->get_preferred_width = gtk_cell_renderer_real_get_preferred_width;
152 class->get_preferred_height = gtk_cell_renderer_real_get_preferred_height;
153 class->get_preferred_width_for_height = gtk_cell_renderer_real_get_preferred_width_for_height;
154 class->get_preferred_height_for_width = gtk_cell_renderer_real_get_preferred_height_for_width;
157 * GtkCellRenderer::editing-canceled:
158 * @renderer: the object which received the signal
160 * This signal gets emitted when the user cancels the process of editing a
161 * cell. For example, an editable cell renderer could be written to cancel
162 * editing when the user presses Escape.
164 * See also: gtk_cell_renderer_stop_editing().
168 cell_renderer_signals[EDITING_CANCELED] =
169 g_signal_new (I_("editing-canceled"),
170 G_OBJECT_CLASS_TYPE (object_class),
172 G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
174 _gtk_marshal_VOID__VOID,
178 * GtkCellRenderer::editing-started:
179 * @renderer: the object which received the signal
180 * @editable: the #GtkCellEditable
181 * @path: the path identifying the edited cell
183 * This signal gets emitted when a cell starts to be edited.
184 * The intended use of this signal is to do special setup
185 * on @editable, e.g. adding a #GtkEntryCompletion or setting
186 * up additional columns in a #GtkComboBox.
188 * Note that GTK+ doesn't guarantee that cell renderers will
189 * continue to use the same kind of widget for editing in future
190 * releases, therefore you should check the type of @editable
191 * before doing any specific setup, as in the following example:
194 * text_editing_started (GtkCellRenderer *cell,
195 * GtkCellEditable *editable,
199 * if (GTK_IS_ENTRY (editable))
201 * GtkEntry *entry = GTK_ENTRY (editable);
203 * /* ... create a GtkEntryCompletion */
205 * gtk_entry_set_completion (entry, completion);
212 cell_renderer_signals[EDITING_STARTED] =
213 g_signal_new (I_("editing-started"),
214 G_OBJECT_CLASS_TYPE (object_class),
216 G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
218 _gtk_marshal_VOID__OBJECT_STRING,
220 GTK_TYPE_CELL_EDITABLE,
223 g_object_class_install_property (object_class,
225 g_param_spec_enum ("mode",
227 P_("Editable mode of the CellRenderer"),
228 GTK_TYPE_CELL_RENDERER_MODE,
229 GTK_CELL_RENDERER_MODE_INERT,
230 GTK_PARAM_READWRITE));
232 g_object_class_install_property (object_class,
234 g_param_spec_boolean ("visible",
236 P_("Display the cell"),
238 GTK_PARAM_READWRITE));
239 g_object_class_install_property (object_class,
241 g_param_spec_boolean ("sensitive",
243 P_("Display the cell sensitive"),
245 GTK_PARAM_READWRITE));
247 g_object_class_install_property (object_class,
249 g_param_spec_float ("xalign",
255 GTK_PARAM_READWRITE));
257 g_object_class_install_property (object_class,
259 g_param_spec_float ("yalign",
265 GTK_PARAM_READWRITE));
267 g_object_class_install_property (object_class,
269 g_param_spec_uint ("xpad",
275 GTK_PARAM_READWRITE));
277 g_object_class_install_property (object_class,
279 g_param_spec_uint ("ypad",
285 GTK_PARAM_READWRITE));
287 g_object_class_install_property (object_class,
289 g_param_spec_int ("width",
291 P_("The fixed width"),
295 GTK_PARAM_READWRITE));
297 g_object_class_install_property (object_class,
299 g_param_spec_int ("height",
301 P_("The fixed height"),
305 GTK_PARAM_READWRITE));
307 g_object_class_install_property (object_class,
309 g_param_spec_boolean ("is-expander",
311 P_("Row has children"),
313 GTK_PARAM_READWRITE));
316 g_object_class_install_property (object_class,
318 g_param_spec_boolean ("is-expanded",
320 P_("Row is an expander row, and is expanded"),
322 GTK_PARAM_READWRITE));
324 g_object_class_install_property (object_class,
325 PROP_CELL_BACKGROUND,
326 g_param_spec_string ("cell-background",
327 P_("Cell background color name"),
328 P_("Cell background color as a string"),
330 GTK_PARAM_WRITABLE));
332 g_object_class_install_property (object_class,
333 PROP_CELL_BACKGROUND_GDK,
334 g_param_spec_boxed ("cell-background-gdk",
335 P_("Cell background color"),
336 P_("Cell background color as a GdkColor"),
338 GTK_PARAM_READWRITE));
340 g_object_class_install_property (object_class,
342 g_param_spec_boolean ("editing",
344 P_("Whether the cell renderer is currently in editing mode"),
346 GTK_PARAM_READABLE));
349 #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))
351 ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
352 P_("Cell background set"),
353 P_("Whether this tag affects the cell background color"));
355 g_type_class_add_private (class, sizeof (GtkCellRendererPrivate));
359 gtk_cell_renderer_get_property (GObject *object,
364 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
365 GtkCellRendererPrivate *priv = cell->priv;
370 g_value_set_enum (value, priv->mode);
373 g_value_set_boolean (value, priv->visible);
376 g_value_set_boolean (value, priv->sensitive);
379 g_value_set_boolean (value, priv->editing);
382 g_value_set_float (value, priv->xalign);
385 g_value_set_float (value, priv->yalign);
388 g_value_set_uint (value, priv->xpad);
391 g_value_set_uint (value, priv->ypad);
394 g_value_set_int (value, priv->width);
397 g_value_set_int (value, priv->height);
399 case PROP_IS_EXPANDER:
400 g_value_set_boolean (value, priv->is_expander);
402 case PROP_IS_EXPANDED:
403 g_value_set_boolean (value, priv->is_expanded);
405 case PROP_CELL_BACKGROUND_GDK:
409 color.red = priv->cell_background.red;
410 color.green = priv->cell_background.green;
411 color.blue = priv->cell_background.blue;
413 g_value_set_boxed (value, &color);
416 case PROP_CELL_BACKGROUND_SET:
417 g_value_set_boolean (value, priv->cell_background_set);
419 case PROP_CELL_BACKGROUND:
421 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
428 gtk_cell_renderer_set_property (GObject *object,
433 GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
434 GtkCellRendererPrivate *priv = cell->priv;
439 priv->mode = g_value_get_enum (value);
442 priv->visible = g_value_get_boolean (value);
445 priv->sensitive = g_value_get_boolean (value);
448 priv->editing = g_value_get_boolean (value);
451 priv->xalign = g_value_get_float (value);
454 priv->yalign = g_value_get_float (value);
457 priv->xpad = g_value_get_uint (value);
460 priv->ypad = g_value_get_uint (value);
463 priv->width = g_value_get_int (value);
466 priv->height = g_value_get_int (value);
468 case PROP_IS_EXPANDER:
469 priv->is_expander = g_value_get_boolean (value);
471 case PROP_IS_EXPANDED:
472 priv->is_expanded = g_value_get_boolean (value);
474 case PROP_CELL_BACKGROUND:
478 if (!g_value_get_string (value))
479 set_cell_bg_color (cell, NULL);
480 else if (gdk_color_parse (g_value_get_string (value), &color))
481 set_cell_bg_color (cell, &color);
483 g_warning ("Don't know color `%s'", g_value_get_string (value));
485 g_object_notify (object, "cell-background-gdk");
488 case PROP_CELL_BACKGROUND_GDK:
489 set_cell_bg_color (cell, g_value_get_boxed (value));
491 case PROP_CELL_BACKGROUND_SET:
492 priv->cell_background_set = g_value_get_boolean (value);
495 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
501 set_cell_bg_color (GtkCellRenderer *cell,
504 GtkCellRendererPrivate *priv = cell->priv;
508 if (!priv->cell_background_set)
510 priv->cell_background_set = TRUE;
511 g_object_notify (G_OBJECT (cell), "cell-background-set");
514 priv->cell_background.red = color->red;
515 priv->cell_background.green = color->green;
516 priv->cell_background.blue = color->blue;
520 if (priv->cell_background_set)
522 priv->cell_background_set = FALSE;
523 g_object_notify (G_OBJECT (cell), "cell-background-set");
529 * gtk_cell_renderer_get_size:
530 * @cell: a #GtkCellRenderer
531 * @widget: the widget the renderer is rendering to
532 * @cell_area: (allow-none): The area a cell will be allocated, or %NULL
533 * @x_offset: (allow-none): location to return x offset of cell relative to @cell_area, or %NULL
534 * @y_offset: (allow-none): location to return y offset of cell relative to @cell_area, or %NULL
535 * @width: (allow-none): location to return width needed to render a cell, or %NULL
536 * @height: (allow-none): location to return height needed to render a cell, or %NULL
538 * Obtains the width and height needed to render the cell. Used by view
539 * widgets to determine the appropriate size for the cell_area passed to
540 * gtk_cell_renderer_render(). If @cell_area is not %NULL, fills in the
541 * x and y offsets (if set) of the cell relative to this location.
543 * Please note that the values set in @width and @height, as well as those
544 * in @x_offset and @y_offset are inclusive of the xpad and ypad properties.
547 * Deprecated: 3.0: Use gtk_cell_renderer_get_preferred_size() instead.
550 gtk_cell_renderer_get_size (GtkCellRenderer *cell,
552 const GdkRectangle *cell_area,
558 GtkRequisition request;
560 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
562 gtk_cell_renderer_get_preferred_size (cell, widget, &request, NULL);
565 *width = request.width;
568 *height = request.height;
571 _gtk_cell_renderer_calc_offset (cell, cell_area, gtk_widget_get_direction (widget),
572 request.width, request.height, x_offset, y_offset);
576 * gtk_cell_renderer_render:
577 * @cell: a #GtkCellRenderer
578 * @cr: a cairo context to draw to
579 * @widget: the widget owning @window
580 * @background_area: entire cell area (including tree expanders and maybe
581 * padding on the sides)
582 * @cell_area: area normally rendered by a cell renderer
583 * @flags: flags that affect rendering
585 * Invokes the virtual render function of the #GtkCellRenderer. The three
586 * passed-in rectangles are areas in @cr. Most renderers will draw within
587 * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
588 * should be honored with respect to @cell_area. @background_area includes the
589 * blank space around the cell, and also the area containing the tree expander;
590 * so the @background_area rectangles for all cells tile to cover the entire
594 gtk_cell_renderer_render (GtkCellRenderer *cell,
597 const GdkRectangle *background_area,
598 const GdkRectangle *cell_area,
599 GtkCellRendererState flags)
601 gboolean selected = FALSE;
602 GtkCellRendererPrivate *priv = cell->priv;
604 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
605 g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
606 g_return_if_fail (cr != NULL);
608 selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
612 if (priv->cell_background_set && !selected)
614 gdk_cairo_rectangle (cr, background_area);
615 gdk_cairo_set_source_color (cr, &priv->cell_background);
619 GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
630 * gtk_cell_renderer_activate:
631 * @cell: a #GtkCellRenderer
632 * @event: a #GdkEvent
633 * @widget: widget that received the event
634 * @path: widget-dependent string representation of the event location;
635 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
636 * @background_area: background area as passed to gtk_cell_renderer_render()
637 * @cell_area: cell area as passed to gtk_cell_renderer_render()
638 * @flags: render flags
640 * Passes an activate event to the cell renderer for possible processing.
641 * Some cell renderers may use events; for example, #GtkCellRendererToggle
642 * toggles when it gets a mouse click.
644 * Return value: %TRUE if the event was consumed/handled
647 gtk_cell_renderer_activate (GtkCellRenderer *cell,
651 const GdkRectangle *background_area,
652 const GdkRectangle *cell_area,
653 GtkCellRendererState flags)
655 GtkCellRendererPrivate *priv;
657 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
661 if (priv->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
664 if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
667 return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
671 (GdkRectangle *) background_area,
672 (GdkRectangle *) cell_area,
677 * gtk_cell_renderer_start_editing:
678 * @cell: a #GtkCellRenderer
679 * @event: a #GdkEvent
680 * @widget: widget that received the event
681 * @path: widget-dependent string representation of the event location;
682 * e.g. for #GtkTreeView, a string representation of #GtkTreePath
683 * @background_area: background area as passed to gtk_cell_renderer_render()
684 * @cell_area: cell area as passed to gtk_cell_renderer_render()
685 * @flags: render flags
687 * Passes an activate event to the cell renderer for possible processing.
689 * Return value: (transfer full): A new #GtkCellEditable, or %NULL
692 gtk_cell_renderer_start_editing (GtkCellRenderer *cell,
696 const GdkRectangle *background_area,
697 const GdkRectangle *cell_area,
698 GtkCellRendererState flags)
701 GtkCellRendererPrivate *priv;
702 GtkCellEditable *editable;
704 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
708 if (priv->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
711 if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
714 editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
718 (GdkRectangle *) background_area,
719 (GdkRectangle *) cell_area,
723 cell_renderer_signals[EDITING_STARTED], 0,
726 priv->editing = TRUE;
732 * gtk_cell_renderer_set_fixed_size:
733 * @cell: A #GtkCellRenderer
734 * @width: the width of the cell renderer, or -1
735 * @height: the height of the cell renderer, or -1
737 * Sets the renderer size to be explicit, independent of the properties set.
740 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
744 GtkCellRendererPrivate *priv;
746 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
747 g_return_if_fail (width >= -1 && height >= -1);
751 if ((width != priv->width) || (height != priv->height))
753 g_object_freeze_notify (G_OBJECT (cell));
755 if (width != priv->width)
758 g_object_notify (G_OBJECT (cell), "width");
761 if (height != priv->height)
763 priv->height = height;
764 g_object_notify (G_OBJECT (cell), "height");
767 g_object_thaw_notify (G_OBJECT (cell));
772 * gtk_cell_renderer_get_fixed_size:
773 * @cell: A #GtkCellRenderer
774 * @width: (allow-none): location to fill in with the fixed width of the cell, or %NULL
775 * @height: (allow-none): location to fill in with the fixed height of the cell, or %NULL
777 * Fills in @width and @height with the appropriate size of @cell.
780 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
784 GtkCellRendererPrivate *priv;
786 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
791 *width = priv->width;
793 *height = priv->height;
797 * gtk_cell_renderer_set_alignment:
798 * @cell: A #GtkCellRenderer
799 * @xalign: the x alignment of the cell renderer
800 * @yalign: the y alignment of the cell renderer
802 * Sets the renderer's alignment within its available space.
807 gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
811 GtkCellRendererPrivate *priv;
813 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
814 g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
815 g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
819 if ((xalign != priv->xalign) || (yalign != priv->yalign))
821 g_object_freeze_notify (G_OBJECT (cell));
823 if (xalign != priv->xalign)
825 priv->xalign = xalign;
826 g_object_notify (G_OBJECT (cell), "xalign");
829 if (yalign != priv->yalign)
831 priv->yalign = yalign;
832 g_object_notify (G_OBJECT (cell), "yalign");
835 g_object_thaw_notify (G_OBJECT (cell));
840 * gtk_cell_renderer_get_alignment:
841 * @cell: A #GtkCellRenderer
842 * @xalign: (allow-none): location to fill in with the x alignment of the cell, or %NULL
843 * @yalign: (allow-none): location to fill in with the y alignment of the cell, or %NULL
845 * Fills in @xalign and @yalign with the appropriate values of @cell.
850 gtk_cell_renderer_get_alignment (GtkCellRenderer *cell,
854 GtkCellRendererPrivate *priv;
856 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
861 *xalign = priv->xalign;
863 *yalign = priv->yalign;
867 * gtk_cell_renderer_set_padding:
868 * @cell: A #GtkCellRenderer
869 * @xpad: the x padding of the cell renderer
870 * @ypad: the y padding of the cell renderer
872 * Sets the renderer's padding.
877 gtk_cell_renderer_set_padding (GtkCellRenderer *cell,
881 GtkCellRendererPrivate *priv;
883 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
884 g_return_if_fail (xpad >= 0 && xpad >= 0);
888 if ((xpad != priv->xpad) || (ypad != priv->ypad))
890 g_object_freeze_notify (G_OBJECT (cell));
892 if (xpad != priv->xpad)
895 g_object_notify (G_OBJECT (cell), "xpad");
898 if (ypad != priv->ypad)
901 g_object_notify (G_OBJECT (cell), "ypad");
904 g_object_thaw_notify (G_OBJECT (cell));
909 * gtk_cell_renderer_get_padding:
910 * @cell: A #GtkCellRenderer
911 * @xpad: (allow-none): location to fill in with the x padding of the cell, or %NULL
912 * @ypad: (allow-none): location to fill in with the y padding of the cell, or %NULL
914 * Fills in @xpad and @ypad with the appropriate values of @cell.
919 gtk_cell_renderer_get_padding (GtkCellRenderer *cell,
923 GtkCellRendererPrivate *priv;
925 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
936 * gtk_cell_renderer_set_visible:
937 * @cell: A #GtkCellRenderer
938 * @visible: the visibility of the cell
940 * Sets the cell renderer's visibility.
945 gtk_cell_renderer_set_visible (GtkCellRenderer *cell,
948 GtkCellRendererPrivate *priv;
950 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
954 if (priv->visible != visible)
956 priv->visible = visible ? TRUE : FALSE;
957 g_object_notify (G_OBJECT (cell), "visible");
962 * gtk_cell_renderer_get_visible:
963 * @cell: A #GtkCellRenderer
965 * Returns the cell renderer's visibility.
967 * Returns: %TRUE if the cell renderer is visible
972 gtk_cell_renderer_get_visible (GtkCellRenderer *cell)
974 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
976 return cell->priv->visible;
980 * gtk_cell_renderer_set_sensitive:
981 * @cell: A #GtkCellRenderer
982 * @sensitive: the sensitivity of the cell
984 * Sets the cell renderer's sensitivity.
989 gtk_cell_renderer_set_sensitive (GtkCellRenderer *cell,
992 GtkCellRendererPrivate *priv;
994 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
998 if (priv->sensitive != sensitive)
1000 priv->sensitive = sensitive ? TRUE : FALSE;
1001 g_object_notify (G_OBJECT (cell), "sensitive");
1006 * gtk_cell_renderer_get_sensitive:
1007 * @cell: A #GtkCellRenderer
1009 * Returns the cell renderer's sensitivity.
1011 * Returns: %TRUE if the cell renderer is sensitive
1016 gtk_cell_renderer_get_sensitive (GtkCellRenderer *cell)
1018 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1020 return cell->priv->sensitive;
1024 * gtk_cell_renderer_stop_editing:
1025 * @cell: A #GtkCellRenderer
1026 * @canceled: %TRUE if the editing has been canceled
1028 * Informs the cell renderer that the editing is stopped.
1029 * If @canceled is %TRUE, the cell renderer will emit the
1030 * #GtkCellRenderer::editing-canceled signal.
1032 * This function should be called by cell renderer implementations
1033 * in response to the #GtkCellEditable::editing-done signal of
1039 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1042 GtkCellRendererPrivate *priv;
1044 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1050 priv->editing = FALSE;
1052 g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1057 gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer *cell,
1059 GtkOrientation orientation,
1063 GtkRequisition min_req;
1065 /* Fallback on the old API to get the size. */
1066 if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size)
1067 GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL,
1068 &min_req.width, &min_req.height);
1075 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1078 *minimum_size = min_req.width;
1081 *natural_size = min_req.width;
1086 *minimum_size = min_req.height;
1089 *natural_size = min_req.height;
1094 gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
1099 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL,
1100 minimum_size, natural_size);
1104 gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
1109 gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL,
1110 minimum_size, natural_size);
1115 gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
1118 gint *minimum_height,
1119 gint *natural_height)
1121 /* Fall back on the height reported from ->get_size() */
1122 gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
1126 gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
1129 gint *minimum_width,
1130 gint *natural_width)
1132 /* Fall back on the width reported from ->get_size() */
1133 gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
1136 /* An internal convenience function for some containers to peek at the
1137 * cell alignment in a target allocation (used to draw focus and align
1138 * cells in the icon view).
1140 * Note this is only a trivial 'align * (allocation - request)' operation.
1143 _gtk_cell_renderer_calc_offset (GtkCellRenderer *cell,
1144 const GdkRectangle *cell_area,
1145 GtkTextDirection direction,
1151 GtkCellRendererPrivate *priv;
1153 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1154 g_return_if_fail (cell_area != NULL);
1155 g_return_if_fail (x_offset || y_offset);
1161 *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
1162 (1.0 - priv->xalign) : priv->xalign) *
1163 (cell_area->width - width));
1164 *x_offset = MAX (*x_offset, 0);
1168 *y_offset = (priv->yalign *
1169 (cell_area->height - height));
1170 *y_offset = MAX (*y_offset, 0);
1175 * gtk_cell_renderer_get_request_mode:
1176 * @cell: a #GtkCellRenderer instance
1178 * Gets whether the cell renderer prefers a height-for-width layout
1179 * or a width-for-height layout.
1181 * Returns: The #GtkSizeRequestMode preferred by this renderer.
1186 gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
1188 GtkCellRendererClass *klass;
1190 g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1192 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1193 if (klass->get_request_mode)
1194 return klass->get_request_mode (cell);
1196 /* By default cell renderers are height-for-width. */
1197 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1201 * gtk_cell_renderer_get_preferred_width:
1202 * @cell: a #GtkCellRenderer instance
1203 * @widget: the #GtkWidget this cell will be rendering to
1204 * @minimum_size: location to store the minimum size, or %NULL
1205 * @natural_size: location to store the natural size, or %NULL
1207 * Retreives a renderer's natural size when rendered to @widget.
1212 gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
1217 GtkCellRendererClass *klass;
1220 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1221 g_return_if_fail (GTK_IS_WIDGET (widget));
1222 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1224 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1228 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1229 klass->get_preferred_width (cell, widget, minimum_size, natural_size);
1234 *minimum_size = width;
1236 *natural_size = width;
1239 #if DEBUG_CELL_SIZE_REQUEST
1240 g_message ("%s returning minimum width: %d and natural width: %d",
1241 G_OBJECT_TYPE_NAME (cell),
1242 minimum_size ? *minimum_size : 20000,
1243 natural_size ? *natural_size : 20000);
1249 * gtk_cell_renderer_get_preferred_height:
1250 * @cell: a #GtkCellRenderer instance
1251 * @widget: the #GtkWidget this cell will be rendering to
1252 * @minimum_size: location to store the minimum size, or %NULL
1253 * @natural_size: location to store the natural size, or %NULL
1255 * Retreives a renderer's natural size when rendered to @widget.
1260 gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
1265 GtkCellRendererClass *klass;
1268 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1269 g_return_if_fail (GTK_IS_WIDGET (widget));
1270 g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1272 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1276 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1277 klass->get_preferred_height (cell, widget, minimum_size, natural_size);
1282 *minimum_size = height;
1284 *natural_size = height;
1287 #if DEBUG_CELL_SIZE_REQUEST
1288 g_message ("%s returning minimum height: %d and natural height: %d",
1289 G_OBJECT_TYPE_NAME (cell),
1290 minimum_size ? *minimum_size : 20000,
1291 natural_size ? *natural_size : 20000);
1297 * gtk_cell_renderer_get_preferred_width_for_height:
1298 * @cell: a #GtkCellRenderer instance
1299 * @widget: the #GtkWidget this cell will be rendering to
1300 * @height: the size which is available for allocation
1301 * @minimum_width: location for storing the minimum size, or %NULL
1302 * @natural_width: location for storing the preferred size, or %NULL
1304 * Retreives a cell renderers's minimum and natural width if it were rendered to
1305 * @widget with the specified @height.
1310 gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
1313 gint *minimum_width,
1314 gint *natural_width)
1316 GtkCellRendererClass *klass;
1319 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1320 g_return_if_fail (GTK_IS_WIDGET (widget));
1321 g_return_if_fail (NULL != minimum_width || NULL != natural_width);
1323 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1327 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1328 klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
1333 *minimum_width = width;
1335 *natural_width = width;
1338 #if DEBUG_CELL_SIZE_REQUEST
1339 g_message ("%s width for height: %d is minimum %d and natural: %d",
1340 G_OBJECT_TYPE_NAME (cell), height,
1341 minimum_width ? *minimum_width : 20000,
1342 natural_width ? *natural_width : 20000);
1347 * gtk_cell_renderer_get_preferred_height_for_width:
1348 * @cell: a #GtkCellRenderer instance
1349 * @widget: the #GtkWidget this cell will be rendering to
1350 * @width: the size which is available for allocation
1351 * @minimum_height: location for storing the minimum size, or %NULL
1352 * @natural_height: location for storing the preferred size, or %NULL
1354 * Retreives a cell renderers's minimum and natural height if it were rendered to
1355 * @widget with the specified @width.
1360 gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
1363 gint *minimum_height,
1364 gint *natural_height)
1366 GtkCellRendererClass *klass;
1369 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1370 g_return_if_fail (GTK_IS_WIDGET (widget));
1371 g_return_if_fail (NULL != minimum_height || NULL != natural_height);
1373 gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1377 klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1378 klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
1383 *minimum_height = height;
1385 *natural_height = height;
1388 #if DEBUG_CELL_SIZE_REQUEST
1389 g_message ("%s height for width: %d is minimum %d and natural: %d",
1390 G_OBJECT_TYPE_NAME (cell), width,
1391 minimum_height ? *minimum_height : 20000,
1392 natural_height ? *natural_height : 20000);
1397 * gtk_cell_renderer_get_preferred_size:
1398 * @cell: a #GtkCellRenderer instance
1399 * @widget: the #GtkWidget this cell will be rendering to
1400 * @request_natural: Whether to base the contextual request off of the
1401 * base natural or the base minimum
1402 * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
1403 * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
1405 * Retrieves the minimum and natural size of a cell taking
1406 * into account the widget's preference for height-for-width management.
1408 * If request_natural is specified, the non-contextual natural value will
1409 * be used to make the contextual request; otherwise the minimum will be used.
1414 gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
1416 GtkRequisition *minimum_size,
1417 GtkRequisition *natural_size)
1419 gint min_width, nat_width;
1420 gint min_height, nat_height;
1422 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1424 if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1426 gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
1430 minimum_size->width = min_width;
1431 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
1432 &minimum_size->height, NULL);
1437 natural_size->width = nat_width;
1438 gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
1439 NULL, &natural_size->height);
1442 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1444 gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
1448 minimum_size->height = min_height;
1449 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
1450 &minimum_size->width, NULL);
1455 natural_size->height = nat_height;
1456 gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
1457 NULL, &natural_size->width);