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