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