]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellrenderer.c
Clip to cell_area when rendering cell content
[~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
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 #cairo_t.  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 #cairo_t. 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 static void gtk_cell_renderer_real_get_aligned_area              (GtkCellRenderer         *cell,
101                                                                   GtkWidget               *widget,
102                                                                   GtkCellRendererState     flags,
103                                                                   const GdkRectangle      *cell_area,
104                                                                   GdkRectangle            *aligned_area);
105
106
107 struct _GtkCellRendererPrivate
108 {
109   gfloat xalign;
110   gfloat yalign;
111
112   gint width;
113   gint height;
114
115   guint16 xpad;
116   guint16 ypad;
117
118   guint mode                : 2;
119   guint visible             : 1;
120   guint is_expander         : 1;
121   guint is_expanded         : 1;
122   guint cell_background_set : 1;
123   guint sensitive           : 1;
124   guint editing             : 1;
125
126   GdkRGBA cell_background;
127 };
128
129
130 enum {
131   PROP_0,
132   PROP_MODE,
133   PROP_VISIBLE,
134   PROP_SENSITIVE,
135   PROP_XALIGN,
136   PROP_YALIGN,
137   PROP_XPAD,
138   PROP_YPAD,
139   PROP_WIDTH,
140   PROP_HEIGHT,
141   PROP_IS_EXPANDER,
142   PROP_IS_EXPANDED,
143   PROP_CELL_BACKGROUND,
144   PROP_CELL_BACKGROUND_GDK,
145   PROP_CELL_BACKGROUND_RGBA,
146   PROP_CELL_BACKGROUND_SET,
147   PROP_EDITING
148 };
149
150 /* Signal IDs */
151 enum {
152   EDITING_CANCELED,
153   EDITING_STARTED,
154   LAST_SIGNAL
155 };
156
157 static guint  cell_renderer_signals[LAST_SIGNAL] = { 0 };
158
159 G_DEFINE_ABSTRACT_TYPE(GtkCellRenderer, gtk_cell_renderer, G_TYPE_INITIALLY_UNOWNED)
160
161 static void
162 gtk_cell_renderer_init (GtkCellRenderer *cell)
163 {
164   GtkCellRendererPrivate *priv;
165
166   cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
167                                             GTK_TYPE_CELL_RENDERER,
168                                             GtkCellRendererPrivate);
169   priv = cell->priv;
170
171   priv->mode = GTK_CELL_RENDERER_MODE_INERT;
172   priv->visible = TRUE;
173   priv->width = -1;
174   priv->height = -1;
175   priv->xalign = 0.5;
176   priv->yalign = 0.5;
177   priv->xpad = 0;
178   priv->ypad = 0;
179   priv->sensitive = TRUE;
180   priv->is_expander = FALSE;
181   priv->is_expanded = FALSE;
182   priv->editing = FALSE;
183 }
184
185 static void
186 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
187 {
188   GObjectClass *object_class = G_OBJECT_CLASS (class);
189
190   object_class->get_property = gtk_cell_renderer_get_property;
191   object_class->set_property = gtk_cell_renderer_set_property;
192
193   class->render = NULL;
194   class->get_size = NULL;
195   class->get_preferred_width            = gtk_cell_renderer_real_get_preferred_width;
196   class->get_preferred_height           = gtk_cell_renderer_real_get_preferred_height;
197   class->get_preferred_width_for_height = gtk_cell_renderer_real_get_preferred_width_for_height;
198   class->get_preferred_height_for_width = gtk_cell_renderer_real_get_preferred_height_for_width;
199   class->get_aligned_area               = gtk_cell_renderer_real_get_aligned_area;
200
201   /**
202    * GtkCellRenderer::editing-canceled:
203    * @renderer: the object which received the signal
204    *
205    * This signal gets emitted when the user cancels the process of editing a
206    * cell.  For example, an editable cell renderer could be written to cancel
207    * editing when the user presses Escape. 
208    *
209    * See also: gtk_cell_renderer_stop_editing().
210    *
211    * Since: 2.4
212    */
213   cell_renderer_signals[EDITING_CANCELED] =
214     g_signal_new (I_("editing-canceled"),
215                   G_OBJECT_CLASS_TYPE (object_class),
216                   G_SIGNAL_RUN_FIRST,
217                   G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
218                   NULL, NULL,
219                   _gtk_marshal_VOID__VOID,
220                   G_TYPE_NONE, 0);
221
222   /**
223    * GtkCellRenderer::editing-started:
224    * @renderer: the object which received the signal
225    * @editable: the #GtkCellEditable
226    * @path: the path identifying the edited cell
227    *
228    * This signal gets emitted when a cell starts to be edited.
229    * The intended use of this signal is to do special setup
230    * on @editable, e.g. adding a #GtkEntryCompletion or setting
231    * up additional columns in a #GtkComboBox.
232    *
233    * Note that GTK+ doesn't guarantee that cell renderers will
234    * continue to use the same kind of widget for editing in future
235    * releases, therefore you should check the type of @editable
236    * before doing any specific setup, as in the following example:
237    * |[
238    * static void
239    * text_editing_started (GtkCellRenderer *cell,
240    *                       GtkCellEditable *editable,
241    *                       const gchar     *path,
242    *                       gpointer         data)
243    * {
244    *   if (GTK_IS_ENTRY (editable)) 
245    *     {
246    *       GtkEntry *entry = GTK_ENTRY (editable);
247    *       
248    *       /&ast; ... create a GtkEntryCompletion &ast;/
249    *       
250    *       gtk_entry_set_completion (entry, completion);
251    *     }
252    * }
253    * ]|
254    *
255    * Since: 2.6
256    */
257   cell_renderer_signals[EDITING_STARTED] =
258     g_signal_new (I_("editing-started"),
259                   G_OBJECT_CLASS_TYPE (object_class),
260                   G_SIGNAL_RUN_FIRST,
261                   G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
262                   NULL, NULL,
263                   _gtk_marshal_VOID__OBJECT_STRING,
264                   G_TYPE_NONE, 2,
265                   GTK_TYPE_CELL_EDITABLE,
266                   G_TYPE_STRING);
267
268   g_object_class_install_property (object_class,
269                                    PROP_MODE,
270                                    g_param_spec_enum ("mode",
271                                                       P_("mode"),
272                                                       P_("Editable mode of the CellRenderer"),
273                                                       GTK_TYPE_CELL_RENDERER_MODE,
274                                                       GTK_CELL_RENDERER_MODE_INERT,
275                                                       GTK_PARAM_READWRITE));
276
277   g_object_class_install_property (object_class,
278                                    PROP_VISIBLE,
279                                    g_param_spec_boolean ("visible",
280                                                          P_("visible"),
281                                                          P_("Display the cell"),
282                                                          TRUE,
283                                                          GTK_PARAM_READWRITE));
284   g_object_class_install_property (object_class,
285                                    PROP_SENSITIVE,
286                                    g_param_spec_boolean ("sensitive",
287                                                          P_("Sensitive"),
288                                                          P_("Display the cell sensitive"),
289                                                          TRUE,
290                                                          GTK_PARAM_READWRITE));
291
292   g_object_class_install_property (object_class,
293                                    PROP_XALIGN,
294                                    g_param_spec_float ("xalign",
295                                                        P_("xalign"),
296                                                        P_("The x-align"),
297                                                        0.0,
298                                                        1.0,
299                                                        0.5,
300                                                        GTK_PARAM_READWRITE));
301
302   g_object_class_install_property (object_class,
303                                    PROP_YALIGN,
304                                    g_param_spec_float ("yalign",
305                                                        P_("yalign"),
306                                                        P_("The y-align"),
307                                                        0.0,
308                                                        1.0,
309                                                        0.5,
310                                                        GTK_PARAM_READWRITE));
311
312   g_object_class_install_property (object_class,
313                                    PROP_XPAD,
314                                    g_param_spec_uint ("xpad",
315                                                       P_("xpad"),
316                                                       P_("The xpad"),
317                                                       0,
318                                                       G_MAXUINT,
319                                                       0,
320                                                       GTK_PARAM_READWRITE));
321
322   g_object_class_install_property (object_class,
323                                    PROP_YPAD,
324                                    g_param_spec_uint ("ypad",
325                                                       P_("ypad"),
326                                                       P_("The ypad"),
327                                                       0,
328                                                       G_MAXUINT,
329                                                       0,
330                                                       GTK_PARAM_READWRITE));
331
332   g_object_class_install_property (object_class,
333                                    PROP_WIDTH,
334                                    g_param_spec_int ("width",
335                                                      P_("width"),
336                                                      P_("The fixed width"),
337                                                      -1,
338                                                      G_MAXINT,
339                                                      -1,
340                                                      GTK_PARAM_READWRITE));
341
342   g_object_class_install_property (object_class,
343                                    PROP_HEIGHT,
344                                    g_param_spec_int ("height",
345                                                      P_("height"),
346                                                      P_("The fixed height"),
347                                                      -1,
348                                                      G_MAXINT,
349                                                      -1,
350                                                      GTK_PARAM_READWRITE));
351
352   g_object_class_install_property (object_class,
353                                    PROP_IS_EXPANDER,
354                                    g_param_spec_boolean ("is-expander",
355                                                          P_("Is Expander"),
356                                                          P_("Row has children"),
357                                                          FALSE,
358                                                          GTK_PARAM_READWRITE));
359
360
361   g_object_class_install_property (object_class,
362                                    PROP_IS_EXPANDED,
363                                    g_param_spec_boolean ("is-expanded",
364                                                          P_("Is Expanded"),
365                                                          P_("Row is an expander row, and is expanded"),
366                                                          FALSE,
367                                                          GTK_PARAM_READWRITE));
368
369   g_object_class_install_property (object_class,
370                                    PROP_CELL_BACKGROUND,
371                                    g_param_spec_string ("cell-background",
372                                                         P_("Cell background color name"),
373                                                         P_("Cell background color as a string"),
374                                                         NULL,
375                                                         GTK_PARAM_WRITABLE));
376
377   g_object_class_install_property (object_class,
378                                    PROP_CELL_BACKGROUND_GDK,
379                                    g_param_spec_boxed ("cell-background-gdk",
380                                                        P_("Cell background color"),
381                                                        P_("Cell background color as a GdkColor"),
382                                                        GDK_TYPE_COLOR,
383                                                        GTK_PARAM_READWRITE));
384   /**
385    * GtkCellRenderer:cell-background-rgba:
386    *
387    * Cell background as a #GdkRGBA
388    *
389    * Since: 3.0
390    */
391   g_object_class_install_property (object_class,
392                                    PROP_CELL_BACKGROUND_RGBA,
393                                    g_param_spec_boxed ("cell-background-rgba",
394                                                        P_("Cell background RGBA color"),
395                                                        P_("Cell background color as a GdkRGBA"),
396                                                        GDK_TYPE_RGBA,
397                                                        GTK_PARAM_READWRITE));
398
399   g_object_class_install_property (object_class,
400                                    PROP_EDITING,
401                                    g_param_spec_boolean ("editing",
402                                                          P_("Editing"),
403                                                          P_("Whether the cell renderer is currently in editing mode"),
404                                                          FALSE,
405                                                          GTK_PARAM_READABLE));
406
407
408 #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))
409
410   ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
411                 P_("Cell background set"),
412                 P_("Whether this tag affects the cell background color"));
413
414   g_type_class_add_private (class, sizeof (GtkCellRendererPrivate));
415 }
416
417 static void
418 gtk_cell_renderer_get_property (GObject     *object,
419                                 guint        param_id,
420                                 GValue      *value,
421                                 GParamSpec  *pspec)
422 {
423   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
424   GtkCellRendererPrivate *priv = cell->priv;
425
426   switch (param_id)
427     {
428     case PROP_MODE:
429       g_value_set_enum (value, priv->mode);
430       break;
431     case PROP_VISIBLE:
432       g_value_set_boolean (value, priv->visible);
433       break;
434     case PROP_SENSITIVE:
435       g_value_set_boolean (value, priv->sensitive);
436       break;
437     case PROP_EDITING:
438       g_value_set_boolean (value, priv->editing);
439       break;
440     case PROP_XALIGN:
441       g_value_set_float (value, priv->xalign);
442       break;
443     case PROP_YALIGN:
444       g_value_set_float (value, priv->yalign);
445       break;
446     case PROP_XPAD:
447       g_value_set_uint (value, priv->xpad);
448       break;
449     case PROP_YPAD:
450       g_value_set_uint (value, priv->ypad);
451       break;
452     case PROP_WIDTH:
453       g_value_set_int (value, priv->width);
454       break;
455     case PROP_HEIGHT:
456       g_value_set_int (value, priv->height);
457       break;
458     case PROP_IS_EXPANDER:
459       g_value_set_boolean (value, priv->is_expander);
460       break;
461     case PROP_IS_EXPANDED:
462       g_value_set_boolean (value, priv->is_expanded);
463       break;
464     case PROP_CELL_BACKGROUND_GDK:
465       {
466         GdkColor color;
467
468         color.red = (guint16) (priv->cell_background.red * 65535);
469         color.green = (guint16) (priv->cell_background.green * 65535);
470         color.blue = (guint16) (priv->cell_background.blue * 65535);
471
472         g_value_set_boxed (value, &color);
473       }
474       break;
475     case PROP_CELL_BACKGROUND_RGBA:
476       g_value_set_boxed (value, &priv->cell_background);
477       break;
478     case PROP_CELL_BACKGROUND_SET:
479       g_value_set_boolean (value, priv->cell_background_set);
480       break;
481     case PROP_CELL_BACKGROUND:
482     default:
483       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
484       break;
485     }
486
487 }
488
489 static void
490 gtk_cell_renderer_set_property (GObject      *object,
491                                 guint         param_id,
492                                 const GValue *value,
493                                 GParamSpec   *pspec)
494 {
495   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
496   GtkCellRendererPrivate *priv = cell->priv;
497
498   switch (param_id)
499     {
500     case PROP_MODE:
501       priv->mode = g_value_get_enum (value);
502       break;
503     case PROP_VISIBLE:
504       priv->visible = g_value_get_boolean (value);
505       break;
506     case PROP_SENSITIVE:
507       priv->sensitive = g_value_get_boolean (value);
508       break;
509     case PROP_EDITING:
510       priv->editing = g_value_get_boolean (value);
511       break;
512     case PROP_XALIGN:
513       priv->xalign = g_value_get_float (value);
514       break;
515     case PROP_YALIGN:
516       priv->yalign = g_value_get_float (value);
517       break;
518     case PROP_XPAD:
519       priv->xpad = g_value_get_uint (value);
520       break;
521     case PROP_YPAD:
522       priv->ypad = g_value_get_uint (value);
523       break;
524     case PROP_WIDTH:
525       priv->width = g_value_get_int (value);
526       break;
527     case PROP_HEIGHT:
528       priv->height = g_value_get_int (value);
529       break;
530     case PROP_IS_EXPANDER:
531       priv->is_expander = g_value_get_boolean (value);
532       break;
533     case PROP_IS_EXPANDED:
534       priv->is_expanded = g_value_get_boolean (value);
535       break;
536     case PROP_CELL_BACKGROUND:
537       {
538         GdkRGBA rgba;
539
540         if (!g_value_get_string (value))
541           set_cell_bg_color (cell, NULL);
542         else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
543           set_cell_bg_color (cell, &rgba);
544         else
545           g_warning ("Don't know color `%s'", g_value_get_string (value));
546
547         g_object_notify (object, "cell-background-gdk");
548       }
549       break;
550     case PROP_CELL_BACKGROUND_GDK:
551       {
552         GdkColor *color;
553
554         color = g_value_get_boxed (value);
555         if (color)
556           {
557             GdkRGBA rgba;
558
559             rgba.red = color->red / 65535.;
560             rgba.green = color->green / 65535.;
561             rgba.blue = color->blue / 65535.;
562             rgba.alpha = 1;
563
564             set_cell_bg_color (cell, &rgba);
565           }
566         else
567           {
568             set_cell_bg_color (cell, NULL);
569           }
570       }
571       break;
572     case PROP_CELL_BACKGROUND_RGBA:
573       set_cell_bg_color (cell, g_value_get_boxed (value));
574       break;
575     case PROP_CELL_BACKGROUND_SET:
576       priv->cell_background_set = g_value_get_boolean (value);
577       break;
578     default:
579       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
580       break;
581     }
582 }
583
584 static void
585 set_cell_bg_color (GtkCellRenderer *cell,
586                    GdkRGBA         *rgba)
587 {
588   GtkCellRendererPrivate *priv = cell->priv;
589
590   if (rgba)
591     {
592       if (!priv->cell_background_set)
593         {
594           priv->cell_background_set = TRUE;
595           g_object_notify (G_OBJECT (cell), "cell-background-set");
596         }
597
598       priv->cell_background = *rgba;
599     }
600   else
601     {
602       if (priv->cell_background_set)
603         {
604           priv->cell_background_set = FALSE;
605           g_object_notify (G_OBJECT (cell), "cell-background-set");
606         }
607     }
608 }
609
610 /**
611  * gtk_cell_renderer_get_size:
612  * @cell: a #GtkCellRenderer
613  * @widget: the widget the renderer is rendering to
614  * @cell_area: (allow-none): The area a cell will be allocated, or %NULL
615  * @x_offset: (allow-none): location to return x offset of cell relative to @cell_area, or %NULL
616  * @y_offset: (allow-none): location to return y offset of cell relative to @cell_area, or %NULL
617  * @width: (allow-none): location to return width needed to render a cell, or %NULL
618  * @height: (allow-none): location to return height needed to render a cell, or %NULL
619  *
620  * Obtains the width and height needed to render the cell. Used by view 
621  * widgets to determine the appropriate size for the cell_area passed to
622  * gtk_cell_renderer_render().  If @cell_area is not %NULL, fills in the
623  * x and y offsets (if set) of the cell relative to this location. 
624  *
625  * Please note that the values set in @width and @height, as well as those 
626  * in @x_offset and @y_offset are inclusive of the xpad and ypad properties.
627  *
628  *
629  * Deprecated: 3.0: Use gtk_cell_renderer_get_preferred_size() instead.
630  **/
631 void
632 gtk_cell_renderer_get_size (GtkCellRenderer    *cell,
633                             GtkWidget          *widget,
634                             const GdkRectangle *cell_area,
635                             gint               *x_offset,
636                             gint               *y_offset,
637                             gint               *width,
638                             gint               *height)
639 {
640   GtkRequisition request;
641
642   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
643
644   gtk_cell_renderer_get_preferred_size (cell, widget, &request, NULL);
645
646   if (width)
647     *width = request.width;
648   
649   if (height)
650     *height = request.height;
651
652   if (cell_area)
653     _gtk_cell_renderer_calc_offset (cell, cell_area, gtk_widget_get_direction (widget),
654                                     request.width, request.height, x_offset, y_offset);
655 }
656
657 /**
658  * gtk_cell_renderer_render:
659  * @cell: a #GtkCellRenderer
660  * @cr: a cairo context to draw to
661  * @widget: the widget owning @window
662  * @background_area: entire cell area (including tree expanders and maybe 
663  *    padding on the sides)
664  * @cell_area: area normally rendered by a cell renderer
665  * @flags: flags that affect rendering
666  *
667  * Invokes the virtual render function of the #GtkCellRenderer. The three
668  * passed-in rectangles are areas in @cr. Most renderers will draw within
669  * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
670  * should be honored with respect to @cell_area. @background_area includes the
671  * blank space around the cell, and also the area containing the tree expander;
672  * so the @background_area rectangles for all cells tile to cover the entire
673  * @window.
674  **/
675 void
676 gtk_cell_renderer_render (GtkCellRenderer      *cell,
677                           cairo_t              *cr,
678                           GtkWidget            *widget,
679                           const GdkRectangle   *background_area,
680                           const GdkRectangle   *cell_area,
681                           GtkCellRendererState  flags)
682 {
683   gboolean selected = FALSE;
684   GtkCellRendererPrivate *priv = cell->priv;
685
686   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
687   g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
688   g_return_if_fail (cr != NULL);
689
690   selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
691
692   cairo_save (cr);
693
694   if (priv->cell_background_set && !selected)
695     {
696       gdk_cairo_rectangle (cr, background_area);
697       gdk_cairo_set_source_rgba (cr, &priv->cell_background);
698       cairo_fill (cr);
699     }
700
701   gdk_cairo_rectangle (cr, background_area);
702   cairo_clip (cr);
703
704   GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
705                                               cr,
706                                               widget,
707                                               background_area,
708                                               cell_area,
709                                               flags);
710
711   cairo_restore (cr);
712 }
713
714 /**
715  * gtk_cell_renderer_activate:
716  * @cell: a #GtkCellRenderer
717  * @event: a #GdkEvent
718  * @widget: widget that received the event
719  * @path: widget-dependent string representation of the event location; 
720  *    e.g. for #GtkTreeView, a string representation of #GtkTreePath
721  * @background_area: background area as passed to gtk_cell_renderer_render()
722  * @cell_area: cell area as passed to gtk_cell_renderer_render()
723  * @flags: render flags
724  *
725  * Passes an activate event to the cell renderer for possible processing.  
726  * Some cell renderers may use events; for example, #GtkCellRendererToggle 
727  * toggles when it gets a mouse click.
728  *
729  * Return value: %TRUE if the event was consumed/handled
730  **/
731 gboolean
732 gtk_cell_renderer_activate (GtkCellRenderer      *cell,
733                             GdkEvent             *event,
734                             GtkWidget            *widget,
735                             const gchar          *path,
736                             const GdkRectangle   *background_area,
737                             const GdkRectangle   *cell_area,
738                             GtkCellRendererState  flags)
739 {
740   GtkCellRendererPrivate *priv;
741
742   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
743
744   priv = cell->priv;
745
746   if (priv->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
747     return FALSE;
748
749   if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
750     return FALSE;
751
752   return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
753                                                        event,
754                                                        widget,
755                                                        path,
756                                                        (GdkRectangle *) background_area,
757                                                        (GdkRectangle *) cell_area,
758                                                        flags);
759 }
760
761 /**
762  * gtk_cell_renderer_start_editing:
763  * @cell: a #GtkCellRenderer
764  * @event: a #GdkEvent
765  * @widget: widget that received the event
766  * @path: widget-dependent string representation of the event location;
767  *    e.g. for #GtkTreeView, a string representation of #GtkTreePath
768  * @background_area: background area as passed to gtk_cell_renderer_render()
769  * @cell_area: cell area as passed to gtk_cell_renderer_render()
770  * @flags: render flags
771  *
772  * Passes an activate event to the cell renderer for possible processing.
773  *
774  * Return value: (transfer full): A new #GtkCellEditable, or %NULL
775  **/
776 GtkCellEditable *
777 gtk_cell_renderer_start_editing (GtkCellRenderer      *cell,
778                                  GdkEvent             *event,
779                                  GtkWidget            *widget,
780                                  const gchar          *path,
781                                  const GdkRectangle   *background_area,
782                                  const GdkRectangle   *cell_area,
783                                  GtkCellRendererState  flags)
784
785 {
786   GtkCellRendererPrivate *priv;
787   GtkCellEditable *editable;
788
789   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
790
791   priv = cell->priv;
792
793   if (priv->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
794     return NULL;
795
796   if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
797     return NULL;
798
799   editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
800                                                                 event,
801                                                                 widget,
802                                                                 path,
803                                                                 (GdkRectangle *) background_area,
804                                                                 (GdkRectangle *) cell_area,
805                                                                 flags);
806
807   g_signal_emit (cell, 
808                  cell_renderer_signals[EDITING_STARTED], 0,
809                  editable, path);
810
811   priv->editing = TRUE;
812
813   return editable;
814 }
815
816 /**
817  * gtk_cell_renderer_set_fixed_size:
818  * @cell: A #GtkCellRenderer
819  * @width: the width of the cell renderer, or -1
820  * @height: the height of the cell renderer, or -1
821  *
822  * Sets the renderer size to be explicit, independent of the properties set.
823  **/
824 void
825 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
826                                   gint             width,
827                                   gint             height)
828 {
829   GtkCellRendererPrivate *priv;
830
831   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
832   g_return_if_fail (width >= -1 && height >= -1);
833
834   priv = cell->priv;
835
836   if ((width != priv->width) || (height != priv->height))
837     {
838       g_object_freeze_notify (G_OBJECT (cell));
839
840       if (width != priv->width)
841         {
842           priv->width = width;
843           g_object_notify (G_OBJECT (cell), "width");
844         }
845
846       if (height != priv->height)
847         {
848           priv->height = height;
849           g_object_notify (G_OBJECT (cell), "height");
850         }
851
852       g_object_thaw_notify (G_OBJECT (cell));
853     }
854 }
855
856 /**
857  * gtk_cell_renderer_get_fixed_size:
858  * @cell: A #GtkCellRenderer
859  * @width: (allow-none): location to fill in with the fixed width of the cell, or %NULL
860  * @height: (allow-none): location to fill in with the fixed height of the cell, or %NULL
861  *
862  * Fills in @width and @height with the appropriate size of @cell.
863  **/
864 void
865 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
866                                   gint            *width,
867                                   gint            *height)
868 {
869   GtkCellRendererPrivate *priv;
870
871   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
872
873   priv = cell->priv;
874
875   if (width)
876     *width = priv->width;
877   if (height)
878     *height = priv->height;
879 }
880
881 /**
882  * gtk_cell_renderer_set_alignment:
883  * @cell: A #GtkCellRenderer
884  * @xalign: the x alignment of the cell renderer
885  * @yalign: the y alignment of the cell renderer
886  *
887  * Sets the renderer's alignment within its available space.
888  *
889  * Since: 2.18
890  **/
891 void
892 gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
893                                  gfloat           xalign,
894                                  gfloat           yalign)
895 {
896   GtkCellRendererPrivate *priv;
897
898   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
899   g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
900   g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
901
902   priv = cell->priv;
903
904   if ((xalign != priv->xalign) || (yalign != priv->yalign))
905     {
906       g_object_freeze_notify (G_OBJECT (cell));
907
908       if (xalign != priv->xalign)
909         {
910           priv->xalign = xalign;
911           g_object_notify (G_OBJECT (cell), "xalign");
912         }
913
914       if (yalign != priv->yalign)
915         {
916           priv->yalign = yalign;
917           g_object_notify (G_OBJECT (cell), "yalign");
918         }
919
920       g_object_thaw_notify (G_OBJECT (cell));
921     }
922 }
923
924 /**
925  * gtk_cell_renderer_get_alignment:
926  * @cell: A #GtkCellRenderer
927  * @xalign: (allow-none): location to fill in with the x alignment of the cell, or %NULL
928  * @yalign: (allow-none): location to fill in with the y alignment of the cell, or %NULL
929  *
930  * Fills in @xalign and @yalign with the appropriate values of @cell.
931  *
932  * Since: 2.18
933  **/
934 void
935 gtk_cell_renderer_get_alignment (GtkCellRenderer *cell,
936                                  gfloat          *xalign,
937                                  gfloat          *yalign)
938 {
939   GtkCellRendererPrivate *priv;
940
941   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
942
943   priv = cell->priv;
944
945   if (xalign)
946     *xalign = priv->xalign;
947   if (yalign)
948     *yalign = priv->yalign;
949 }
950
951 /**
952  * gtk_cell_renderer_set_padding:
953  * @cell: A #GtkCellRenderer
954  * @xpad: the x padding of the cell renderer
955  * @ypad: the y padding of the cell renderer
956  *
957  * Sets the renderer's padding.
958  *
959  * Since: 2.18
960  **/
961 void
962 gtk_cell_renderer_set_padding (GtkCellRenderer *cell,
963                                gint             xpad,
964                                gint             ypad)
965 {
966   GtkCellRendererPrivate *priv;
967
968   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
969   g_return_if_fail (xpad >= 0 && xpad >= 0);
970
971   priv = cell->priv;
972
973   if ((xpad != priv->xpad) || (ypad != priv->ypad))
974     {
975       g_object_freeze_notify (G_OBJECT (cell));
976
977       if (xpad != priv->xpad)
978         {
979           priv->xpad = xpad;
980           g_object_notify (G_OBJECT (cell), "xpad");
981         }
982
983       if (ypad != priv->ypad)
984         {
985           priv->ypad = ypad;
986           g_object_notify (G_OBJECT (cell), "ypad");
987         }
988
989       g_object_thaw_notify (G_OBJECT (cell));
990     }
991 }
992
993 /**
994  * gtk_cell_renderer_get_padding:
995  * @cell: A #GtkCellRenderer
996  * @xpad: (allow-none): location to fill in with the x padding of the cell, or %NULL
997  * @ypad: (allow-none): location to fill in with the y padding of the cell, or %NULL
998  *
999  * Fills in @xpad and @ypad with the appropriate values of @cell.
1000  *
1001  * Since: 2.18
1002  **/
1003 void
1004 gtk_cell_renderer_get_padding (GtkCellRenderer *cell,
1005                                gint            *xpad,
1006                                gint            *ypad)
1007 {
1008   GtkCellRendererPrivate *priv;
1009
1010   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1011
1012   priv = cell->priv;
1013
1014   if (xpad)
1015     *xpad = priv->xpad;
1016   if (ypad)
1017     *ypad = priv->ypad;
1018 }
1019
1020 /**
1021  * gtk_cell_renderer_set_visible:
1022  * @cell: A #GtkCellRenderer
1023  * @visible: the visibility of the cell
1024  *
1025  * Sets the cell renderer's visibility.
1026  *
1027  * Since: 2.18
1028  **/
1029 void
1030 gtk_cell_renderer_set_visible (GtkCellRenderer *cell,
1031                                gboolean         visible)
1032 {
1033   GtkCellRendererPrivate *priv;
1034
1035   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1036
1037   priv = cell->priv;
1038
1039   if (priv->visible != visible)
1040     {
1041       priv->visible = visible ? TRUE : FALSE;
1042       g_object_notify (G_OBJECT (cell), "visible");
1043     }
1044 }
1045
1046 /**
1047  * gtk_cell_renderer_get_visible:
1048  * @cell: A #GtkCellRenderer
1049  *
1050  * Returns the cell renderer's visibility.
1051  *
1052  * Returns: %TRUE if the cell renderer is visible
1053  *
1054  * Since: 2.18
1055  */
1056 gboolean
1057 gtk_cell_renderer_get_visible (GtkCellRenderer *cell)
1058 {
1059   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1060
1061   return cell->priv->visible;
1062 }
1063
1064 /**
1065  * gtk_cell_renderer_set_sensitive:
1066  * @cell: A #GtkCellRenderer
1067  * @sensitive: the sensitivity of the cell
1068  *
1069  * Sets the cell renderer's sensitivity.
1070  *
1071  * Since: 2.18
1072  **/
1073 void
1074 gtk_cell_renderer_set_sensitive (GtkCellRenderer *cell,
1075                                  gboolean         sensitive)
1076 {
1077   GtkCellRendererPrivate *priv;
1078
1079   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1080
1081   priv = cell->priv;
1082
1083   if (priv->sensitive != sensitive)
1084     {
1085       priv->sensitive = sensitive ? TRUE : FALSE;
1086       g_object_notify (G_OBJECT (cell), "sensitive");
1087     }
1088 }
1089
1090 /**
1091  * gtk_cell_renderer_get_sensitive:
1092  * @cell: A #GtkCellRenderer
1093  *
1094  * Returns the cell renderer's sensitivity.
1095  *
1096  * Returns: %TRUE if the cell renderer is sensitive
1097  *
1098  * Since: 2.18
1099  */
1100 gboolean
1101 gtk_cell_renderer_get_sensitive (GtkCellRenderer *cell)
1102 {
1103   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1104
1105   return cell->priv->sensitive;
1106 }
1107
1108
1109 /**
1110  * gtk_cell_renderer_is_activatable:
1111  * @cell: A #GtkCellRenderer
1112  *
1113  * Checks whether the cell renderer can do something when activated.
1114  *
1115  * Returns: %TRUE if the cell renderer can do anything when activated.
1116  *
1117  * Since: 3.0
1118  */
1119 gboolean
1120 gtk_cell_renderer_is_activatable (GtkCellRenderer *cell)
1121 {
1122   GtkCellRendererPrivate *priv;
1123
1124   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1125
1126   priv = cell->priv;
1127
1128   return (cell->priv->visible &&
1129           (cell->priv->mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1130            cell->priv->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE));
1131 }
1132
1133
1134 /**
1135  * gtk_cell_renderer_stop_editing:
1136  * @cell: A #GtkCellRenderer
1137  * @canceled: %TRUE if the editing has been canceled
1138  * 
1139  * Informs the cell renderer that the editing is stopped.
1140  * If @canceled is %TRUE, the cell renderer will emit the 
1141  * #GtkCellRenderer::editing-canceled signal. 
1142  *
1143  * This function should be called by cell renderer implementations 
1144  * in response to the #GtkCellEditable::editing-done signal of 
1145  * #GtkCellEditable.
1146  *
1147  * Since: 2.6
1148  **/
1149 void
1150 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1151                                 gboolean         canceled)
1152 {
1153   GtkCellRendererPrivate *priv;
1154
1155   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1156
1157   priv = cell->priv;
1158
1159   if (priv->editing)
1160     {
1161       priv->editing = FALSE;
1162       if (canceled)
1163         g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1164     }
1165 }
1166
1167 static void
1168 gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer   *cell,
1169                                            GtkWidget         *widget,
1170                                            GtkOrientation     orientation,
1171                                            gint              *minimum_size,
1172                                            gint              *natural_size)
1173 {
1174   GtkRequisition min_req;
1175
1176   /* Fallback on the old API to get the size. */
1177   if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size)
1178     GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL,
1179                                                   &min_req.width, &min_req.height);
1180   else
1181     {
1182       min_req.width = 0;
1183       min_req.height = 0;
1184     }
1185
1186   if (orientation == GTK_ORIENTATION_HORIZONTAL)
1187     {
1188       if (minimum_size)
1189         *minimum_size = min_req.width;
1190
1191       if (natural_size)
1192         *natural_size = min_req.width;
1193     }
1194   else
1195     {
1196       if (minimum_size)
1197         *minimum_size = min_req.height;
1198
1199       if (natural_size)
1200         *natural_size = min_req.height;
1201     }
1202 }
1203
1204 static void
1205 gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
1206                                             GtkWidget       *widget,
1207                                             gint            *minimum_size,
1208                                             gint            *natural_size)
1209 {
1210   gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL, 
1211                                              minimum_size, natural_size);
1212 }
1213
1214 static void
1215 gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
1216                                              GtkWidget       *widget,
1217                                              gint            *minimum_size,
1218                                              gint            *natural_size)
1219 {
1220   gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL, 
1221                                              minimum_size, natural_size);
1222 }
1223
1224
1225 static void
1226 gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
1227                                                        GtkWidget       *widget,
1228                                                        gint             width,
1229                                                        gint            *minimum_height,
1230                                                        gint            *natural_height)
1231 {
1232   /* Fall back on the height reported from ->get_size() */
1233   gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
1234 }
1235
1236 static void
1237 gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
1238                                                        GtkWidget       *widget,
1239                                                        gint             height,
1240                                                        gint            *minimum_width,
1241                                                        gint            *natural_width)
1242 {
1243   /* Fall back on the width reported from ->get_size() */
1244   gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
1245 }
1246
1247
1248 /* Default implementation assumes that a cell renderer will never use more
1249  * space than it's natural size (this is fine for toggles and pixbufs etc
1250  * but needs to be overridden from wrapping/ellipsizing text renderers) */
1251 static void
1252 gtk_cell_renderer_real_get_aligned_area (GtkCellRenderer         *cell,
1253                                          GtkWidget               *widget,
1254                                          GtkCellRendererState     flags,
1255                                          const GdkRectangle      *cell_area,
1256                                          GdkRectangle            *aligned_area)
1257 {
1258   gint opposite_size, x_offset, y_offset;
1259   gint natural_size;
1260
1261   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1262   g_return_if_fail (GTK_IS_WIDGET (widget));
1263   g_return_if_fail (cell_area != NULL);
1264   g_return_if_fail (aligned_area != NULL);
1265
1266   *aligned_area = *cell_area;
1267
1268   /* Trim up the aligned size */
1269   if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1270     {
1271       gtk_cell_renderer_get_preferred_width (cell, widget, 
1272                                              NULL, &natural_size);
1273
1274       aligned_area->width = MIN (aligned_area->width, natural_size);
1275
1276       gtk_cell_renderer_get_preferred_height_for_width (cell, widget, 
1277                                                         aligned_area->width, 
1278                                                         NULL, &opposite_size);
1279
1280       aligned_area->height = MIN (opposite_size, aligned_area->height);
1281     }
1282   else
1283     {
1284       gtk_cell_renderer_get_preferred_height (cell, widget, 
1285                                               NULL, &natural_size);
1286
1287       aligned_area->height = MIN (aligned_area->width, natural_size);
1288
1289       gtk_cell_renderer_get_preferred_width_for_height (cell, widget, 
1290                                                         aligned_area->height, 
1291                                                         NULL, &opposite_size);
1292
1293       aligned_area->width = MIN (opposite_size, aligned_area->width);
1294     }
1295
1296   /* offset the cell position */
1297   _gtk_cell_renderer_calc_offset (cell, cell_area, 
1298                                   gtk_widget_get_direction (widget),
1299                                   aligned_area->width, 
1300                                   aligned_area->height,
1301                                   &x_offset, &y_offset);
1302
1303   aligned_area->x += x_offset;
1304   aligned_area->y += y_offset;
1305 }
1306
1307
1308 /* An internal convenience function for some containers to peek at the
1309  * cell alignment in a target allocation (used to draw focus and align
1310  * cells in the icon view).
1311  *
1312  * Note this is only a trivial 'align * (allocation - request)' operation.
1313  */
1314 void
1315 _gtk_cell_renderer_calc_offset    (GtkCellRenderer      *cell,
1316                                    const GdkRectangle   *cell_area,
1317                                    GtkTextDirection      direction,
1318                                    gint                  width,
1319                                    gint                  height,
1320                                    gint                 *x_offset,
1321                                    gint                 *y_offset)
1322
1323   GtkCellRendererPrivate *priv;
1324
1325   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1326   g_return_if_fail (cell_area != NULL);
1327   g_return_if_fail (x_offset || y_offset);
1328
1329   priv = cell->priv;
1330
1331   if (x_offset)
1332     {
1333       *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
1334                     (1.0 - priv->xalign) : priv->xalign) * 
1335                    (cell_area->width - width));
1336       *x_offset = MAX (*x_offset, 0);
1337     }
1338   if (y_offset)
1339     {
1340       *y_offset = (priv->yalign *
1341                    (cell_area->height - height));
1342       *y_offset = MAX (*y_offset, 0);
1343     }
1344 }
1345
1346 /**
1347  * gtk_cell_renderer_get_request_mode:
1348  * @cell: a #GtkCellRenderer    instance
1349  *
1350  * Gets whether the cell renderer prefers a height-for-width layout
1351  * or a width-for-height layout.
1352  *
1353  * Returns: The #GtkSizeRequestMode preferred by this renderer.
1354  *
1355  * Since: 3.0
1356  */
1357 GtkSizeRequestMode
1358 gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
1359 {
1360   GtkCellRendererClass *klass;
1361
1362   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1363
1364   klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1365   if (klass->get_request_mode)
1366     return klass->get_request_mode (cell);
1367
1368   /* By default cell renderers are height-for-width. */
1369   return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1370 }
1371
1372 /**
1373  * gtk_cell_renderer_get_preferred_width:
1374  * @cell: a #GtkCellRenderer instance
1375  * @widget: the #GtkWidget this cell will be rendering to
1376  * @minimum_size: location to store the minimum size, or %NULL
1377  * @natural_size: location to store the natural size, or %NULL
1378  *
1379  * Retreives a renderer's natural size when rendered to @widget.
1380  *
1381  * Since: 3.0
1382  */
1383 void
1384 gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
1385                                        GtkWidget       *widget,
1386                                        gint            *minimum_size,
1387                                        gint            *natural_size)
1388 {
1389   GtkCellRendererClass *klass;
1390   gint width;
1391
1392   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1393   g_return_if_fail (GTK_IS_WIDGET (widget));
1394   g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1395
1396   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1397
1398   if (width < 0)
1399     {
1400       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1401       klass->get_preferred_width (cell, widget, minimum_size, natural_size);
1402     }
1403   else
1404     {
1405       if (minimum_size)
1406         *minimum_size = width;
1407       if (natural_size)
1408         *natural_size = width;
1409     }
1410
1411 #if DEBUG_CELL_SIZE_REQUEST
1412   g_message ("%s returning minimum width: %d and natural width: %d",
1413              G_OBJECT_TYPE_NAME (cell), 
1414              minimum_size ? *minimum_size : 20000, 
1415              natural_size ? *natural_size : 20000);
1416 #endif
1417 }
1418
1419
1420 /**
1421  * gtk_cell_renderer_get_preferred_height:
1422  * @cell: a #GtkCellRenderer instance
1423  * @widget: the #GtkWidget this cell will be rendering to
1424  * @minimum_size: location to store the minimum size, or %NULL
1425  * @natural_size: location to store the natural size, or %NULL
1426  *
1427  * Retreives a renderer's natural size when rendered to @widget.
1428  *
1429  * Since: 3.0
1430  */
1431 void
1432 gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
1433                                         GtkWidget       *widget,
1434                                         gint            *minimum_size,
1435                                         gint            *natural_size)
1436 {
1437   GtkCellRendererClass *klass;
1438   gint height;
1439
1440   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1441   g_return_if_fail (GTK_IS_WIDGET (widget));
1442   g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1443
1444   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1445
1446   if (height < 0)
1447     {
1448       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1449       klass->get_preferred_height (cell, widget, minimum_size, natural_size);
1450     }
1451   else
1452     {
1453       if (minimum_size)
1454         *minimum_size = height;
1455       if (natural_size)
1456         *natural_size = height;
1457     }
1458
1459 #if DEBUG_CELL_SIZE_REQUEST
1460   g_message ("%s returning minimum height: %d and natural height: %d",
1461              G_OBJECT_TYPE_NAME (cell), 
1462              minimum_size ? *minimum_size : 20000, 
1463              natural_size ? *natural_size : 20000);
1464 #endif
1465 }
1466
1467
1468 /**
1469  * gtk_cell_renderer_get_preferred_width_for_height:
1470  * @cell: a #GtkCellRenderer instance
1471  * @widget: the #GtkWidget this cell will be rendering to
1472  * @height: the size which is available for allocation
1473  * @minimum_width: location for storing the minimum size, or %NULL
1474  * @natural_width: location for storing the preferred size, or %NULL
1475  *
1476  * Retreives a cell renderers's minimum and natural width if it were rendered to 
1477  * @widget with the specified @height.
1478  *
1479  * Since: 3.0
1480  */
1481 void
1482 gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
1483                                                   GtkWidget       *widget,
1484                                                   gint             height,
1485                                                   gint            *minimum_width,
1486                                                   gint            *natural_width)
1487 {
1488   GtkCellRendererClass *klass;
1489   gint width;
1490
1491   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1492   g_return_if_fail (GTK_IS_WIDGET (widget));
1493   g_return_if_fail (NULL != minimum_width || NULL != natural_width);
1494
1495   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1496
1497   if (width < 0)
1498     {
1499       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1500       klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
1501     }
1502   else
1503     {
1504       if (minimum_width)
1505         *minimum_width = width;
1506       if (natural_width)
1507         *natural_width = width;
1508     }
1509
1510 #if DEBUG_CELL_SIZE_REQUEST
1511   g_message ("%s width for height: %d is minimum %d and natural: %d",
1512              G_OBJECT_TYPE_NAME (cell), height,
1513              minimum_width ? *minimum_width : 20000, 
1514              natural_width ? *natural_width : 20000);
1515 #endif
1516 }
1517
1518 /**
1519  * gtk_cell_renderer_get_preferred_height_for_width:
1520  * @cell: a #GtkCellRenderer instance
1521  * @widget: the #GtkWidget this cell will be rendering to
1522  * @width: the size which is available for allocation
1523  * @minimum_height: location for storing the minimum size, or %NULL
1524  * @natural_height: location for storing the preferred size, or %NULL
1525  *
1526  * Retreives a cell renderers's minimum and natural height if it were rendered to 
1527  * @widget with the specified @width.
1528  *
1529  * Since: 3.0
1530  */
1531 void
1532 gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
1533                                                   GtkWidget       *widget,
1534                                                   gint             width,
1535                                                   gint            *minimum_height,
1536                                                   gint            *natural_height)
1537 {
1538   GtkCellRendererClass *klass;
1539   gint height;
1540
1541   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1542   g_return_if_fail (GTK_IS_WIDGET (widget));
1543   g_return_if_fail (NULL != minimum_height || NULL != natural_height);
1544
1545   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1546
1547   if (height < 0)
1548     {
1549       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1550       klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
1551     }
1552   else
1553     {
1554       if (minimum_height)
1555         *minimum_height = height;
1556       if (natural_height)
1557         *natural_height = height;
1558     }
1559
1560 #if DEBUG_CELL_SIZE_REQUEST
1561   g_message ("%s height for width: %d is minimum %d and natural: %d",
1562              G_OBJECT_TYPE_NAME (cell), width,
1563              minimum_height ? *minimum_height : 20000, 
1564              natural_height ? *natural_height : 20000);
1565 #endif
1566 }
1567
1568 /**
1569  * gtk_cell_renderer_get_preferred_size:
1570  * @cell: a #GtkCellRenderer instance
1571  * @widget: the #GtkWidget this cell will be rendering to
1572  * @request_natural: Whether to base the contextual request off of the
1573  *     base natural or the base minimum
1574  * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
1575  * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
1576  *
1577  * Retrieves the minimum and natural size of a cell taking
1578  * into account the widget's preference for height-for-width management.
1579  *
1580  * If request_natural is specified, the non-contextual natural value will
1581  * be used to make the contextual request; otherwise the minimum will be used.
1582  *
1583  * Since: 3.0
1584  */
1585 void
1586 gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
1587                                       GtkWidget       *widget,
1588                                       GtkRequisition  *minimum_size,
1589                                       GtkRequisition  *natural_size)
1590 {
1591   gint min_width, nat_width;
1592   gint min_height, nat_height;
1593
1594   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1595
1596   if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1597     {
1598       gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
1599
1600       if (minimum_size)
1601         {
1602           minimum_size->width = min_width;
1603           gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
1604                                                             &minimum_size->height, NULL);
1605         }
1606
1607       if (natural_size)
1608         {
1609           natural_size->width = nat_width;
1610           gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
1611                                                             NULL, &natural_size->height);
1612         }
1613     }
1614   else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1615     {
1616       gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
1617
1618       if (minimum_size)
1619         {
1620           minimum_size->height = min_height;
1621           gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
1622                                                             &minimum_size->width, NULL);
1623         }
1624
1625       if (natural_size)
1626         {
1627           natural_size->height = nat_height;
1628           gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
1629                                                             NULL, &natural_size->width);
1630         }
1631     }
1632 }
1633
1634 /**
1635  * gtk_cell_renderer_get_aligned_area:
1636  * @cell: a #GtkCellRenderer instance
1637  * @widget: the #GtkWidget this cell will be rendering to
1638  * @flags: render flags
1639  * @cell_area: cell area which would be passed to gtk_cell_renderer_render()
1640  * @aligned_area: the return location for the space inside @cell_area that
1641  *                would acually be used to render.
1642  *
1643  * Gets the aligned area used by @cell inside @cell_area. Used for finding
1644  * the appropriate edit and focus rectangle.
1645  *
1646  * Since: 3.0
1647  */
1648 void
1649 gtk_cell_renderer_get_aligned_area (GtkCellRenderer      *cell,
1650                                     GtkWidget            *widget,
1651                                     GtkCellRendererState  flags,
1652                                     const GdkRectangle   *cell_area,
1653                                     GdkRectangle         *aligned_area)
1654 {
1655   GtkCellRendererClass *klass;
1656
1657   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1658   g_return_if_fail (GTK_IS_WIDGET (widget));
1659   g_return_if_fail (cell_area != NULL);
1660   g_return_if_fail (aligned_area != NULL);
1661
1662   klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1663   klass->get_aligned_area (cell, widget, flags, cell_area, aligned_area);
1664 }