]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellrenderer.c
Don't export _gtk_cell_renderer_calc_offset
[~andy/gtk] / gtk / gtkcellrenderer.c
1 /* gtkcellrenderer.c
2  * Copyright (C) 2000  Red Hat, Inc. Jonathan Blandford
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21 #include "gtkcellrenderer.h"
22 #include "gtkintl.h"
23 #include "gtkmarshalers.h"
24 #include "gtkprivate.h"
25 #include "gtktreeprivate.h"
26
27
28 /**
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
33  *
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.
39  *
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().
47  *
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.
53  *
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.
63  */
64
65
66 #define DEBUG_CELL_SIZE_REQUEST 0
67
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,
71                                              guint                 param_id,
72                                              GValue               *value,
73                                              GParamSpec           *pspec);
74 static void gtk_cell_renderer_set_property  (GObject              *object,
75                                              guint                 param_id,
76                                              const GValue         *value,
77                                              GParamSpec           *pspec);
78 static void set_cell_bg_color               (GtkCellRenderer      *cell,
79                                              GdkRGBA              *rgba);
80
81 /* Fallback GtkCellRenderer    implementation to use remaining ->get_size() implementations */
82 static void gtk_cell_renderer_real_get_preferred_width           (GtkCellRenderer         *cell,
83                                                                   GtkWidget               *widget,
84                                                                   gint                    *minimum_size,
85                                                                   gint                    *natural_size);
86 static void gtk_cell_renderer_real_get_preferred_height          (GtkCellRenderer         *cell,
87                                                                   GtkWidget               *widget,
88                                                                   gint                    *minimum_size,
89                                                                   gint                    *natural_size);
90 static void gtk_cell_renderer_real_get_preferred_height_for_width(GtkCellRenderer         *cell,
91                                                                   GtkWidget               *widget,
92                                                                   gint                     width,
93                                                                   gint                    *minimum_height,
94                                                                   gint                    *natural_height);
95 static void gtk_cell_renderer_real_get_preferred_width_for_height(GtkCellRenderer         *cell,
96                                                                   GtkWidget               *widget,
97                                                                   gint                     height,
98                                                                   gint                    *minimum_width,
99                                                                   gint                    *natural_width);
100
101
102
103 struct _GtkCellRendererPrivate
104 {
105   gfloat xalign;
106   gfloat yalign;
107
108   gint width;
109   gint height;
110
111   guint16 xpad;
112   guint16 ypad;
113
114   guint mode                : 2;
115   guint visible             : 1;
116   guint is_expander         : 1;
117   guint is_expanded         : 1;
118   guint cell_background_set : 1;
119   guint sensitive           : 1;
120   guint editing             : 1;
121
122   GdkRGBA cell_background;
123 };
124
125
126 enum {
127   PROP_0,
128   PROP_MODE,
129   PROP_VISIBLE,
130   PROP_SENSITIVE,
131   PROP_XALIGN,
132   PROP_YALIGN,
133   PROP_XPAD,
134   PROP_YPAD,
135   PROP_WIDTH,
136   PROP_HEIGHT,
137   PROP_IS_EXPANDER,
138   PROP_IS_EXPANDED,
139   PROP_CELL_BACKGROUND,
140   PROP_CELL_BACKGROUND_GDK,
141   PROP_CELL_BACKGROUND_RGBA,
142   PROP_CELL_BACKGROUND_SET,
143   PROP_EDITING
144 };
145
146 /* Signal IDs */
147 enum {
148   EDITING_CANCELED,
149   EDITING_STARTED,
150   LAST_SIGNAL
151 };
152
153 static guint  cell_renderer_signals[LAST_SIGNAL] = { 0 };
154
155 G_DEFINE_ABSTRACT_TYPE(GtkCellRenderer, gtk_cell_renderer, G_TYPE_INITIALLY_UNOWNED)
156
157 static void
158 gtk_cell_renderer_init (GtkCellRenderer *cell)
159 {
160   GtkCellRendererPrivate *priv;
161
162   cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
163                                             GTK_TYPE_CELL_RENDERER,
164                                             GtkCellRendererPrivate);
165   priv = cell->priv;
166
167   priv->mode = GTK_CELL_RENDERER_MODE_INERT;
168   priv->visible = TRUE;
169   priv->width = -1;
170   priv->height = -1;
171   priv->xalign = 0.5;
172   priv->yalign = 0.5;
173   priv->xpad = 0;
174   priv->ypad = 0;
175   priv->sensitive = TRUE;
176   priv->is_expander = FALSE;
177   priv->is_expanded = FALSE;
178   priv->editing = FALSE;
179 }
180
181 static void
182 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
183 {
184   GObjectClass *object_class = G_OBJECT_CLASS (class);
185
186   object_class->get_property = gtk_cell_renderer_get_property;
187   object_class->set_property = gtk_cell_renderer_set_property;
188
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;
195
196   /**
197    * GtkCellRenderer::editing-canceled:
198    * @renderer: the object which received the signal
199    *
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. 
203    *
204    * See also: gtk_cell_renderer_stop_editing().
205    *
206    * Since: 2.4
207    */
208   cell_renderer_signals[EDITING_CANCELED] =
209     g_signal_new (I_("editing-canceled"),
210                   G_OBJECT_CLASS_TYPE (object_class),
211                   G_SIGNAL_RUN_FIRST,
212                   G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
213                   NULL, NULL,
214                   _gtk_marshal_VOID__VOID,
215                   G_TYPE_NONE, 0);
216
217   /**
218    * GtkCellRenderer::editing-started:
219    * @renderer: the object which received the signal
220    * @editable: the #GtkCellEditable
221    * @path: the path identifying the edited cell
222    *
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.
227    *
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:
232    * |[
233    * static void
234    * text_editing_started (GtkCellRenderer *cell,
235    *                       GtkCellEditable *editable,
236    *                       const gchar     *path,
237    *                       gpointer         data)
238    * {
239    *   if (GTK_IS_ENTRY (editable)) 
240    *     {
241    *       GtkEntry *entry = GTK_ENTRY (editable);
242    *       
243    *       /&ast; ... create a GtkEntryCompletion &ast;/
244    *       
245    *       gtk_entry_set_completion (entry, completion);
246    *     }
247    * }
248    * ]|
249    *
250    * Since: 2.6
251    */
252   cell_renderer_signals[EDITING_STARTED] =
253     g_signal_new (I_("editing-started"),
254                   G_OBJECT_CLASS_TYPE (object_class),
255                   G_SIGNAL_RUN_FIRST,
256                   G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
257                   NULL, NULL,
258                   _gtk_marshal_VOID__OBJECT_STRING,
259                   G_TYPE_NONE, 2,
260                   GTK_TYPE_CELL_EDITABLE,
261                   G_TYPE_STRING);
262
263   g_object_class_install_property (object_class,
264                                    PROP_MODE,
265                                    g_param_spec_enum ("mode",
266                                                       P_("mode"),
267                                                       P_("Editable mode of the CellRenderer"),
268                                                       GTK_TYPE_CELL_RENDERER_MODE,
269                                                       GTK_CELL_RENDERER_MODE_INERT,
270                                                       GTK_PARAM_READWRITE));
271
272   g_object_class_install_property (object_class,
273                                    PROP_VISIBLE,
274                                    g_param_spec_boolean ("visible",
275                                                          P_("visible"),
276                                                          P_("Display the cell"),
277                                                          TRUE,
278                                                          GTK_PARAM_READWRITE));
279   g_object_class_install_property (object_class,
280                                    PROP_SENSITIVE,
281                                    g_param_spec_boolean ("sensitive",
282                                                          P_("Sensitive"),
283                                                          P_("Display the cell sensitive"),
284                                                          TRUE,
285                                                          GTK_PARAM_READWRITE));
286
287   g_object_class_install_property (object_class,
288                                    PROP_XALIGN,
289                                    g_param_spec_float ("xalign",
290                                                        P_("xalign"),
291                                                        P_("The x-align"),
292                                                        0.0,
293                                                        1.0,
294                                                        0.5,
295                                                        GTK_PARAM_READWRITE));
296
297   g_object_class_install_property (object_class,
298                                    PROP_YALIGN,
299                                    g_param_spec_float ("yalign",
300                                                        P_("yalign"),
301                                                        P_("The y-align"),
302                                                        0.0,
303                                                        1.0,
304                                                        0.5,
305                                                        GTK_PARAM_READWRITE));
306
307   g_object_class_install_property (object_class,
308                                    PROP_XPAD,
309                                    g_param_spec_uint ("xpad",
310                                                       P_("xpad"),
311                                                       P_("The xpad"),
312                                                       0,
313                                                       G_MAXUINT,
314                                                       0,
315                                                       GTK_PARAM_READWRITE));
316
317   g_object_class_install_property (object_class,
318                                    PROP_YPAD,
319                                    g_param_spec_uint ("ypad",
320                                                       P_("ypad"),
321                                                       P_("The ypad"),
322                                                       0,
323                                                       G_MAXUINT,
324                                                       0,
325                                                       GTK_PARAM_READWRITE));
326
327   g_object_class_install_property (object_class,
328                                    PROP_WIDTH,
329                                    g_param_spec_int ("width",
330                                                      P_("width"),
331                                                      P_("The fixed width"),
332                                                      -1,
333                                                      G_MAXINT,
334                                                      -1,
335                                                      GTK_PARAM_READWRITE));
336
337   g_object_class_install_property (object_class,
338                                    PROP_HEIGHT,
339                                    g_param_spec_int ("height",
340                                                      P_("height"),
341                                                      P_("The fixed height"),
342                                                      -1,
343                                                      G_MAXINT,
344                                                      -1,
345                                                      GTK_PARAM_READWRITE));
346
347   g_object_class_install_property (object_class,
348                                    PROP_IS_EXPANDER,
349                                    g_param_spec_boolean ("is-expander",
350                                                          P_("Is Expander"),
351                                                          P_("Row has children"),
352                                                          FALSE,
353                                                          GTK_PARAM_READWRITE));
354
355
356   g_object_class_install_property (object_class,
357                                    PROP_IS_EXPANDED,
358                                    g_param_spec_boolean ("is-expanded",
359                                                          P_("Is Expanded"),
360                                                          P_("Row is an expander row, and is expanded"),
361                                                          FALSE,
362                                                          GTK_PARAM_READWRITE));
363
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"),
369                                                         NULL,
370                                                         GTK_PARAM_WRITABLE));
371
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"),
377                                                        GDK_TYPE_COLOR,
378                                                        GTK_PARAM_READWRITE));
379   /**
380    * GtkCellRenderer:cell-background-rgba:
381    *
382    * Cell background as a #GdkRGBA
383    *
384    * Since: 3.0
385    */
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"),
391                                                        GDK_TYPE_RGBA,
392                                                        GTK_PARAM_READWRITE));
393
394   g_object_class_install_property (object_class,
395                                    PROP_EDITING,
396                                    g_param_spec_boolean ("editing",
397                                                          P_("Editing"),
398                                                          P_("Whether the cell renderer is currently in editing mode"),
399                                                          FALSE,
400                                                          GTK_PARAM_READABLE));
401
402
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))
404
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"));
408
409   g_type_class_add_private (class, sizeof (GtkCellRendererPrivate));
410 }
411
412 static void
413 gtk_cell_renderer_get_property (GObject     *object,
414                                 guint        param_id,
415                                 GValue      *value,
416                                 GParamSpec  *pspec)
417 {
418   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
419   GtkCellRendererPrivate *priv = cell->priv;
420
421   switch (param_id)
422     {
423     case PROP_MODE:
424       g_value_set_enum (value, priv->mode);
425       break;
426     case PROP_VISIBLE:
427       g_value_set_boolean (value, priv->visible);
428       break;
429     case PROP_SENSITIVE:
430       g_value_set_boolean (value, priv->sensitive);
431       break;
432     case PROP_EDITING:
433       g_value_set_boolean (value, priv->editing);
434       break;
435     case PROP_XALIGN:
436       g_value_set_float (value, priv->xalign);
437       break;
438     case PROP_YALIGN:
439       g_value_set_float (value, priv->yalign);
440       break;
441     case PROP_XPAD:
442       g_value_set_uint (value, priv->xpad);
443       break;
444     case PROP_YPAD:
445       g_value_set_uint (value, priv->ypad);
446       break;
447     case PROP_WIDTH:
448       g_value_set_int (value, priv->width);
449       break;
450     case PROP_HEIGHT:
451       g_value_set_int (value, priv->height);
452       break;
453     case PROP_IS_EXPANDER:
454       g_value_set_boolean (value, priv->is_expander);
455       break;
456     case PROP_IS_EXPANDED:
457       g_value_set_boolean (value, priv->is_expanded);
458       break;
459     case PROP_CELL_BACKGROUND_GDK:
460       {
461         GdkColor color;
462
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);
466
467         g_value_set_boxed (value, &color);
468       }
469       break;
470     case PROP_CELL_BACKGROUND_RGBA:
471       g_value_set_boxed (value, &priv->cell_background);
472       break;
473     case PROP_CELL_BACKGROUND_SET:
474       g_value_set_boolean (value, priv->cell_background_set);
475       break;
476     case PROP_CELL_BACKGROUND:
477     default:
478       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
479       break;
480     }
481
482 }
483
484 static void
485 gtk_cell_renderer_set_property (GObject      *object,
486                                 guint         param_id,
487                                 const GValue *value,
488                                 GParamSpec   *pspec)
489 {
490   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
491   GtkCellRendererPrivate *priv = cell->priv;
492
493   switch (param_id)
494     {
495     case PROP_MODE:
496       priv->mode = g_value_get_enum (value);
497       break;
498     case PROP_VISIBLE:
499       priv->visible = g_value_get_boolean (value);
500       break;
501     case PROP_SENSITIVE:
502       priv->sensitive = g_value_get_boolean (value);
503       break;
504     case PROP_EDITING:
505       priv->editing = g_value_get_boolean (value);
506       break;
507     case PROP_XALIGN:
508       priv->xalign = g_value_get_float (value);
509       break;
510     case PROP_YALIGN:
511       priv->yalign = g_value_get_float (value);
512       break;
513     case PROP_XPAD:
514       priv->xpad = g_value_get_uint (value);
515       break;
516     case PROP_YPAD:
517       priv->ypad = g_value_get_uint (value);
518       break;
519     case PROP_WIDTH:
520       priv->width = g_value_get_int (value);
521       break;
522     case PROP_HEIGHT:
523       priv->height = g_value_get_int (value);
524       break;
525     case PROP_IS_EXPANDER:
526       priv->is_expander = g_value_get_boolean (value);
527       break;
528     case PROP_IS_EXPANDED:
529       priv->is_expanded = g_value_get_boolean (value);
530       break;
531     case PROP_CELL_BACKGROUND:
532       {
533         GdkRGBA rgba;
534
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);
539         else
540           g_warning ("Don't know color `%s'", g_value_get_string (value));
541
542         g_object_notify (object, "cell-background-gdk");
543       }
544       break;
545     case PROP_CELL_BACKGROUND_GDK:
546       {
547         GdkColor *color;
548
549         color = g_value_get_boxed (value);
550         if (color)
551           {
552             GdkRGBA rgba;
553
554             rgba.red = color->red / 65535.;
555             rgba.green = color->green / 65535.;
556             rgba.blue = color->blue / 65535.;
557             rgba.alpha = 1;
558
559             set_cell_bg_color (cell, &rgba);
560           }
561         else
562           {
563             set_cell_bg_color (cell, NULL);
564           }
565       }
566       break;
567     case PROP_CELL_BACKGROUND_RGBA:
568       set_cell_bg_color (cell, g_value_get_boxed (value));
569       break;
570     case PROP_CELL_BACKGROUND_SET:
571       priv->cell_background_set = g_value_get_boolean (value);
572       break;
573     default:
574       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
575       break;
576     }
577 }
578
579 static void
580 set_cell_bg_color (GtkCellRenderer *cell,
581                    GdkRGBA         *rgba)
582 {
583   GtkCellRendererPrivate *priv = cell->priv;
584
585   if (rgba)
586     {
587       if (!priv->cell_background_set)
588         {
589           priv->cell_background_set = TRUE;
590           g_object_notify (G_OBJECT (cell), "cell-background-set");
591         }
592
593       priv->cell_background = *rgba;
594     }
595   else
596     {
597       if (priv->cell_background_set)
598         {
599           priv->cell_background_set = FALSE;
600           g_object_notify (G_OBJECT (cell), "cell-background-set");
601         }
602     }
603 }
604
605 /**
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
614  *
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. 
619  *
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.
622  *
623  *
624  * Deprecated: 3.0: Use gtk_cell_renderer_get_preferred_size() instead.
625  **/
626 void
627 gtk_cell_renderer_get_size (GtkCellRenderer    *cell,
628                             GtkWidget          *widget,
629                             const GdkRectangle *cell_area,
630                             gint               *x_offset,
631                             gint               *y_offset,
632                             gint               *width,
633                             gint               *height)
634 {
635   GtkRequisition request;
636
637   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
638
639   gtk_cell_renderer_get_preferred_size (cell, widget, &request, NULL);
640
641   if (width)
642     *width = request.width;
643   
644   if (height)
645     *height = request.height;
646
647   if (cell_area)
648     _gtk_cell_renderer_calc_offset (cell, cell_area, gtk_widget_get_direction (widget),
649                                     request.width, request.height, x_offset, y_offset);
650 }
651
652 /**
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
661  *
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
668  * @window.
669  **/
670 void
671 gtk_cell_renderer_render (GtkCellRenderer      *cell,
672                           cairo_t              *cr,
673                           GtkWidget            *widget,
674                           const GdkRectangle   *background_area,
675                           const GdkRectangle   *cell_area,
676                           GtkCellRendererState  flags)
677 {
678   gboolean selected = FALSE;
679   GtkCellRendererPrivate *priv = cell->priv;
680
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);
684
685   selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
686
687   cairo_save (cr);
688
689   if (priv->cell_background_set && !selected)
690     {
691       gdk_cairo_rectangle (cr, background_area);
692       gdk_cairo_set_source_rgba (cr, &priv->cell_background);
693       cairo_fill (cr);
694     }
695
696   GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
697                                               cr,
698                                               widget,
699                                               background_area,
700                                               cell_area,
701                                               flags);
702
703   cairo_restore (cr);
704 }
705
706 /**
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
716  *
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.
720  *
721  * Return value: %TRUE if the event was consumed/handled
722  **/
723 gboolean
724 gtk_cell_renderer_activate (GtkCellRenderer      *cell,
725                             GdkEvent             *event,
726                             GtkWidget            *widget,
727                             const gchar          *path,
728                             const GdkRectangle   *background_area,
729                             const GdkRectangle   *cell_area,
730                             GtkCellRendererState  flags)
731 {
732   GtkCellRendererPrivate *priv;
733
734   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
735
736   priv = cell->priv;
737
738   if (priv->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
739     return FALSE;
740
741   if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
742     return FALSE;
743
744   return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
745                                                        event,
746                                                        widget,
747                                                        path,
748                                                        (GdkRectangle *) background_area,
749                                                        (GdkRectangle *) cell_area,
750                                                        flags);
751 }
752
753 /**
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
763  *
764  * Passes an activate event to the cell renderer for possible processing.
765  *
766  * Return value: (transfer full): A new #GtkCellEditable, or %NULL
767  **/
768 GtkCellEditable *
769 gtk_cell_renderer_start_editing (GtkCellRenderer      *cell,
770                                  GdkEvent             *event,
771                                  GtkWidget            *widget,
772                                  const gchar          *path,
773                                  const GdkRectangle   *background_area,
774                                  const GdkRectangle   *cell_area,
775                                  GtkCellRendererState  flags)
776
777 {
778   GtkCellRendererPrivate *priv;
779   GtkCellEditable *editable;
780
781   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
782
783   priv = cell->priv;
784
785   if (priv->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
786     return NULL;
787
788   if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
789     return NULL;
790
791   editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
792                                                                 event,
793                                                                 widget,
794                                                                 path,
795                                                                 (GdkRectangle *) background_area,
796                                                                 (GdkRectangle *) cell_area,
797                                                                 flags);
798
799   g_signal_emit (cell, 
800                  cell_renderer_signals[EDITING_STARTED], 0,
801                  editable, path);
802
803   priv->editing = TRUE;
804
805   return editable;
806 }
807
808 /**
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
813  *
814  * Sets the renderer size to be explicit, independent of the properties set.
815  **/
816 void
817 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
818                                   gint             width,
819                                   gint             height)
820 {
821   GtkCellRendererPrivate *priv;
822
823   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
824   g_return_if_fail (width >= -1 && height >= -1);
825
826   priv = cell->priv;
827
828   if ((width != priv->width) || (height != priv->height))
829     {
830       g_object_freeze_notify (G_OBJECT (cell));
831
832       if (width != priv->width)
833         {
834           priv->width = width;
835           g_object_notify (G_OBJECT (cell), "width");
836         }
837
838       if (height != priv->height)
839         {
840           priv->height = height;
841           g_object_notify (G_OBJECT (cell), "height");
842         }
843
844       g_object_thaw_notify (G_OBJECT (cell));
845     }
846 }
847
848 /**
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
853  *
854  * Fills in @width and @height with the appropriate size of @cell.
855  **/
856 void
857 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
858                                   gint            *width,
859                                   gint            *height)
860 {
861   GtkCellRendererPrivate *priv;
862
863   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
864
865   priv = cell->priv;
866
867   if (width)
868     *width = priv->width;
869   if (height)
870     *height = priv->height;
871 }
872
873 /**
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
878  *
879  * Sets the renderer's alignment within its available space.
880  *
881  * Since: 2.18
882  **/
883 void
884 gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
885                                  gfloat           xalign,
886                                  gfloat           yalign)
887 {
888   GtkCellRendererPrivate *priv;
889
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);
893
894   priv = cell->priv;
895
896   if ((xalign != priv->xalign) || (yalign != priv->yalign))
897     {
898       g_object_freeze_notify (G_OBJECT (cell));
899
900       if (xalign != priv->xalign)
901         {
902           priv->xalign = xalign;
903           g_object_notify (G_OBJECT (cell), "xalign");
904         }
905
906       if (yalign != priv->yalign)
907         {
908           priv->yalign = yalign;
909           g_object_notify (G_OBJECT (cell), "yalign");
910         }
911
912       g_object_thaw_notify (G_OBJECT (cell));
913     }
914 }
915
916 /**
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
921  *
922  * Fills in @xalign and @yalign with the appropriate values of @cell.
923  *
924  * Since: 2.18
925  **/
926 void
927 gtk_cell_renderer_get_alignment (GtkCellRenderer *cell,
928                                  gfloat          *xalign,
929                                  gfloat          *yalign)
930 {
931   GtkCellRendererPrivate *priv;
932
933   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
934
935   priv = cell->priv;
936
937   if (xalign)
938     *xalign = priv->xalign;
939   if (yalign)
940     *yalign = priv->yalign;
941 }
942
943 /**
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
948  *
949  * Sets the renderer's padding.
950  *
951  * Since: 2.18
952  **/
953 void
954 gtk_cell_renderer_set_padding (GtkCellRenderer *cell,
955                                gint             xpad,
956                                gint             ypad)
957 {
958   GtkCellRendererPrivate *priv;
959
960   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
961   g_return_if_fail (xpad >= 0 && xpad >= 0);
962
963   priv = cell->priv;
964
965   if ((xpad != priv->xpad) || (ypad != priv->ypad))
966     {
967       g_object_freeze_notify (G_OBJECT (cell));
968
969       if (xpad != priv->xpad)
970         {
971           priv->xpad = xpad;
972           g_object_notify (G_OBJECT (cell), "xpad");
973         }
974
975       if (ypad != priv->ypad)
976         {
977           priv->ypad = ypad;
978           g_object_notify (G_OBJECT (cell), "ypad");
979         }
980
981       g_object_thaw_notify (G_OBJECT (cell));
982     }
983 }
984
985 /**
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
990  *
991  * Fills in @xpad and @ypad with the appropriate values of @cell.
992  *
993  * Since: 2.18
994  **/
995 void
996 gtk_cell_renderer_get_padding (GtkCellRenderer *cell,
997                                gint            *xpad,
998                                gint            *ypad)
999 {
1000   GtkCellRendererPrivate *priv;
1001
1002   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1003
1004   priv = cell->priv;
1005
1006   if (xpad)
1007     *xpad = priv->xpad;
1008   if (ypad)
1009     *ypad = priv->ypad;
1010 }
1011
1012 /**
1013  * gtk_cell_renderer_set_visible:
1014  * @cell: A #GtkCellRenderer
1015  * @visible: the visibility of the cell
1016  *
1017  * Sets the cell renderer's visibility.
1018  *
1019  * Since: 2.18
1020  **/
1021 void
1022 gtk_cell_renderer_set_visible (GtkCellRenderer *cell,
1023                                gboolean         visible)
1024 {
1025   GtkCellRendererPrivate *priv;
1026
1027   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1028
1029   priv = cell->priv;
1030
1031   if (priv->visible != visible)
1032     {
1033       priv->visible = visible ? TRUE : FALSE;
1034       g_object_notify (G_OBJECT (cell), "visible");
1035     }
1036 }
1037
1038 /**
1039  * gtk_cell_renderer_get_visible:
1040  * @cell: A #GtkCellRenderer
1041  *
1042  * Returns the cell renderer's visibility.
1043  *
1044  * Returns: %TRUE if the cell renderer is visible
1045  *
1046  * Since: 2.18
1047  */
1048 gboolean
1049 gtk_cell_renderer_get_visible (GtkCellRenderer *cell)
1050 {
1051   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1052
1053   return cell->priv->visible;
1054 }
1055
1056 /**
1057  * gtk_cell_renderer_set_sensitive:
1058  * @cell: A #GtkCellRenderer
1059  * @sensitive: the sensitivity of the cell
1060  *
1061  * Sets the cell renderer's sensitivity.
1062  *
1063  * Since: 2.18
1064  **/
1065 void
1066 gtk_cell_renderer_set_sensitive (GtkCellRenderer *cell,
1067                                  gboolean         sensitive)
1068 {
1069   GtkCellRendererPrivate *priv;
1070
1071   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1072
1073   priv = cell->priv;
1074
1075   if (priv->sensitive != sensitive)
1076     {
1077       priv->sensitive = sensitive ? TRUE : FALSE;
1078       g_object_notify (G_OBJECT (cell), "sensitive");
1079     }
1080 }
1081
1082 /**
1083  * gtk_cell_renderer_get_sensitive:
1084  * @cell: A #GtkCellRenderer
1085  *
1086  * Returns the cell renderer's sensitivity.
1087  *
1088  * Returns: %TRUE if the cell renderer is sensitive
1089  *
1090  * Since: 2.18
1091  */
1092 gboolean
1093 gtk_cell_renderer_get_sensitive (GtkCellRenderer *cell)
1094 {
1095   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1096
1097   return cell->priv->sensitive;
1098 }
1099
1100
1101 /**
1102  * gtk_cell_renderer_can_focus:
1103  * @cell: A #GtkCellRenderer
1104  *
1105  * Checks whether the cell renderer can receive focus.
1106  *
1107  * Returns: %TRUE if the cell renderer can do anything with keyboard focus
1108  *
1109  * Since: 3.0
1110  */
1111 gboolean
1112 gtk_cell_renderer_can_focus (GtkCellRenderer *cell)
1113 {
1114   GtkCellRendererPrivate *priv;
1115
1116   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1117
1118   priv = cell->priv;
1119
1120   return (cell->priv->visible &&
1121           (cell->priv->mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1122            cell->priv->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE));
1123 }
1124
1125
1126 /**
1127  * gtk_cell_renderer_stop_editing:
1128  * @cell: A #GtkCellRenderer
1129  * @canceled: %TRUE if the editing has been canceled
1130  * 
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. 
1134  *
1135  * This function should be called by cell renderer implementations 
1136  * in response to the #GtkCellEditable::editing-done signal of 
1137  * #GtkCellEditable.
1138  *
1139  * Since: 2.6
1140  **/
1141 void
1142 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1143                                 gboolean         canceled)
1144 {
1145   GtkCellRendererPrivate *priv;
1146
1147   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1148
1149   priv = cell->priv;
1150
1151   if (priv->editing)
1152     {
1153       priv->editing = FALSE;
1154       if (canceled)
1155         g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1156     }
1157 }
1158
1159 static void
1160 gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer   *cell,
1161                                            GtkWidget         *widget,
1162                                            GtkOrientation     orientation,
1163                                            gint              *minimum_size,
1164                                            gint              *natural_size)
1165 {
1166   GtkRequisition min_req;
1167
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);
1172   else
1173     {
1174       min_req.width = 0;
1175       min_req.height = 0;
1176     }
1177
1178   if (orientation == GTK_ORIENTATION_HORIZONTAL)
1179     {
1180       if (minimum_size)
1181         *minimum_size = min_req.width;
1182
1183       if (natural_size)
1184         *natural_size = min_req.width;
1185     }
1186   else
1187     {
1188       if (minimum_size)
1189         *minimum_size = min_req.height;
1190
1191       if (natural_size)
1192         *natural_size = min_req.height;
1193     }
1194 }
1195
1196 static void
1197 gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
1198                                             GtkWidget       *widget,
1199                                             gint            *minimum_size,
1200                                             gint            *natural_size)
1201 {
1202   gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL, 
1203                                              minimum_size, natural_size);
1204 }
1205
1206 static void
1207 gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
1208                                              GtkWidget       *widget,
1209                                              gint            *minimum_size,
1210                                              gint            *natural_size)
1211 {
1212   gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL, 
1213                                              minimum_size, natural_size);
1214 }
1215
1216
1217 static void
1218 gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
1219                                                        GtkWidget       *widget,
1220                                                        gint             width,
1221                                                        gint            *minimum_height,
1222                                                        gint            *natural_height)
1223 {
1224   /* Fall back on the height reported from ->get_size() */
1225   gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
1226 }
1227
1228 static void
1229 gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
1230                                                        GtkWidget       *widget,
1231                                                        gint             height,
1232                                                        gint            *minimum_width,
1233                                                        gint            *natural_width)
1234 {
1235   /* Fall back on the width reported from ->get_size() */
1236   gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
1237 }
1238
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).
1242  *
1243  * Note this is only a trivial 'align * (allocation - request)' operation.
1244  */
1245 void
1246 _gtk_cell_renderer_calc_offset    (GtkCellRenderer      *cell,
1247                                    const GdkRectangle   *cell_area,
1248                                    GtkTextDirection      direction,
1249                                    gint                  width,
1250                                    gint                  height,
1251                                    gint                 *x_offset,
1252                                    gint                 *y_offset)
1253
1254   GtkCellRendererPrivate *priv;
1255
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);
1259
1260   priv = cell->priv;
1261
1262   if (x_offset)
1263     {
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);
1268     }
1269   if (y_offset)
1270     {
1271       *y_offset = (priv->yalign *
1272                    (cell_area->height - height));
1273       *y_offset = MAX (*y_offset, 0);
1274     }
1275 }
1276
1277 /**
1278  * gtk_cell_renderer_get_request_mode:
1279  * @cell: a #GtkCellRenderer    instance
1280  *
1281  * Gets whether the cell renderer prefers a height-for-width layout
1282  * or a width-for-height layout.
1283  *
1284  * Returns: The #GtkSizeRequestMode preferred by this renderer.
1285  *
1286  * Since: 3.0
1287  */
1288 GtkSizeRequestMode
1289 gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
1290 {
1291   GtkCellRendererClass *klass;
1292
1293   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1294
1295   klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1296   if (klass->get_request_mode)
1297     return klass->get_request_mode (cell);
1298
1299   /* By default cell renderers are height-for-width. */
1300   return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1301 }
1302
1303 /**
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
1309  *
1310  * Retreives a renderer's natural size when rendered to @widget.
1311  *
1312  * Since: 3.0
1313  */
1314 void
1315 gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
1316                                        GtkWidget       *widget,
1317                                        gint            *minimum_size,
1318                                        gint            *natural_size)
1319 {
1320   GtkCellRendererClass *klass;
1321   gint width;
1322
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);
1326
1327   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1328
1329   if (width < 0)
1330     {
1331       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1332       klass->get_preferred_width (cell, widget, minimum_size, natural_size);
1333     }
1334   else
1335     {
1336       if (minimum_size)
1337         *minimum_size = width;
1338       if (natural_size)
1339         *natural_size = width;
1340     }
1341
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);
1347 #endif
1348 }
1349
1350
1351 /**
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
1357  *
1358  * Retreives a renderer's natural size when rendered to @widget.
1359  *
1360  * Since: 3.0
1361  */
1362 void
1363 gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
1364                                         GtkWidget       *widget,
1365                                         gint            *minimum_size,
1366                                         gint            *natural_size)
1367 {
1368   GtkCellRendererClass *klass;
1369   gint height;
1370
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);
1374
1375   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1376
1377   if (height < 0)
1378     {
1379       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1380       klass->get_preferred_height (cell, widget, minimum_size, natural_size);
1381     }
1382   else
1383     {
1384       if (minimum_size)
1385         *minimum_size = height;
1386       if (natural_size)
1387         *natural_size = height;
1388     }
1389
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);
1395 #endif
1396 }
1397
1398
1399 /**
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
1406  *
1407  * Retreives a cell renderers's minimum and natural width if it were rendered to 
1408  * @widget with the specified @height.
1409  *
1410  * Since: 3.0
1411  */
1412 void
1413 gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
1414                                                   GtkWidget       *widget,
1415                                                   gint             height,
1416                                                   gint            *minimum_width,
1417                                                   gint            *natural_width)
1418 {
1419   GtkCellRendererClass *klass;
1420   gint width;
1421
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);
1425
1426   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1427
1428   if (width < 0)
1429     {
1430       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1431       klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
1432     }
1433   else
1434     {
1435       if (minimum_width)
1436         *minimum_width = width;
1437       if (natural_width)
1438         *natural_width = width;
1439     }
1440
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);
1446 #endif
1447 }
1448
1449 /**
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
1456  *
1457  * Retreives a cell renderers's minimum and natural height if it were rendered to 
1458  * @widget with the specified @width.
1459  *
1460  * Since: 3.0
1461  */
1462 void
1463 gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
1464                                                   GtkWidget       *widget,
1465                                                   gint             width,
1466                                                   gint            *minimum_height,
1467                                                   gint            *natural_height)
1468 {
1469   GtkCellRendererClass *klass;
1470   gint height;
1471
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);
1475
1476   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1477
1478   if (height < 0)
1479     {
1480       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1481       klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
1482     }
1483   else
1484     {
1485       if (minimum_height)
1486         *minimum_height = height;
1487       if (natural_height)
1488         *natural_height = height;
1489     }
1490
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);
1496 #endif
1497 }
1498
1499 /**
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
1507  *
1508  * Retrieves the minimum and natural size of a cell taking
1509  * into account the widget's preference for height-for-width management.
1510  *
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.
1513  *
1514  * Since: 3.0
1515  */
1516 void
1517 gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
1518                                       GtkWidget       *widget,
1519                                       GtkRequisition  *minimum_size,
1520                                       GtkRequisition  *natural_size)
1521 {
1522   gint min_width, nat_width;
1523   gint min_height, nat_height;
1524
1525   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1526
1527   if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1528     {
1529       gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
1530
1531       if (minimum_size)
1532         {
1533           minimum_size->width = min_width;
1534           gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
1535                                                             &minimum_size->height, NULL);
1536         }
1537
1538       if (natural_size)
1539         {
1540           natural_size->width = nat_width;
1541           gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
1542                                                             NULL, &natural_size->height);
1543         }
1544     }
1545   else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1546     {
1547       gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
1548
1549       if (minimum_size)
1550         {
1551           minimum_size->height = min_height;
1552           gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
1553                                                             &minimum_size->width, NULL);
1554         }
1555
1556       if (natural_size)
1557         {
1558           natural_size->height = nat_height;
1559           gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
1560                                                             NULL, &natural_size->width);
1561         }
1562     }
1563 }