]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellarea.c
Added cell focus apis to GtkCellArea.
[~andy/gtk] / gtk / gtkcellarea.c
1 /* gtkcellarea.c
2  *
3  * Copyright (C) 2010 Openismus GmbH
4  *
5  * Authors:
6  *      Tristan Van Berkom <tristanvb@openismus.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include "config.h"
25
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdlib.h>
29
30 #include "gtkintl.h"
31 #include "gtkcelllayout.h"
32 #include "gtkcellarea.h"
33 #include "gtkcellareaiter.h"
34 #include "gtkmarshalers.h"
35 #include "gtkprivate.h"
36
37 #include <gobject/gvaluecollector.h>
38
39
40 /* GObjectClass */
41 static void      gtk_cell_area_dispose                             (GObject            *object);
42 static void      gtk_cell_area_finalize                            (GObject            *object);
43 static void      gtk_cell_area_set_property                        (GObject            *object,
44                                                                     guint               prop_id,
45                                                                     const GValue       *value,
46                                                                     GParamSpec         *pspec);
47 static void      gtk_cell_area_get_property                        (GObject            *object,
48                                                                     guint               prop_id,
49                                                                     GValue             *value,
50                                                                     GParamSpec         *pspec);
51
52 /* GtkCellAreaClass */
53 static void      gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea        *area,
54                                                                     GtkCellAreaIter    *iter,
55                                                                     GtkWidget          *widget,
56                                                                     gint                width,
57                                                                     gint               *minimum_height,
58                                                                     gint               *natural_height);
59 static void      gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea        *area,
60                                                                     GtkCellAreaIter    *iter,
61                                                                     GtkWidget          *widget,
62                                                                     gint                height,
63                                                                     gint               *minimum_width,
64                                                                     gint               *natural_width);
65
66 /* GtkCellLayoutIface */
67 static void      gtk_cell_area_cell_layout_init              (GtkCellLayoutIface    *iface);
68 static void      gtk_cell_area_pack_default                  (GtkCellLayout         *cell_layout,
69                                                               GtkCellRenderer       *renderer,
70                                                               gboolean               expand);
71 static void      gtk_cell_area_clear                         (GtkCellLayout         *cell_layout);
72 static void      gtk_cell_area_add_attribute                 (GtkCellLayout         *cell_layout,
73                                                               GtkCellRenderer       *renderer,
74                                                               const gchar           *attribute,
75                                                               gint                   column);
76 static void      gtk_cell_area_set_cell_data_func            (GtkCellLayout         *cell_layout,
77                                                               GtkCellRenderer       *cell,
78                                                               GtkCellLayoutDataFunc  func,
79                                                               gpointer               func_data,
80                                                               GDestroyNotify         destroy);
81 static void      gtk_cell_area_clear_attributes              (GtkCellLayout         *cell_layout,
82                                                               GtkCellRenderer       *renderer);
83 static void      gtk_cell_area_reorder                       (GtkCellLayout         *cell_layout,
84                                                               GtkCellRenderer       *cell,
85                                                               gint                   position);
86 static GList    *gtk_cell_area_get_cells                     (GtkCellLayout         *cell_layout);
87
88 /* Attribute/Cell metadata */
89 typedef struct {
90   const gchar *attribute;
91   gint         column;
92 } CellAttribute;
93
94 typedef struct {
95   GSList                *attributes;
96
97   GtkCellLayoutDataFunc  func;
98   gpointer               data;
99   GDestroyNotify         destroy;
100 } CellInfo;
101
102 static CellInfo       *cell_info_new       (GtkCellLayoutDataFunc  func,
103                                             gpointer               data,
104                                             GDestroyNotify         destroy);
105 static void            cell_info_free      (CellInfo              *info);
106 static CellAttribute  *cell_attribute_new  (GtkCellRenderer       *renderer,
107                                             const gchar           *attribute,
108                                             gint                   column);
109 static void            cell_attribute_free (CellAttribute         *attribute);
110 static gint            cell_attribute_find (CellAttribute         *cell_attribute,
111                                             const gchar           *attribute);
112
113 /* Struct to pass data along while looping over 
114  * cell renderers to apply attributes
115  */
116 typedef struct {
117   GtkCellArea  *area;
118   GtkTreeModel *model;
119   GtkTreeIter  *iter;
120 } AttributeData;
121
122 struct _GtkCellAreaPrivate
123 {
124   GHashTable      *cell_info;
125
126   GtkBorder        cell_border;
127
128   GtkCellRenderer *focus_cell;
129   guint            can_focus : 1;
130
131 };
132
133 enum {
134   PROP_0,
135   PROP_CELL_MARGIN_LEFT,
136   PROP_CELL_MARGIN_RIGHT,
137   PROP_CELL_MARGIN_TOP,
138   PROP_CELL_MARGIN_BOTTOM
139 };
140
141 enum {
142   SIGNAL_FOCUS_LEAVE,
143   LAST_SIGNAL
144 };
145
146 /* Keep the paramspec pool internal, no need to deliver notifications
147  * on cells. at least no percieved need for now */
148 static GParamSpecPool *cell_property_pool = NULL;
149 static guint           cell_area_signals[LAST_SIGNAL] = { 0 };
150
151 #define PARAM_SPEC_PARAM_ID(pspec)              ((pspec)->param_id)
152 #define PARAM_SPEC_SET_PARAM_ID(pspec, id)      ((pspec)->param_id = (id))
153
154
155 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkCellArea, gtk_cell_area, G_TYPE_INITIALLY_UNOWNED,
156                                   G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
157                                                          gtk_cell_area_cell_layout_init));
158
159 static void
160 gtk_cell_area_init (GtkCellArea *area)
161 {
162   GtkCellAreaPrivate *priv;
163
164   area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area,
165                                             GTK_TYPE_CELL_AREA,
166                                             GtkCellAreaPrivate);
167   priv = area->priv;
168
169   priv->cell_info = g_hash_table_new_full (g_direct_hash, 
170                                            g_direct_equal,
171                                            NULL, 
172                                            (GDestroyNotify)cell_info_free);
173
174   priv->cell_border.left   = 0;
175   priv->cell_border.right  = 0;
176   priv->cell_border.top    = 0;
177   priv->cell_border.bottom = 0;
178
179   priv->focus_cell         = NULL;
180 }
181
182 static void 
183 gtk_cell_area_class_init (GtkCellAreaClass *class)
184 {
185   GObjectClass *object_class = G_OBJECT_CLASS (class);
186   
187   /* GObjectClass */
188   object_class->dispose      = gtk_cell_area_dispose;
189   object_class->finalize     = gtk_cell_area_finalize;
190   object_class->get_property = gtk_cell_area_get_property;
191   object_class->set_property = gtk_cell_area_set_property;
192
193   /* general */
194   class->add     = NULL;
195   class->remove  = NULL;
196   class->forall  = NULL;
197   class->event   = NULL;
198   class->render  = NULL;
199
200   /* geometry */
201   class->create_iter                    = NULL;
202   class->get_request_mode               = NULL;
203   class->get_preferred_width            = NULL;
204   class->get_preferred_height           = NULL;
205   class->get_preferred_height_for_width = gtk_cell_area_real_get_preferred_height_for_width;
206   class->get_preferred_width_for_height = gtk_cell_area_real_get_preferred_width_for_height;
207
208   /* focus */
209   class->grab_focus = NULL;
210
211   /* Signals */
212   cell_area_signals[SIGNAL_FOCUS_LEAVE] =
213     g_signal_new (I_("focus-leave"),
214                   G_TYPE_FROM_CLASS (object_class),
215                   G_SIGNAL_RUN_LAST,
216                   0, /* Class offset (just a notification, no class handler) */
217                   NULL, NULL,
218                   _gtk_marshal_VOID__ENUM_STRING,
219                   G_TYPE_NONE, 2,
220                   GTK_TYPE_DIRECTION_TYPE, G_TYPE_STRING);
221
222
223   /* Properties */
224   g_object_class_install_property (object_class,
225                                    PROP_CELL_MARGIN_LEFT,
226                                    g_param_spec_int
227                                    ("cell-margin-left",
228                                     P_("Margin on Left"),
229                                     P_("Pixels of extra space on the left side of each cell"),
230                                     0,
231                                     G_MAXINT16,
232                                     0,
233                                     GTK_PARAM_READWRITE));
234
235   g_object_class_install_property (object_class,
236                                    PROP_CELL_MARGIN_RIGHT,
237                                    g_param_spec_int
238                                    ("cell-margin-right",
239                                     P_("Margin on Right"),
240                                     P_("Pixels of extra space on the right side of each cell"),
241                                     0,
242                                     G_MAXINT16,
243                                     0,
244                                     GTK_PARAM_READWRITE));
245   
246   g_object_class_install_property (object_class,
247                                    PROP_CELL_MARGIN_TOP,
248                                    g_param_spec_int 
249                                    ("cell-margin-top",
250                                     P_("Margin on Top"),
251                                     P_("Pixels of extra space on the top side of each cell"),
252                                     0,
253                                     G_MAXINT16,
254                                     0,
255                                     GTK_PARAM_READWRITE));
256
257   g_object_class_install_property (object_class,
258                                    PROP_CELL_MARGIN_BOTTOM,
259                                    g_param_spec_int
260                                    ("cell-margin-bottom",
261                                     P_("Margin on Bottom"),
262                                     P_("Pixels of extra space on the bottom side of each cell"),
263                                     0,
264                                     G_MAXINT16,
265                                     0,
266                                     GTK_PARAM_READWRITE));
267
268   /* Pool for Cell Properties */
269   if (!cell_property_pool)
270     cell_property_pool = g_param_spec_pool_new (FALSE);
271
272   g_type_class_add_private (object_class, sizeof (GtkCellAreaPrivate));
273 }
274
275 /*************************************************************
276  *                    CellInfo Basics                        *
277  *************************************************************/
278 static CellInfo *
279 cell_info_new (GtkCellLayoutDataFunc  func,
280                gpointer               data,
281                GDestroyNotify         destroy)
282 {
283   CellInfo *info = g_slice_new (CellInfo);
284   
285   info->attributes = NULL;
286   info->func       = func;
287   info->data       = data;
288   info->destroy    = destroy;
289
290   return info;
291 }
292
293 static void
294 cell_info_free (CellInfo *info)
295 {
296   if (info->destroy)
297     info->destroy (info->data);
298
299   g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
300   g_slist_free (info->attributes);
301
302   g_slice_free (CellInfo, info);
303 }
304
305 static CellAttribute  *
306 cell_attribute_new  (GtkCellRenderer       *renderer,
307                      const gchar           *attribute,
308                      gint                   column)
309 {
310   GParamSpec *pspec;
311
312   /* Check if the attribute really exists and point to
313    * the property string installed on the cell renderer
314    * class (dont dup the string) 
315    */
316   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (renderer), attribute);
317
318   if (pspec)
319     {
320       CellAttribute *cell_attribute = g_slice_new (CellAttribute);
321
322       cell_attribute->attribute = pspec->name;
323       cell_attribute->column    = column;
324
325       return cell_attribute;
326     }
327
328   return NULL;
329 }
330
331 static void
332 cell_attribute_free (CellAttribute *attribute)
333 {
334   g_slice_free (CellAttribute, attribute);
335 }
336
337 /* GCompareFunc for g_slist_find_custom() */
338 static gint
339 cell_attribute_find (CellAttribute *cell_attribute,
340                      const gchar   *attribute)
341 {
342   return g_strcmp0 (cell_attribute->attribute, attribute);
343 }
344
345 /*************************************************************
346  *                      GObjectClass                         *
347  *************************************************************/
348 static void
349 gtk_cell_area_finalize (GObject *object)
350 {
351   GtkCellArea        *area   = GTK_CELL_AREA (object);
352   GtkCellAreaPrivate *priv   = area->priv;
353
354   /* All cell renderers should already be removed at this point,
355    * just kill our hash table here. 
356    */
357   g_hash_table_destroy (priv->cell_info);
358
359   G_OBJECT_CLASS (gtk_cell_area_parent_class)->finalize (object);
360 }
361
362
363 static void
364 gtk_cell_area_dispose (GObject *object)
365 {
366   /* This removes every cell renderer that may be added to the GtkCellArea,
367    * subclasses should be breaking references to the GtkCellRenderers 
368    * at this point.
369    */
370   gtk_cell_layout_clear (GTK_CELL_LAYOUT (object));
371
372   /* Remove any ref to a focused cell */
373   gtk_cell_area_set_focus_cell (GTK_CELL_AREA (object), NULL);
374
375   G_OBJECT_CLASS (gtk_cell_area_parent_class)->dispose (object);
376 }
377
378 static void
379 gtk_cell_area_set_property (GObject       *object,
380                             guint          prop_id,
381                             const GValue  *value,
382                             GParamSpec    *pspec)
383 {
384   GtkCellArea *area = GTK_CELL_AREA (object);
385
386   switch (prop_id)
387     {
388     case PROP_CELL_MARGIN_LEFT:
389       gtk_cell_area_set_cell_margin_left (area, g_value_get_int (value));
390       break;
391     case PROP_CELL_MARGIN_RIGHT:
392       gtk_cell_area_set_cell_margin_right (area, g_value_get_int (value));
393       break;
394     case PROP_CELL_MARGIN_TOP:
395       gtk_cell_area_set_cell_margin_top (area, g_value_get_int (value));
396       break;
397     case PROP_CELL_MARGIN_BOTTOM:
398       gtk_cell_area_set_cell_margin_bottom (area, g_value_get_int (value));
399       break;
400     default:
401       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
402       break;
403     }
404 }
405
406 static void
407 gtk_cell_area_get_property (GObject     *object,
408                             guint        prop_id,
409                             GValue      *value,
410                             GParamSpec  *pspec)
411 {
412   GtkCellArea        *area = GTK_CELL_AREA (object);
413   GtkCellAreaPrivate *priv = area->priv;
414
415   switch (prop_id)
416     {
417     case PROP_CELL_MARGIN_LEFT:
418       g_value_set_int (value, priv->cell_border.left);
419       break;
420     case PROP_CELL_MARGIN_RIGHT:
421       g_value_set_int (value, priv->cell_border.right);
422       break;
423     case PROP_CELL_MARGIN_TOP:
424       g_value_set_int (value, priv->cell_border.top);
425       break;
426     case PROP_CELL_MARGIN_BOTTOM:
427       g_value_set_int (value, priv->cell_border.bottom);
428       break;
429     default:
430       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
431       break;
432     }
433 }
434
435 /*************************************************************
436  *                    GtkCellAreaClass                       *
437  *************************************************************/
438 static void
439 gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea        *area,
440                                                    GtkCellAreaIter    *iter,
441                                                    GtkWidget          *widget,
442                                                    gint                width,
443                                                    gint               *minimum_height,
444                                                    gint               *natural_height)
445 {
446   /* If the area doesnt do height-for-width, fallback on base preferred height */
447   GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, iter, widget, minimum_height, natural_height);
448 }
449
450 static void
451 gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea        *area,
452                                                    GtkCellAreaIter    *iter,
453                                                    GtkWidget          *widget,
454                                                    gint                height,
455                                                    gint               *minimum_width,
456                                                    gint               *natural_width)
457 {
458   /* If the area doesnt do width-for-height, fallback on base preferred width */
459   GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, iter, widget, minimum_width, natural_width);
460 }
461
462 /*************************************************************
463  *                   GtkCellLayoutIface                      *
464  *************************************************************/
465 static void
466 gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface)
467 {
468   iface->pack_start         = gtk_cell_area_pack_default;
469   iface->pack_end           = gtk_cell_area_pack_default;
470   iface->clear              = gtk_cell_area_clear;
471   iface->add_attribute      = gtk_cell_area_add_attribute;
472   iface->set_cell_data_func = gtk_cell_area_set_cell_data_func;
473   iface->clear_attributes   = gtk_cell_area_clear_attributes;
474   iface->reorder            = gtk_cell_area_reorder;
475   iface->get_cells          = gtk_cell_area_get_cells;
476 }
477
478 static void
479 gtk_cell_area_pack_default (GtkCellLayout         *cell_layout,
480                             GtkCellRenderer       *renderer,
481                             gboolean               expand)
482 {
483   gtk_cell_area_add (GTK_CELL_AREA (cell_layout), renderer);
484 }
485
486 static void
487 gtk_cell_area_clear (GtkCellLayout *cell_layout)
488 {
489   GtkCellArea *area = GTK_CELL_AREA (cell_layout);
490   GList *l, *cells  =
491     gtk_cell_layout_get_cells (cell_layout);
492
493   for (l = cells; l; l = l->next)
494     {
495       GtkCellRenderer *renderer = l->data;
496       gtk_cell_area_remove (area, renderer);
497     }
498
499   g_list_free (cells);
500 }
501
502 static void
503 gtk_cell_area_add_attribute (GtkCellLayout         *cell_layout,
504                              GtkCellRenderer       *renderer,
505                              const gchar           *attribute,
506                              gint                   column)
507 {
508   gtk_cell_area_attribute_connect (GTK_CELL_AREA (cell_layout),
509                                    renderer, attribute, column);
510 }
511
512 static void
513 gtk_cell_area_set_cell_data_func (GtkCellLayout         *cell_layout,
514                                   GtkCellRenderer       *renderer,
515                                   GtkCellLayoutDataFunc  func,
516                                   gpointer               func_data,
517                                   GDestroyNotify         destroy)
518 {
519   GtkCellArea        *area   = GTK_CELL_AREA (cell_layout);
520   GtkCellAreaPrivate *priv   = area->priv;
521   CellInfo           *info;
522
523   info = g_hash_table_lookup (priv->cell_info, renderer);
524
525   if (info)
526     {
527       if (info->destroy && info->data)
528         info->destroy (info->data);
529
530       if (func)
531         {
532           info->func    = func;
533           info->data    = func_data;
534           info->destroy = destroy;
535         }
536       else
537         {
538           info->func    = NULL;
539           info->data    = NULL;
540           info->destroy = NULL;
541         }
542     }
543   else
544     {
545       info = cell_info_new (func, func_data, destroy);
546
547       g_hash_table_insert (priv->cell_info, renderer, info);
548     }
549 }
550
551 static void
552 gtk_cell_area_clear_attributes (GtkCellLayout         *cell_layout,
553                                 GtkCellRenderer       *renderer)
554 {
555   GtkCellArea        *area = GTK_CELL_AREA (cell_layout);
556   GtkCellAreaPrivate *priv = area->priv;
557   CellInfo           *info;
558
559   info = g_hash_table_lookup (priv->cell_info, renderer);
560
561   if (info)
562     {
563       g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
564       g_slist_free (info->attributes);
565
566       info->attributes = NULL;
567     }
568 }
569
570 static void 
571 gtk_cell_area_reorder (GtkCellLayout   *cell_layout,
572                        GtkCellRenderer *cell,
573                        gint             position)
574 {
575   g_warning ("GtkCellLayout::reorder not implemented for `%s'", 
576              g_type_name (G_TYPE_FROM_INSTANCE (cell_layout)));
577 }
578
579 static void
580 accum_cells (GtkCellRenderer *renderer,
581              GList          **accum)
582 {
583   *accum = g_list_prepend (*accum, renderer);
584 }
585
586 static GList *
587 gtk_cell_area_get_cells (GtkCellLayout *cell_layout)
588 {
589   GList *cells = NULL;
590
591   gtk_cell_area_forall (GTK_CELL_AREA (cell_layout), 
592                         (GtkCellCallback)accum_cells,
593                         &cells);
594
595   return g_list_reverse (cells);
596 }
597
598
599 /*************************************************************
600  *                            API                            *
601  *************************************************************/
602 void
603 gtk_cell_area_add (GtkCellArea        *area,
604                    GtkCellRenderer    *renderer)
605 {
606   GtkCellAreaClass *class;
607
608   g_return_if_fail (GTK_IS_CELL_AREA (area));
609   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
610
611   class = GTK_CELL_AREA_GET_CLASS (area);
612
613   if (class->add)
614     class->add (area, renderer);
615   else
616     g_warning ("GtkCellAreaClass::add not implemented for `%s'", 
617                g_type_name (G_TYPE_FROM_INSTANCE (area)));
618 }
619
620 void
621 gtk_cell_area_remove (GtkCellArea        *area,
622                       GtkCellRenderer    *renderer)
623 {
624   GtkCellAreaClass   *class;
625   GtkCellAreaPrivate *priv;
626
627   g_return_if_fail (GTK_IS_CELL_AREA (area));
628   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
629
630   class = GTK_CELL_AREA_GET_CLASS (area);
631   priv  = area->priv;
632
633   /* Remove any custom attributes and custom cell data func here first */
634   g_hash_table_remove (priv->cell_info, renderer);
635
636   if (class->remove)
637     class->remove (area, renderer);
638   else
639     g_warning ("GtkCellAreaClass::remove not implemented for `%s'", 
640                g_type_name (G_TYPE_FROM_INSTANCE (area)));
641 }
642
643 void
644 gtk_cell_area_forall (GtkCellArea        *area,
645                       GtkCellCallback     callback,
646                       gpointer            callback_data)
647 {
648   GtkCellAreaClass *class;
649
650   g_return_if_fail (GTK_IS_CELL_AREA (area));
651   g_return_if_fail (callback != NULL);
652
653   class = GTK_CELL_AREA_GET_CLASS (area);
654
655   if (class->forall)
656     class->forall (area, callback, callback_data);
657   else
658     g_warning ("GtkCellAreaClass::forall not implemented for `%s'", 
659                g_type_name (G_TYPE_FROM_INSTANCE (area)));
660 }
661
662 gint
663 gtk_cell_area_event (GtkCellArea          *area,
664                      GtkCellAreaIter      *iter,
665                      GtkWidget            *widget,
666                      GdkEvent             *event,
667                      const GdkRectangle   *cell_area,
668                      GtkCellRendererState  flags)
669 {
670   GtkCellAreaClass *class;
671
672   g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
673   g_return_val_if_fail (GTK_IS_CELL_AREA_ITER (iter), 0);
674   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
675   g_return_val_if_fail (event != NULL, 0);
676   g_return_val_if_fail (cell_area != NULL, 0);
677
678   class = GTK_CELL_AREA_GET_CLASS (area);
679
680   if (class->event)
681     return class->event (area, iter, widget, event, cell_area, flags);
682
683   g_warning ("GtkCellAreaClass::event not implemented for `%s'", 
684              g_type_name (G_TYPE_FROM_INSTANCE (area)));
685   return 0;
686 }
687
688 void
689 gtk_cell_area_render (GtkCellArea          *area,
690                       GtkCellAreaIter      *iter,
691                       GtkWidget            *widget,
692                       cairo_t              *cr,
693                       const GdkRectangle   *cell_area,
694                       GtkCellRendererState  flags)
695 {
696   GtkCellAreaClass *class;
697
698   g_return_if_fail (GTK_IS_CELL_AREA (area));
699   g_return_if_fail (GTK_IS_CELL_AREA_ITER (iter));
700   g_return_if_fail (GTK_IS_WIDGET (widget));
701   g_return_if_fail (cr != NULL);
702   g_return_if_fail (cell_area != NULL);
703
704   class = GTK_CELL_AREA_GET_CLASS (area);
705
706   if (class->render)
707     class->render (area, iter, widget, cr, cell_area, flags);
708   else
709     g_warning ("GtkCellAreaClass::render not implemented for `%s'", 
710                g_type_name (G_TYPE_FROM_INSTANCE (area)));
711 }
712
713 /*************************************************************
714  *                      API: Geometry                        *
715  *************************************************************/
716 GtkCellAreaIter   *
717 gtk_cell_area_create_iter (GtkCellArea *area)
718 {
719   GtkCellAreaClass *class;
720
721   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
722
723   class = GTK_CELL_AREA_GET_CLASS (area);
724
725   if (class->create_iter)
726     return class->create_iter (area);
727
728   g_warning ("GtkCellAreaClass::create_iter not implemented for `%s'", 
729              g_type_name (G_TYPE_FROM_INSTANCE (area)));
730   
731   return NULL;
732 }
733
734
735 GtkSizeRequestMode 
736 gtk_cell_area_get_request_mode (GtkCellArea *area)
737 {
738   GtkCellAreaClass *class;
739
740   g_return_val_if_fail (GTK_IS_CELL_AREA (area), 
741                         GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
742
743   class = GTK_CELL_AREA_GET_CLASS (area);
744
745   if (class->get_request_mode)
746     return class->get_request_mode (area);
747
748   g_warning ("GtkCellAreaClass::get_request_mode not implemented for `%s'", 
749              g_type_name (G_TYPE_FROM_INSTANCE (area)));
750   
751   return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
752 }
753
754 void
755 gtk_cell_area_get_preferred_width (GtkCellArea        *area,
756                                    GtkCellAreaIter    *iter,
757                                    GtkWidget          *widget,
758                                    gint               *minimum_size,
759                                    gint               *natural_size)
760 {
761   GtkCellAreaClass *class;
762
763   g_return_if_fail (GTK_IS_CELL_AREA (area));
764   g_return_if_fail (GTK_IS_WIDGET (widget));
765
766   class = GTK_CELL_AREA_GET_CLASS (area);
767
768   if (class->get_preferred_width)
769     class->get_preferred_width (area, iter, widget, minimum_size, natural_size);
770   else
771     g_warning ("GtkCellAreaClass::get_preferred_width not implemented for `%s'", 
772                g_type_name (G_TYPE_FROM_INSTANCE (area)));
773 }
774
775 void
776 gtk_cell_area_get_preferred_height_for_width (GtkCellArea        *area,
777                                               GtkCellAreaIter    *iter,
778                                               GtkWidget          *widget,
779                                               gint                width,
780                                               gint               *minimum_height,
781                                               gint               *natural_height)
782 {
783   GtkCellAreaClass *class;
784
785   g_return_if_fail (GTK_IS_CELL_AREA (area));
786   g_return_if_fail (GTK_IS_WIDGET (widget));
787
788   class = GTK_CELL_AREA_GET_CLASS (area);
789   class->get_preferred_height_for_width (area, iter, widget, width, minimum_height, natural_height);
790 }
791
792 void
793 gtk_cell_area_get_preferred_height (GtkCellArea        *area,
794                                     GtkCellAreaIter    *iter,
795                                     GtkWidget          *widget,
796                                     gint               *minimum_size,
797                                     gint               *natural_size)
798 {
799   GtkCellAreaClass *class;
800
801   g_return_if_fail (GTK_IS_CELL_AREA (area));
802   g_return_if_fail (GTK_IS_WIDGET (widget));
803
804   class = GTK_CELL_AREA_GET_CLASS (area);
805
806   if (class->get_preferred_height)
807     class->get_preferred_height (area, iter, widget, minimum_size, natural_size);
808   else
809     g_warning ("GtkCellAreaClass::get_preferred_height not implemented for `%s'", 
810                g_type_name (G_TYPE_FROM_INSTANCE (area)));
811 }
812
813 void
814 gtk_cell_area_get_preferred_width_for_height (GtkCellArea        *area,
815                                               GtkCellAreaIter    *iter,
816                                               GtkWidget          *widget,
817                                               gint                height,
818                                               gint               *minimum_width,
819                                               gint               *natural_width)
820 {
821   GtkCellAreaClass *class;
822
823   g_return_if_fail (GTK_IS_CELL_AREA (area));
824   g_return_if_fail (GTK_IS_WIDGET (widget));
825
826   class = GTK_CELL_AREA_GET_CLASS (area);
827   class->get_preferred_width_for_height (area, iter, widget, height, minimum_width, natural_width);
828 }
829
830 /*************************************************************
831  *                      API: Attributes                      *
832  *************************************************************/
833 void
834 gtk_cell_area_attribute_connect (GtkCellArea        *area,
835                                  GtkCellRenderer    *renderer,
836                                  const gchar        *attribute,
837                                  gint                column)
838
839   GtkCellAreaPrivate *priv;
840   CellInfo           *info;
841   CellAttribute      *cell_attribute;
842
843   g_return_if_fail (GTK_IS_CELL_AREA (area));
844   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
845   g_return_if_fail (attribute != NULL);
846
847   priv = area->priv;
848   info = g_hash_table_lookup (priv->cell_info, renderer);
849
850   if (!info)
851     {
852       info = cell_info_new (NULL, NULL, NULL);
853
854       g_hash_table_insert (priv->cell_info, renderer, info);
855     }
856   else
857     {
858       GSList *node;
859
860       /* Check we are not adding the same attribute twice */
861       if ((node = g_slist_find_custom (info->attributes, attribute,
862                                        (GCompareFunc)cell_attribute_find)) != NULL)
863         {
864           cell_attribute = node->data;
865
866           g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
867                      "since `%s' is already attributed to column %d", 
868                      attribute,
869                      g_type_name (G_TYPE_FROM_INSTANCE (area)),
870                      attribute, cell_attribute->column);
871           return;
872         }
873     }
874
875   cell_attribute = cell_attribute_new (renderer, attribute, column);
876
877   if (!cell_attribute)
878     {
879       g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
880                  "since attribute does not exist", 
881                  attribute,
882                  g_type_name (G_TYPE_FROM_INSTANCE (area)));
883       return;
884     }
885
886   info->attributes = g_slist_prepend (info->attributes, cell_attribute);
887 }
888
889 void 
890 gtk_cell_area_attribute_disconnect (GtkCellArea        *area,
891                                     GtkCellRenderer    *renderer,
892                                     const gchar        *attribute)
893 {
894   GtkCellAreaPrivate *priv;
895   CellInfo           *info;
896   CellAttribute      *cell_attribute;
897   GSList             *node;
898
899   g_return_if_fail (GTK_IS_CELL_AREA (area));
900   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
901   g_return_if_fail (attribute != NULL);
902
903   priv = area->priv;
904   info = g_hash_table_lookup (priv->cell_info, renderer);
905
906   if (info)
907     {
908       node = g_slist_find_custom (info->attributes, attribute,
909                                   (GCompareFunc)cell_attribute_find);
910       if (node)
911         {
912           cell_attribute = node->data;
913
914           cell_attribute_free (cell_attribute);
915
916           info->attributes = g_slist_delete_link (info->attributes, node);
917         }
918     }
919 }
920
921 static void
922 apply_cell_attributes (GtkCellRenderer *renderer,
923                        CellInfo        *info,
924                        AttributeData   *data)
925 {
926   CellAttribute *attribute;
927   GSList        *list;
928   GValue         value = { 0, };
929
930   /* Apply the attributes directly to the renderer */
931   for (list = info->attributes; list; list = list->next)
932     {
933       attribute = list->data;
934
935       gtk_tree_model_get_value (data->model, data->iter, attribute->column, &value);
936       g_object_set_property (G_OBJECT (renderer), attribute->attribute, &value);
937       g_value_unset (&value);
938     }
939
940   /* Call any GtkCellLayoutDataFunc that may have been set by the user
941    */
942   if (info->func)
943     info->func (GTK_CELL_LAYOUT (data->area), renderer,
944                 data->model, data->iter, info->data);
945 }
946
947 void
948 gtk_cell_area_apply_attributes (GtkCellArea  *area,
949                                 GtkTreeModel *tree_model,
950                                 GtkTreeIter  *iter)
951 {
952   GtkCellAreaPrivate *priv;
953   AttributeData       data;
954
955   g_return_if_fail (GTK_IS_CELL_AREA (area));
956   g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
957   g_return_if_fail (iter != NULL);
958
959   priv = area->priv;
960
961   /* Go over any cells that have attributes or custom GtkCellLayoutDataFuncs and
962    * apply the data from the treemodel */
963   g_hash_table_foreach (priv->cell_info, (GHFunc)apply_cell_attributes, &data);
964 }
965
966 /*************************************************************
967  *                    API: Cell Properties                   *
968  *************************************************************/
969 void
970 gtk_cell_area_class_install_cell_property (GtkCellAreaClass   *aclass,
971                                            guint               property_id,
972                                            GParamSpec         *pspec)
973 {
974   g_return_if_fail (GTK_IS_CELL_AREA_CLASS (aclass));
975   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
976   if (pspec->flags & G_PARAM_WRITABLE)
977     g_return_if_fail (aclass->set_cell_property != NULL);
978   if (pspec->flags & G_PARAM_READABLE)
979     g_return_if_fail (aclass->get_cell_property != NULL);
980   g_return_if_fail (property_id > 0);
981   g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0);  /* paranoid */
982   g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
983
984   if (g_param_spec_pool_lookup (cell_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (aclass), TRUE))
985     {
986       g_warning (G_STRLOC ": class `%s' already contains a cell property named `%s'",
987                  G_OBJECT_CLASS_NAME (aclass), pspec->name);
988       return;
989     }
990   g_param_spec_ref (pspec);
991   g_param_spec_sink (pspec);
992   PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
993   g_param_spec_pool_insert (cell_property_pool, pspec, G_OBJECT_CLASS_TYPE (aclass));
994 }
995
996 GParamSpec*
997 gtk_cell_area_class_find_cell_property (GtkCellAreaClass   *aclass,
998                                         const gchar        *property_name)
999 {
1000   g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
1001   g_return_val_if_fail (property_name != NULL, NULL);
1002
1003   return g_param_spec_pool_lookup (cell_property_pool,
1004                                    property_name,
1005                                    G_OBJECT_CLASS_TYPE (aclass),
1006                                    TRUE);
1007 }
1008
1009 GParamSpec**
1010 gtk_cell_area_class_list_cell_properties (GtkCellAreaClass   *aclass,
1011                                           guint             *n_properties)
1012 {
1013   GParamSpec **pspecs;
1014   guint n;
1015
1016   g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
1017
1018   pspecs = g_param_spec_pool_list (cell_property_pool,
1019                                    G_OBJECT_CLASS_TYPE (aclass),
1020                                    &n);
1021   if (n_properties)
1022     *n_properties = n;
1023
1024   return pspecs;
1025 }
1026
1027 void
1028 gtk_cell_area_add_with_properties (GtkCellArea        *area,
1029                                    GtkCellRenderer    *renderer,
1030                                    const gchar        *first_prop_name,
1031                                    ...)
1032 {
1033   GtkCellAreaClass *class;
1034
1035   g_return_if_fail (GTK_IS_CELL_AREA (area));
1036   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1037
1038   class = GTK_CELL_AREA_GET_CLASS (area);
1039
1040   if (class->add)
1041     {
1042       va_list var_args;
1043
1044       class->add (area, renderer);
1045
1046       va_start (var_args, first_prop_name);
1047       gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
1048       va_end (var_args);
1049     }
1050   else
1051     g_warning ("GtkCellAreaClass::add not implemented for `%s'", 
1052                g_type_name (G_TYPE_FROM_INSTANCE (area)));
1053 }
1054
1055 void
1056 gtk_cell_area_cell_set (GtkCellArea        *area,
1057                         GtkCellRenderer    *renderer,
1058                         const gchar        *first_prop_name,
1059                         ...)
1060 {
1061   va_list var_args;
1062
1063   g_return_if_fail (GTK_IS_CELL_AREA (area));
1064   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1065
1066   va_start (var_args, first_prop_name);
1067   gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
1068   va_end (var_args);
1069 }
1070
1071 void
1072 gtk_cell_area_cell_get (GtkCellArea        *area,
1073                         GtkCellRenderer    *renderer,
1074                         const gchar        *first_prop_name,
1075                         ...)
1076 {
1077   va_list var_args;
1078
1079   g_return_if_fail (GTK_IS_CELL_AREA (area));
1080   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1081
1082   va_start (var_args, first_prop_name);
1083   gtk_cell_area_cell_get_valist (area, renderer, first_prop_name, var_args);
1084   va_end (var_args);
1085 }
1086
1087 static inline void
1088 area_get_cell_property (GtkCellArea     *area,
1089                         GtkCellRenderer *renderer,
1090                         GParamSpec      *pspec,
1091                         GValue          *value)
1092 {
1093   GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
1094   
1095   class->get_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
1096 }
1097
1098 static inline void
1099 area_set_cell_property (GtkCellArea     *area,
1100                         GtkCellRenderer *renderer,
1101                         GParamSpec      *pspec,
1102                         const GValue    *value)
1103 {
1104   GValue tmp_value = { 0, };
1105   GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
1106
1107   /* provide a copy to work from, convert (if necessary) and validate */
1108   g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1109   if (!g_value_transform (value, &tmp_value))
1110     g_warning ("unable to set cell property `%s' of type `%s' from value of type `%s'",
1111                pspec->name,
1112                g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1113                G_VALUE_TYPE_NAME (value));
1114   else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
1115     {
1116       gchar *contents = g_strdup_value_contents (value);
1117
1118       g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
1119                  contents,
1120                  G_VALUE_TYPE_NAME (value),
1121                  pspec->name,
1122                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1123       g_free (contents);
1124     }
1125   else
1126     {
1127       class->set_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
1128     }
1129   g_value_unset (&tmp_value);
1130 }
1131
1132 void
1133 gtk_cell_area_cell_set_valist (GtkCellArea        *area,
1134                                GtkCellRenderer    *renderer,
1135                                const gchar        *first_property_name,
1136                                va_list             var_args)
1137 {
1138   const gchar *name;
1139
1140   g_return_if_fail (GTK_IS_CELL_AREA (area));
1141   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1142
1143   name = first_property_name;
1144   while (name)
1145     {
1146       GValue value = { 0, };
1147       gchar *error = NULL;
1148       GParamSpec *pspec = 
1149         g_param_spec_pool_lookup (cell_property_pool, name,
1150                                   G_OBJECT_TYPE (area), TRUE);
1151       if (!pspec)
1152         {
1153           g_warning ("%s: cell area class `%s' has no cell property named `%s'",
1154                      G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
1155           break;
1156         }
1157       if (!(pspec->flags & G_PARAM_WRITABLE))
1158         {
1159           g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
1160                      G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
1161           break;
1162         }
1163
1164       g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1165       G_VALUE_COLLECT (&value, var_args, 0, &error);
1166       if (error)
1167         {
1168           g_warning ("%s: %s", G_STRLOC, error);
1169           g_free (error);
1170
1171           /* we purposely leak the value here, it might not be
1172            * in a sane state if an error condition occoured
1173            */
1174           break;
1175         }
1176       area_set_cell_property (area, renderer, pspec, &value);
1177       g_value_unset (&value);
1178       name = va_arg (var_args, gchar*);
1179     }
1180 }
1181
1182 void
1183 gtk_cell_area_cell_get_valist (GtkCellArea        *area,
1184                                GtkCellRenderer    *renderer,
1185                                const gchar        *first_property_name,
1186                                va_list             var_args)
1187 {
1188   const gchar *name;
1189
1190   g_return_if_fail (GTK_IS_CELL_AREA (area));
1191   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1192
1193   name = first_property_name;
1194   while (name)
1195     {
1196       GValue value = { 0, };
1197       GParamSpec *pspec;
1198       gchar *error;
1199
1200       pspec = g_param_spec_pool_lookup (cell_property_pool, name,
1201                                         G_OBJECT_TYPE (area), TRUE);
1202       if (!pspec)
1203         {
1204           g_warning ("%s: cell area class `%s' has no cell property named `%s'",
1205                      G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
1206           break;
1207         }
1208       if (!(pspec->flags & G_PARAM_READABLE))
1209         {
1210           g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
1211                      G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
1212           break;
1213         }
1214
1215       g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1216       area_get_cell_property (area, renderer, pspec, &value);
1217       G_VALUE_LCOPY (&value, var_args, 0, &error);
1218       if (error)
1219         {
1220           g_warning ("%s: %s", G_STRLOC, error);
1221           g_free (error);
1222           g_value_unset (&value);
1223           break;
1224         }
1225       g_value_unset (&value);
1226       name = va_arg (var_args, gchar*);
1227     }
1228 }
1229
1230 void
1231 gtk_cell_area_cell_set_property (GtkCellArea        *area,
1232                                  GtkCellRenderer    *renderer,
1233                                  const gchar        *property_name,
1234                                  const GValue       *value)
1235 {
1236   GParamSpec *pspec;
1237
1238   g_return_if_fail (GTK_IS_CELL_AREA (area));
1239   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1240   g_return_if_fail (property_name != NULL);
1241   g_return_if_fail (G_IS_VALUE (value));
1242   
1243   pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
1244                                     G_OBJECT_TYPE (area), TRUE);
1245   if (!pspec)
1246     g_warning ("%s: cell area class `%s' has no cell property named `%s'",
1247                G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
1248   else if (!(pspec->flags & G_PARAM_WRITABLE))
1249     g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
1250                G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
1251   else
1252     {
1253       area_set_cell_property (area, renderer, pspec, value);
1254     }
1255 }
1256
1257 void
1258 gtk_cell_area_cell_get_property (GtkCellArea        *area,
1259                                  GtkCellRenderer    *renderer,
1260                                  const gchar        *property_name,
1261                                  GValue             *value)
1262 {
1263   GParamSpec *pspec;
1264
1265   g_return_if_fail (GTK_IS_CELL_AREA (area));
1266   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1267   g_return_if_fail (property_name != NULL);
1268   g_return_if_fail (G_IS_VALUE (value));
1269   
1270   pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
1271                                     G_OBJECT_TYPE (area), TRUE);
1272   if (!pspec)
1273     g_warning ("%s: cell area class `%s' has no cell property named `%s'",
1274                G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
1275   else if (!(pspec->flags & G_PARAM_READABLE))
1276     g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
1277                G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
1278   else
1279     {
1280       GValue *prop_value, tmp_value = { 0, };
1281
1282       /* auto-conversion of the callers value type
1283        */
1284       if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
1285         {
1286           g_value_reset (value);
1287           prop_value = value;
1288         }
1289       else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
1290         {
1291           g_warning ("can't retrieve cell property `%s' of type `%s' as value of type `%s'",
1292                      pspec->name,
1293                      g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1294                      G_VALUE_TYPE_NAME (value));
1295           return;
1296         }
1297       else
1298         {
1299           g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1300           prop_value = &tmp_value;
1301         }
1302
1303       area_get_cell_property (area, renderer, pspec, prop_value);
1304
1305       if (prop_value != value)
1306         {
1307           g_value_transform (prop_value, value);
1308           g_value_unset (&tmp_value);
1309         }
1310     }
1311 }
1312
1313 /*************************************************************
1314  *                         API: Focus                        *
1315  *************************************************************/
1316 void
1317 gtk_cell_area_grab_focus (GtkCellArea      *area,
1318                           GtkDirectionType  direction)
1319 {
1320   GtkCellAreaClass *class;
1321
1322   g_return_if_fail (GTK_IS_CELL_AREA (area));
1323
1324   class = GTK_CELL_AREA_GET_CLASS (area);
1325
1326   if (class->grab_focus)
1327     class->grab_focus (area, direction);
1328   else
1329     g_warning ("GtkCellAreaClass::grab_focus not implemented for `%s'", 
1330                g_type_name (G_TYPE_FROM_INSTANCE (area)));
1331 }
1332
1333 void
1334 gtk_cell_area_focus_leave (GtkCellArea        *area,
1335                            GtkDirectionType    direction,
1336                            const gchar        *path)
1337 {
1338   g_return_if_fail (GTK_IS_CELL_AREA (area));
1339
1340   g_signal_emit (area, cell_area_signals[SIGNAL_FOCUS_LEAVE], 0, direction, path);
1341 }
1342
1343 void
1344 gtk_cell_area_set_can_focus (GtkCellArea *area,
1345                              gboolean     can_focus)
1346 {
1347   GtkCellAreaPrivate *priv;
1348
1349   g_return_if_fail (GTK_IS_CELL_AREA (area));
1350
1351   priv = area->priv;
1352
1353   if (priv->can_focus != can_focus)
1354     {
1355       priv->can_focus = can_focus;
1356     }
1357 }
1358
1359 gboolean
1360 gtk_cell_area_get_can_focus (GtkCellArea *area)
1361 {
1362   GtkCellAreaPrivate *priv;
1363
1364   g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
1365
1366   priv = area->priv;
1367
1368   return priv->can_focus;
1369 }
1370
1371 void
1372 gtk_cell_area_set_focus_cell (GtkCellArea     *area,
1373                               GtkCellRenderer *renderer)
1374 {
1375   GtkCellAreaPrivate *priv;
1376
1377   g_return_if_fail (GTK_IS_CELL_AREA (area));
1378   g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
1379
1380   priv = area->priv;
1381
1382   if (priv->focus_cell != renderer)
1383     {
1384       if (priv->focus_cell)
1385         g_object_unref (priv->focus_cell);
1386
1387       priv->focus_cell = renderer;
1388
1389       if (priv->focus_cell)
1390         g_object_ref (priv->focus_cell);
1391     }
1392 }
1393
1394 GtkCellRenderer *
1395 gtk_cell_area_get_focus_cell (GtkCellArea *area)
1396 {
1397   GtkCellAreaPrivate *priv;
1398
1399   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1400
1401   priv = area->priv;
1402
1403   return priv->focus_cell;
1404 }
1405
1406 /*************************************************************
1407  *                        API: Margins                       *
1408  *************************************************************/
1409 gint
1410 gtk_cell_area_get_cell_margin_left (GtkCellArea *area)
1411 {
1412   g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1413
1414   return area->priv->cell_border.left;
1415 }
1416
1417 void
1418 gtk_cell_area_set_cell_margin_left (GtkCellArea *area,
1419                                     gint         margin)
1420 {
1421   GtkCellAreaPrivate *priv;
1422
1423   g_return_if_fail (GTK_IS_CELL_AREA (area));
1424
1425   priv = area->priv;
1426
1427   if (priv->cell_border.left != margin)
1428     {
1429       priv->cell_border.left = margin;
1430
1431       g_object_notify (G_OBJECT (area), "margin-left");
1432     }
1433 }
1434
1435 gint
1436 gtk_cell_area_get_cell_margin_right (GtkCellArea *area)
1437 {
1438   g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1439
1440   return area->priv->cell_border.right;
1441 }
1442
1443 void
1444 gtk_cell_area_set_cell_margin_right (GtkCellArea *area,
1445                                      gint         margin)
1446 {
1447   GtkCellAreaPrivate *priv;
1448
1449   g_return_if_fail (GTK_IS_CELL_AREA (area));
1450
1451   priv = area->priv;
1452
1453   if (priv->cell_border.right != margin)
1454     {
1455       priv->cell_border.right = margin;
1456
1457       g_object_notify (G_OBJECT (area), "margin-right");
1458     }
1459 }
1460
1461 gint
1462 gtk_cell_area_get_cell_margin_top (GtkCellArea *area)
1463 {
1464   g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1465
1466   return area->priv->cell_border.top;
1467 }
1468
1469 void
1470 gtk_cell_area_set_cell_margin_top (GtkCellArea *area,
1471                                    gint         margin)
1472 {
1473   GtkCellAreaPrivate *priv;
1474
1475   g_return_if_fail (GTK_IS_CELL_AREA (area));
1476
1477   priv = area->priv;
1478
1479   if (priv->cell_border.top != margin)
1480     {
1481       priv->cell_border.top = margin;
1482
1483       g_object_notify (G_OBJECT (area), "margin-top");
1484     }
1485 }
1486
1487 gint
1488 gtk_cell_area_get_cell_margin_bottom (GtkCellArea *area)
1489 {
1490   g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1491
1492   return area->priv->cell_border.bottom;
1493 }
1494
1495 void
1496 gtk_cell_area_set_cell_margin_bottom (GtkCellArea *area,
1497                                       gint         margin)
1498 {
1499   GtkCellAreaPrivate *priv;
1500
1501   g_return_if_fail (GTK_IS_CELL_AREA (area));
1502
1503   priv = area->priv;
1504
1505   if (priv->cell_border.bottom != margin)
1506     {
1507       priv->cell_border.bottom = margin;
1508
1509       g_object_notify (G_OBJECT (area), "margin-bottom");
1510     }
1511 }
1512
1513 /* For convenience in area implementations */
1514 void
1515 gtk_cell_area_inner_cell_area (GtkCellArea        *area,
1516                                GdkRectangle       *background_area,
1517                                GdkRectangle       *cell_area)
1518 {
1519   GtkCellAreaPrivate *priv;
1520
1521   g_return_if_fail (GTK_IS_CELL_AREA (area));
1522   g_return_if_fail (background_area != NULL);
1523   g_return_if_fail (cell_area != NULL);
1524
1525   priv = area->priv;
1526
1527   *cell_area = *background_area;
1528
1529   cell_area->x      += priv->cell_border.left;
1530   cell_area->width  -= (priv->cell_border.left + priv->cell_border.right);
1531   cell_area->y      += priv->cell_border.top;
1532   cell_area->height -= (priv->cell_border.top + priv->cell_border.bottom);
1533 }
1534
1535 void
1536 gtk_cell_area_request_renderer (GtkCellArea        *area,
1537                                 GtkCellRenderer    *renderer,
1538                                 GtkOrientation      orientation,
1539                                 GtkWidget          *widget,
1540                                 gint                for_size,
1541                                 gint               *minimum_size,
1542                                 gint               *natural_size)
1543 {
1544   GtkCellAreaPrivate *priv;
1545
1546   g_return_if_fail (GTK_IS_CELL_AREA (area));
1547   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1548   g_return_if_fail (GTK_IS_WIDGET (widget));
1549   g_return_if_fail (minimum_size != NULL);
1550   g_return_if_fail (natural_size != NULL);
1551
1552   priv = area->priv;
1553
1554   if (orientation == GTK_ORIENTATION_HORIZONTAL)
1555     {
1556       if (for_size < 0)
1557           gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
1558       else
1559         {
1560           for_size = MAX (0, for_size - (priv->cell_border.top + priv->cell_border.bottom));
1561
1562           gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size, 
1563                                                             minimum_size, natural_size);
1564         }
1565
1566       *minimum_size += (priv->cell_border.left + priv->cell_border.right);
1567       *natural_size += (priv->cell_border.left + priv->cell_border.right);
1568     }
1569   else /* GTK_ORIENTATION_VERTICAL */
1570     {
1571       if (for_size < 0)
1572         gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
1573       else
1574         {
1575           for_size = MAX (0, for_size - (priv->cell_border.left + priv->cell_border.right));
1576
1577           gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size, 
1578                                                             minimum_size, natural_size);
1579         }
1580
1581       *minimum_size += (priv->cell_border.top + priv->cell_border.bottom);
1582       *natural_size += (priv->cell_border.top + priv->cell_border.bottom);
1583     }
1584 }