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