]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellrenderer.c
rgba: Invert the arguments and improve bindability
[~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 (&rgba, g_value_get_string (value)))
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  * gtk_cell_renderer_stop_editing:
1102  * @cell: A #GtkCellRenderer
1103  * @canceled: %TRUE if the editing has been canceled
1104  * 
1105  * Informs the cell renderer that the editing is stopped.
1106  * If @canceled is %TRUE, the cell renderer will emit the 
1107  * #GtkCellRenderer::editing-canceled signal. 
1108  *
1109  * This function should be called by cell renderer implementations 
1110  * in response to the #GtkCellEditable::editing-done signal of 
1111  * #GtkCellEditable.
1112  *
1113  * Since: 2.6
1114  **/
1115 void
1116 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1117                                 gboolean         canceled)
1118 {
1119   GtkCellRendererPrivate *priv;
1120
1121   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1122
1123   priv = cell->priv;
1124
1125   if (priv->editing)
1126     {
1127       priv->editing = FALSE;
1128       if (canceled)
1129         g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1130     }
1131 }
1132
1133 static void
1134 gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer   *cell,
1135                                            GtkWidget         *widget,
1136                                            GtkOrientation     orientation,
1137                                            gint              *minimum_size,
1138                                            gint              *natural_size)
1139 {
1140   GtkRequisition min_req;
1141
1142   /* Fallback on the old API to get the size. */
1143   if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size)
1144     GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL,
1145                                                   &min_req.width, &min_req.height);
1146   else
1147     {
1148       min_req.width = 0;
1149       min_req.height = 0;
1150     }
1151
1152   if (orientation == GTK_ORIENTATION_HORIZONTAL)
1153     {
1154       if (minimum_size)
1155         *minimum_size = min_req.width;
1156
1157       if (natural_size)
1158         *natural_size = min_req.width;
1159     }
1160   else
1161     {
1162       if (minimum_size)
1163         *minimum_size = min_req.height;
1164
1165       if (natural_size)
1166         *natural_size = min_req.height;
1167     }
1168 }
1169
1170 static void
1171 gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
1172                                             GtkWidget       *widget,
1173                                             gint            *minimum_size,
1174                                             gint            *natural_size)
1175 {
1176   gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL, 
1177                                              minimum_size, natural_size);
1178 }
1179
1180 static void
1181 gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
1182                                              GtkWidget       *widget,
1183                                              gint            *minimum_size,
1184                                              gint            *natural_size)
1185 {
1186   gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL, 
1187                                              minimum_size, natural_size);
1188 }
1189
1190
1191 static void
1192 gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
1193                                                        GtkWidget       *widget,
1194                                                        gint             width,
1195                                                        gint            *minimum_height,
1196                                                        gint            *natural_height)
1197 {
1198   /* Fall back on the height reported from ->get_size() */
1199   gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
1200 }
1201
1202 static void
1203 gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
1204                                                        GtkWidget       *widget,
1205                                                        gint             height,
1206                                                        gint            *minimum_width,
1207                                                        gint            *natural_width)
1208 {
1209   /* Fall back on the width reported from ->get_size() */
1210   gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
1211 }
1212
1213 /* An internal convenience function for some containers to peek at the
1214  * cell alignment in a target allocation (used to draw focus and align
1215  * cells in the icon view).
1216  *
1217  * Note this is only a trivial 'align * (allocation - request)' operation.
1218  */
1219 void
1220 _gtk_cell_renderer_calc_offset    (GtkCellRenderer      *cell,
1221                                    const GdkRectangle   *cell_area,
1222                                    GtkTextDirection      direction,
1223                                    gint                  width,
1224                                    gint                  height,
1225                                    gint                 *x_offset,
1226                                    gint                 *y_offset)
1227
1228   GtkCellRendererPrivate *priv;
1229
1230   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1231   g_return_if_fail (cell_area != NULL);
1232   g_return_if_fail (x_offset || y_offset);
1233
1234   priv = cell->priv;
1235
1236   if (x_offset)
1237     {
1238       *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
1239                     (1.0 - priv->xalign) : priv->xalign) * 
1240                    (cell_area->width - width));
1241       *x_offset = MAX (*x_offset, 0);
1242     }
1243   if (y_offset)
1244     {
1245       *y_offset = (priv->yalign *
1246                    (cell_area->height - height));
1247       *y_offset = MAX (*y_offset, 0);
1248     }
1249 }
1250
1251 /**
1252  * gtk_cell_renderer_get_request_mode:
1253  * @cell: a #GtkCellRenderer    instance
1254  *
1255  * Gets whether the cell renderer prefers a height-for-width layout
1256  * or a width-for-height layout.
1257  *
1258  * Returns: The #GtkSizeRequestMode preferred by this renderer.
1259  *
1260  * Since: 3.0
1261  */
1262 GtkSizeRequestMode
1263 gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
1264 {
1265   GtkCellRendererClass *klass;
1266
1267   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1268
1269   klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1270   if (klass->get_request_mode)
1271     return klass->get_request_mode (cell);
1272
1273   /* By default cell renderers are height-for-width. */
1274   return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1275 }
1276
1277 /**
1278  * gtk_cell_renderer_get_preferred_width:
1279  * @cell: a #GtkCellRenderer instance
1280  * @widget: the #GtkWidget this cell will be rendering to
1281  * @minimum_size: location to store the minimum size, or %NULL
1282  * @natural_size: location to store the natural size, or %NULL
1283  *
1284  * Retreives a renderer's natural size when rendered to @widget.
1285  *
1286  * Since: 3.0
1287  */
1288 void
1289 gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
1290                                        GtkWidget       *widget,
1291                                        gint            *minimum_size,
1292                                        gint            *natural_size)
1293 {
1294   GtkCellRendererClass *klass;
1295   gint width;
1296
1297   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1298   g_return_if_fail (GTK_IS_WIDGET (widget));
1299   g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1300
1301   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1302
1303   if (width < 0)
1304     {
1305       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1306       klass->get_preferred_width (cell, widget, minimum_size, natural_size);
1307     }
1308   else
1309     {
1310       if (minimum_size)
1311         *minimum_size = width;
1312       if (natural_size)
1313         *natural_size = width;
1314     }
1315
1316 #if DEBUG_CELL_SIZE_REQUEST
1317   g_message ("%s returning minimum width: %d and natural width: %d",
1318              G_OBJECT_TYPE_NAME (cell), 
1319              minimum_size ? *minimum_size : 20000, 
1320              natural_size ? *natural_size : 20000);
1321 #endif
1322 }
1323
1324
1325 /**
1326  * gtk_cell_renderer_get_preferred_height:
1327  * @cell: a #GtkCellRenderer instance
1328  * @widget: the #GtkWidget this cell will be rendering to
1329  * @minimum_size: location to store the minimum size, or %NULL
1330  * @natural_size: location to store the natural size, or %NULL
1331  *
1332  * Retreives a renderer's natural size when rendered to @widget.
1333  *
1334  * Since: 3.0
1335  */
1336 void
1337 gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
1338                                         GtkWidget       *widget,
1339                                         gint            *minimum_size,
1340                                         gint            *natural_size)
1341 {
1342   GtkCellRendererClass *klass;
1343   gint height;
1344
1345   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1346   g_return_if_fail (GTK_IS_WIDGET (widget));
1347   g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1348
1349   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1350
1351   if (height < 0)
1352     {
1353       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1354       klass->get_preferred_height (cell, widget, minimum_size, natural_size);
1355     }
1356   else
1357     {
1358       if (minimum_size)
1359         *minimum_size = height;
1360       if (natural_size)
1361         *natural_size = height;
1362     }
1363
1364 #if DEBUG_CELL_SIZE_REQUEST
1365   g_message ("%s returning minimum height: %d and natural height: %d",
1366              G_OBJECT_TYPE_NAME (cell), 
1367              minimum_size ? *minimum_size : 20000, 
1368              natural_size ? *natural_size : 20000);
1369 #endif
1370 }
1371
1372
1373 /**
1374  * gtk_cell_renderer_get_preferred_width_for_height:
1375  * @cell: a #GtkCellRenderer instance
1376  * @widget: the #GtkWidget this cell will be rendering to
1377  * @height: the size which is available for allocation
1378  * @minimum_width: location for storing the minimum size, or %NULL
1379  * @natural_width: location for storing the preferred size, or %NULL
1380  *
1381  * Retreives a cell renderers's minimum and natural width if it were rendered to 
1382  * @widget with the specified @height.
1383  *
1384  * Since: 3.0
1385  */
1386 void
1387 gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
1388                                                   GtkWidget       *widget,
1389                                                   gint             height,
1390                                                   gint            *minimum_width,
1391                                                   gint            *natural_width)
1392 {
1393   GtkCellRendererClass *klass;
1394   gint width;
1395
1396   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1397   g_return_if_fail (GTK_IS_WIDGET (widget));
1398   g_return_if_fail (NULL != minimum_width || NULL != natural_width);
1399
1400   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1401
1402   if (width < 0)
1403     {
1404       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1405       klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
1406     }
1407   else
1408     {
1409       if (minimum_width)
1410         *minimum_width = width;
1411       if (natural_width)
1412         *natural_width = width;
1413     }
1414
1415 #if DEBUG_CELL_SIZE_REQUEST
1416   g_message ("%s width for height: %d is minimum %d and natural: %d",
1417              G_OBJECT_TYPE_NAME (cell), height,
1418              minimum_width ? *minimum_width : 20000, 
1419              natural_width ? *natural_width : 20000);
1420 #endif
1421 }
1422
1423 /**
1424  * gtk_cell_renderer_get_preferred_height_for_width:
1425  * @cell: a #GtkCellRenderer instance
1426  * @widget: the #GtkWidget this cell will be rendering to
1427  * @width: the size which is available for allocation
1428  * @minimum_height: location for storing the minimum size, or %NULL
1429  * @natural_height: location for storing the preferred size, or %NULL
1430  *
1431  * Retreives a cell renderers's minimum and natural height if it were rendered to 
1432  * @widget with the specified @width.
1433  *
1434  * Since: 3.0
1435  */
1436 void
1437 gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
1438                                                   GtkWidget       *widget,
1439                                                   gint             width,
1440                                                   gint            *minimum_height,
1441                                                   gint            *natural_height)
1442 {
1443   GtkCellRendererClass *klass;
1444   gint height;
1445
1446   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1447   g_return_if_fail (GTK_IS_WIDGET (widget));
1448   g_return_if_fail (NULL != minimum_height || NULL != natural_height);
1449
1450   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1451
1452   if (height < 0)
1453     {
1454       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1455       klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
1456     }
1457   else
1458     {
1459       if (minimum_height)
1460         *minimum_height = height;
1461       if (natural_height)
1462         *natural_height = height;
1463     }
1464
1465 #if DEBUG_CELL_SIZE_REQUEST
1466   g_message ("%s height for width: %d is minimum %d and natural: %d",
1467              G_OBJECT_TYPE_NAME (cell), width,
1468              minimum_height ? *minimum_height : 20000, 
1469              natural_height ? *natural_height : 20000);
1470 #endif
1471 }
1472
1473 /**
1474  * gtk_cell_renderer_get_preferred_size:
1475  * @cell: a #GtkCellRenderer instance
1476  * @widget: the #GtkWidget this cell will be rendering to
1477  * @request_natural: Whether to base the contextual request off of the
1478  *     base natural or the base minimum
1479  * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
1480  * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
1481  *
1482  * Retrieves the minimum and natural size of a cell taking
1483  * into account the widget's preference for height-for-width management.
1484  *
1485  * If request_natural is specified, the non-contextual natural value will
1486  * be used to make the contextual request; otherwise the minimum will be used.
1487  *
1488  * Since: 3.0
1489  */
1490 void
1491 gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
1492                                       GtkWidget       *widget,
1493                                       GtkRequisition  *minimum_size,
1494                                       GtkRequisition  *natural_size)
1495 {
1496   gint min_width, nat_width;
1497   gint min_height, nat_height;
1498
1499   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1500
1501   if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1502     {
1503       gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
1504
1505       if (minimum_size)
1506         {
1507           minimum_size->width = min_width;
1508           gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
1509                                                             &minimum_size->height, NULL);
1510         }
1511
1512       if (natural_size)
1513         {
1514           natural_size->width = nat_width;
1515           gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
1516                                                             NULL, &natural_size->height);
1517         }
1518     }
1519   else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1520     {
1521       gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
1522
1523       if (minimum_size)
1524         {
1525           minimum_size->height = min_height;
1526           gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
1527                                                             &minimum_size->width, NULL);
1528         }
1529
1530       if (natural_size)
1531         {
1532           natural_size->height = nat_height;
1533           gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
1534                                                             NULL, &natural_size->width);
1535         }
1536     }
1537 }