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