]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellarea.c
Make editable widget fill the entire inner area of the edited cell
[~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 /**
25  * SECTION:gtkcellarea
26  * @Short_Description: An abstract class for laying out #GtkCellRenderers
27  * @Title: GtkCellArea
28  *
29  * The #GtkCellArea is an abstract class for laying out #GtkCellRenderers
30  * onto a given area of a #GtkWidget.
31  *
32  * The work of rendering #GtkCellRenderers can be very complicated; it involves
33  * requesting size for cells, driving keyboard focus from cell to cell, rendering
34  * the actual cells, painting the focus onto the currently focused cell and finally
35  * activating cells which are %GTK_CELL_RENDERER_MODE_ACTIVATABLE and editing cells
36  * which are %GTK_CELL_RENDERER_MODE_EDITABLE. The work is even more complex since
37  * a cell renderer as opposed to a widget, is used to interact with an arbitrary
38  * number of #GtkTreeModel rows instead of always displaying the same data.
39  *
40  * <refsect2 id="cell-area-geometry-management">
41  * <title>Requesting area sizes</title>
42  * <para>
43  * As outlined in <link linkend="geometry-management">GtkWidget's
44  * geometry management section</link>, GTK+ uses a height-for-width
45  * geometry managemen system to compute the sizes of widgets and user 
46  * interfaces. #GtkCellArea uses the same semantics to calculate the
47  * size of an area for an arbitrary number of #GtkTreeModel rows.
48  *
49  * When requesting the size of a #GtkCellArea one needs to calculate
50  * the size of a handful of rows, this will be done differently by
51  * different #GtkCellLayout widgets. For instance a #GtkTreeViewColumn
52  * always lines up the areas from top to bottom while a #GtkIconView
53  * on the other hand might enforce that areas maintain a fixed width
54  * and then wrap the area around, thus requesting height for more
55  * areas when allocated less width.
56  *
57  * It's also important for #GtkCellAreas to maintain some cell 
58  * alignments with areas rendered for different rows so that
59  * a handful of rendered rows can allocate the same size for
60  * a said cell across rows (and also to make sure to request
61  * an appropriate size for the largest row after requesting
62  * a hand full of rows). For this reason the #GtkCellArea
63  * uses a #GtkCellAreaContext object to store the alignments
64  * and sizes along the way.
65  *
66  * In order to request the width of all the rows at the root level
67  * of a #GtkTreeModel one would do the following:
68  * <example>
69  *   <title>Requesting the width of a hand full of GtkTreeModel rows.</title>
70  *   <programlisting>
71  * GtkTreeIter iter;
72  * gint        minimum_width;
73  * gint        natural_width;
74  *
75  * valid = gtk_tree_model_get_iter_first (model, &iter);
76  * while (valid)
77  *   {
78  *     gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
79  *     gtk_cell_area_get_preferred_width (area, context, widget, NULL, NULL);
80  *
81  *     valid = gtk_tree_model_iter_next (model, &iter);
82  *   }
83  * gtk_cell_area_context_get_preferred_width (context, &minimum_width, &natural_width);
84  *   </programlisting>
85  * </example>
86  * Note that in this example it's not important to observe the returned minimum and
87  * natural width of the area for each row unless the cell layouting object is actually
88  * interested in the widths of individual rows. The overall width is however stored
89  * in the accompanying #GtkCellAreaContext object and can be consulted at any time.
90  *
91  * This can be useful since #GtkCellLayout widgets usually have to support requesting
92  * and rendering rows in treemodels with an exceedingly large amount of rows. The
93  * #GtkCellLayout widget in that case would calculate the required width of the rows
94  * in an idle or timeout source (see g_timeout_add()) and when the widget is requested
95  * its actual width in #GtkWidgetClass.get_preferred_width() it can simply consult the
96  * width accumulated so far in the #GtkCellAreaContext object.
97  *
98  * A simple example where rows are rendered from top to bottom and take up the full
99  * width of the layouting widget would look like:
100  * <example>
101  *   <title>Requesting the width of a hand full of GtkTreeModel rows.</title>
102  *   <programlisting>
103  * static void
104  * foo_get_preferred_width (GtkWidget       *widget,
105  *                          gint            *minimum_size,
106  *                          gint            *natural_size)
107  * {
108  *   Foo        *foo  = FOO (widget);
109  *   FooPrivate *priv = foo->priv;
110  *
111  *   foo_ensure_at_least_one_handfull_of_rows_have_been_requested (foo);
112  *
113  *   gtk_cell_area_context_get_preferred_width (priv->context, minimum_size, natural_size);
114  * }
115  *   </programlisting>
116  * </example>
117  * 
118  * In the above example the Foo widget has to make sure that some row sizes have
119  * been calculated (the amount of rows that Foo judged was appropriate to request
120  * space for in a single timeout iteration) before simply returning the amount
121  * of space required by the area via the #GtkCellAreaContext.
122  * 
123  * Requesting the height for width (or width for height) of an area is a similar
124  * task except in this case the #GtkCellAreaContext does not store the data (actually
125  * it does not know how much space the layouting widget plans to allocate it for
126  * every row, it's up to the layouting widget to render each row of data with
127  * the appropriate height and width which was requested by the #GtkCellArea).
128  *
129  * In order to request the height for width of all the rows at the root level
130  * of a #GtkTreeModel one would do the following:
131  * <example>
132  *   <title>Requesting the height for width of a hand full of GtkTreeModel rows.</title>
133  *   <programlisting>
134  * GtkTreeIter iter;
135  * gint        minimum_height;
136  * gint        natural_height;
137  * gint        full_minimum_height = 0;
138  * gint        full_natural_height = 0;
139  *
140  * valid = gtk_tree_model_get_iter_first (model, &iter);
141  * while (valid)
142  *   {
143  *     gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
144  *     gtk_cell_area_get_preferred_height_for_width (area, context, widget, 
145  *                                                   width, &minimum_height, &natural_height);
146  *
147  *     if (width_is_for_allocation)
148  *        cache_row_height (&iter, minimum_height, natural_height);
149  *
150  *     full_minimum_height += minimum_height;
151  *     full_natural_height += natural_height;
152  *
153  *     valid = gtk_tree_model_iter_next (model, &iter);
154  *   }
155  *   </programlisting>
156  * </example>
157  *
158  * Note that in the above example we would need to cache the heights returned for each
159  * treemodel row so that we would know what sizes to render the areas for each row. However
160  * we would only want to really cache the heights if the request is intended for the
161  * layouting widgets real allocation.
162  *
163  * In some cases the layouting widget is requested the height for an arbitrary for_width,
164  * this is a special case for layouting widgets who need to request size for tens of thousands 
165  * of treemodel rows. For this case it's only important that the layouting widget calculate
166  * one reasonably sized chunk of rows and return that height synchronously. The reasoning here
167  * is that any layouting widget is at least capable of synchronously calculating enough 
168  * height to fill the screen height (or scrolled window height) in response to a single call to 
169  * #GtkWidgetClass.get_preferred_height_for_width(). Returning a perfect height for width that
170  * is larger than the screen area is inconsequential since after the layouting receives an
171  * allocation from a scrolled window it simply continues to drive the the scrollbar
172  * values while more and mode height is required for the row heights that are calculated
173  * in the background.
174  * </para>
175  * </refsect2>
176  * <refsect2 id="cell-area-rendering">
177  * <title>Rendering Areas</title>
178  * <para>
179  * Once area sizes have been aquired at least for the rows in the visible area of the
180  * layouting widget they can be rendered at #GtkWidgetClass.draw() time.
181  *
182  * A crued example of how to render all the rows at the root level runs as follows:
183  * <example>
184  *   <title>Requesting the width of a hand full of GtkTreeModel rows.</title>
185  *   <programlisting>
186  * GtkAllocation allocation;
187  * GdkRectangle  cell_area = { 0, };
188  * GtkTreeIter   iter;
189  * gint          minimum_width;
190  * gint          natural_width;
191  *
192  * gtk_widget_get_allocation (widget, &allocation);
193  * cell_area.width = allocation.width;
194  *
195  * valid = gtk_tree_model_get_iter_first (model, &iter);
196  * while (valid)
197  *   {
198  *     cell_area.height = get_cached_height_for_row (&iter);
199  *
200  *     gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
201  *     gtk_cell_area_render (area, context, widget, cr, 
202  *                           &cell_area, &cell_area, state_flags, FALSE);
203  *
204  *     cell_area.y += cell_area.height;
205  *
206  *     valid = gtk_tree_model_iter_next (model, &iter);
207  *   }
208  *   </programlisting>
209  * </example>
210  * Note that the cached height in this example really depends on how the layouting
211  * widget works. The layouting widget might decide to give every row it's minimum
212  * or natural height or if the model content is expected to fit inside the layouting
213  * widget with not scrolled window it would make sense to calculate the allocation
214  * for each row at #GtkWidget.size_allocate() time using gtk_distribute_natural_allocation().
215  * </para>
216  * </refsect2>
217  * <refsect2 id="cell-area-events-and-focus">
218  * <title>Handling Events and Driving Keyboard Focus</title>
219  * <para>
220  * Passing events to the area is as simple as handling events on any normal
221  * widget and then passing them to the gtk_cell_area_event() api as they come
222  * in. Usually #GtkCellArea is only interested in button events, however some
223  * customized derived areas can be implemented who are interested in handling
224  * other events. Handling an event can trigger the #GtkCellArea::focus-changed
225  * signal to fire as well as #GtkCellArea::add-editable in the case that
226  * an editable cell was clicked and needs to start editing.
227  *
228  * The #GtkCellArea drives keyboard focus from cell to cell in a way similar
229  * to #GtkWidget. For layouting widgets that support giving focus to cells it's
230  * important to remember to pass %GTK_CELL_RENDERER_FOCUSED to the area functions
231  * for the row that has focus and to tell the area to paint the focus at render
232  * time.
233  *
234  * Layouting widgets that accept focus on cells should implement the #GtkWidgetClass.focus()
235  * virtual method. The layouting widget is always responsible for knowing where 
236  * #GtkTreeModel rows are rendered inside the widget, so at #GtkWidgetClass.focus() time 
237  * the layouting widget should use the #GtkCellArea methods to navigate focus inside the 
238  * area and then observe the GtkDirectionType to pass the focus to adjacent rows and
239  * areas.
240  *
241  * A basic example of how the #GtkWidgetClass.focus() virtual method should be implemented:
242  * <example>
243  *   <title>Implementing keyboard focus navigation when displaying rows from top to bottom.</title>
244  *   <programlisting>
245  * static void
246  * foo_focus (GtkWidget       *widget,
247  *            GtkDirectionType direction)
248  * {
249  *   Foo        *foo  = FOO (widget);
250  *   FooPrivate *priv = foo->priv;
251  *   gint        focus_row;
252  *   gboolean    have_focus = FALSE;
253  *
254  *   focus_row = priv->focus_row;
255  *
256  *   if (!gtk_widget_has_focus (widget))
257  *     gtk_widget_grab_focus (widget);
258  *
259  *   valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, priv->focus_row);
260  *   while (valid)
261  *     {
262  *       gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
263  *
264  *       if (gtk_cell_area_focus (priv->area, direction))
265  *         {
266  *            priv->focus_row = focus_row;
267  *            have_focus = TRUE;
268  *            break;
269  *         }
270  *       else
271  *         {
272  *           if (direction == GTK_DIR_RIGHT ||
273  *               direction == GTK_DIR_LEFT)
274  *             break;
275  *           else if (direction == GTK_DIR_UP ||
276  *                    direction == GTK_DIR_TAB_BACKWARD)
277  *             {
278  *               if (focus_row == 0)
279  *                 break;
280  *               else
281  *                {
282  *                   focus_row--;
283  *                   valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, focus_row);
284  *                }
285  *             }
286  *           else
287  *             {
288  *               if (focus_row == last_row)
289  *                 break;
290  *               else
291  *                 {
292  *                   focus_row++;
293  *                   valid = gtk_tree_model_iter_next (priv->model, &iter);
294  *                 }
295  *             }
296  *         }
297  *     }
298  *     return have_focus;
299  * }
300  *   </programlisting>
301  * </example>
302  * </para>
303  * </refsect2>
304  *
305  */
306
307 #include "config.h"
308
309 #include <stdarg.h>
310 #include <string.h>
311 #include <stdlib.h>
312
313 #include "gtkintl.h"
314 #include "gtkcelllayout.h"
315 #include "gtkcellarea.h"
316 #include "gtkcellareacontext.h"
317 #include "gtkmarshalers.h"
318 #include "gtkprivate.h"
319
320 #include <gobject/gvaluecollector.h>
321
322
323 /* GObjectClass */
324 static void      gtk_cell_area_dispose                             (GObject            *object);
325 static void      gtk_cell_area_finalize                            (GObject            *object);
326 static void      gtk_cell_area_set_property                        (GObject            *object,
327                                                                     guint               prop_id,
328                                                                     const GValue       *value,
329                                                                     GParamSpec         *pspec);
330 static void      gtk_cell_area_get_property                        (GObject            *object,
331                                                                     guint               prop_id,
332                                                                     GValue             *value,
333                                                                     GParamSpec         *pspec);
334
335 /* GtkCellAreaClass */
336 static gint      gtk_cell_area_real_event                          (GtkCellArea          *area,
337                                                                     GtkCellAreaContext   *context,
338                                                                     GtkWidget            *widget,
339                                                                     GdkEvent             *event,
340                                                                     const GdkRectangle   *cell_area,
341                                                                     GtkCellRendererState  flags);
342 static void      gtk_cell_area_real_apply_attributes               (GtkCellArea           *area,
343                                                                     GtkTreeModel          *tree_model,
344                                                                     GtkTreeIter           *iter,
345                                                                     gboolean               is_expander,
346                                                                     gboolean               is_expanded);
347 static void      gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea           *area,
348                                                                     GtkCellAreaContext    *context,
349                                                                     GtkWidget             *widget,
350                                                                     gint                   width,
351                                                                     gint                  *minimum_height,
352                                                                     gint                  *natural_height);
353 static void      gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea           *area,
354                                                                     GtkCellAreaContext    *context,
355                                                                     GtkWidget             *widget,
356                                                                     gint                   height,
357                                                                     gint                  *minimum_width,
358                                                                     gint                  *natural_width);
359 static gboolean  gtk_cell_area_real_can_focus                      (GtkCellArea           *area);
360 static gboolean  gtk_cell_area_real_activate                       (GtkCellArea           *area,
361                                                                     GtkCellAreaContext    *context,
362                                                                     GtkWidget             *widget,
363                                                                     const GdkRectangle    *cell_area,
364                                                                     GtkCellRendererState   flags);
365
366 /* GtkCellLayoutIface */
367 static void      gtk_cell_area_cell_layout_init              (GtkCellLayoutIface    *iface);
368 static void      gtk_cell_area_pack_default                  (GtkCellLayout         *cell_layout,
369                                                               GtkCellRenderer       *renderer,
370                                                               gboolean               expand);
371 static void      gtk_cell_area_clear                         (GtkCellLayout         *cell_layout);
372 static void      gtk_cell_area_add_attribute                 (GtkCellLayout         *cell_layout,
373                                                               GtkCellRenderer       *renderer,
374                                                               const gchar           *attribute,
375                                                               gint                   column);
376 static void      gtk_cell_area_set_cell_data_func            (GtkCellLayout         *cell_layout,
377                                                               GtkCellRenderer       *cell,
378                                                               GtkCellLayoutDataFunc  func,
379                                                               gpointer               func_data,
380                                                               GDestroyNotify         destroy);
381 static void      gtk_cell_area_clear_attributes              (GtkCellLayout         *cell_layout,
382                                                               GtkCellRenderer       *renderer);
383 static void      gtk_cell_area_reorder                       (GtkCellLayout         *cell_layout,
384                                                               GtkCellRenderer       *cell,
385                                                               gint                   position);
386 static GList    *gtk_cell_area_get_cells                     (GtkCellLayout         *cell_layout);
387
388
389 /* Used in forall loop to check if a child renderer is present */
390 typedef struct {
391   GtkCellRenderer *renderer;
392   gboolean         has_renderer;
393 } HasRendererCheck;
394
395 /* Attribute/Cell metadata */
396 typedef struct {
397   const gchar *attribute;
398   gint         column;
399 } CellAttribute;
400
401 typedef struct {
402   GSList          *attributes;
403
404   GtkCellLayoutDataFunc  func;
405   gpointer               data;
406   GDestroyNotify         destroy;
407 } CellInfo;
408
409 static CellInfo       *cell_info_new       (GtkCellLayoutDataFunc  func,
410                                             gpointer               data,
411                                             GDestroyNotify         destroy);
412 static void            cell_info_free      (CellInfo              *info);
413 static CellAttribute  *cell_attribute_new  (GtkCellRenderer       *renderer,
414                                             const gchar           *attribute,
415                                             gint                   column);
416 static void            cell_attribute_free (CellAttribute         *attribute);
417 static gint            cell_attribute_find (CellAttribute         *cell_attribute,
418                                             const gchar           *attribute);
419
420 /* Internal functions/signal emissions */
421 static void            gtk_cell_area_add_editable     (GtkCellArea        *area,
422                                                        GtkCellRenderer    *renderer,
423                                                        GtkCellEditable    *editable,
424                                                        GdkRectangle       *cell_area);
425 static void            gtk_cell_area_remove_editable  (GtkCellArea        *area,
426                                                        GtkCellRenderer    *renderer,
427                                                        GtkCellEditable    *editable);
428 static void            gtk_cell_area_set_edit_widget  (GtkCellArea        *area,
429                                                        GtkCellEditable    *editable);
430 static void            gtk_cell_area_set_edited_cell  (GtkCellArea        *area,
431                                                        GtkCellRenderer    *renderer);
432
433
434 /* Struct to pass data along while looping over 
435  * cell renderers to apply attributes
436  */
437 typedef struct {
438   GtkCellArea  *area;
439   GtkTreeModel *model;
440   GtkTreeIter  *iter;
441   gboolean      is_expander;
442   gboolean      is_expanded;
443 } AttributeData;
444
445 struct _GtkCellAreaPrivate
446 {
447   /* The GtkCellArea bookkeeps any connected 
448    * attributes in this hash table.
449    */
450   GHashTable      *cell_info;
451
452   /* Current path is saved as a side-effect
453    * of gtk_cell_area_apply_attributes() */
454   gchar           *current_path;
455
456   /* Current cell being edited and editable widget used */
457   GtkCellEditable *edit_widget;
458   GtkCellRenderer *edited_cell;
459
460   /* Signal connections to the editable widget */
461   gulong           remove_widget_id;
462
463   /* Currently focused cell */
464   GtkCellRenderer *focus_cell;
465
466   /* Tracking which cells are focus siblings of focusable cells */
467   GHashTable      *focus_siblings;
468
469   /* Detail string to pass to gtk_paint_*() functions */
470   gchar           *style_detail;
471 };
472
473 enum {
474   PROP_0,
475   PROP_FOCUS_CELL,
476   PROP_EDITED_CELL,
477   PROP_EDIT_WIDGET
478 };
479
480 enum {
481   SIGNAL_APPLY_ATTRIBUTES,
482   SIGNAL_ADD_EDITABLE,
483   SIGNAL_REMOVE_EDITABLE,
484   SIGNAL_FOCUS_CHANGED,
485   LAST_SIGNAL
486 };
487
488 /* Keep the paramspec pool internal, no need to deliver notifications
489  * on cells. at least no percieved need for now */
490 static GParamSpecPool *cell_property_pool = NULL;
491 static guint           cell_area_signals[LAST_SIGNAL] = { 0 };
492
493 #define PARAM_SPEC_PARAM_ID(pspec)              ((pspec)->param_id)
494 #define PARAM_SPEC_SET_PARAM_ID(pspec, id)      ((pspec)->param_id = (id))
495
496
497 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkCellArea, gtk_cell_area, G_TYPE_INITIALLY_UNOWNED,
498                                   G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
499                                                          gtk_cell_area_cell_layout_init));
500
501 static void
502 gtk_cell_area_init (GtkCellArea *area)
503 {
504   GtkCellAreaPrivate *priv;
505
506   area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area,
507                                             GTK_TYPE_CELL_AREA,
508                                             GtkCellAreaPrivate);
509   priv = area->priv;
510
511   priv->cell_info = g_hash_table_new_full (g_direct_hash, 
512                                            g_direct_equal,
513                                            NULL, 
514                                            (GDestroyNotify)cell_info_free);
515
516   priv->focus_siblings = g_hash_table_new_full (g_direct_hash, 
517                                                 g_direct_equal,
518                                                 NULL, 
519                                                 (GDestroyNotify)g_list_free);
520
521   priv->focus_cell         = NULL;
522   priv->edited_cell        = NULL;
523   priv->edit_widget        = NULL;
524
525   priv->remove_widget_id   = 0;
526 }
527
528 static void 
529 gtk_cell_area_class_init (GtkCellAreaClass *class)
530 {
531   GObjectClass *object_class = G_OBJECT_CLASS (class);
532   
533   /* GObjectClass */
534   object_class->dispose      = gtk_cell_area_dispose;
535   object_class->finalize     = gtk_cell_area_finalize;
536   object_class->get_property = gtk_cell_area_get_property;
537   object_class->set_property = gtk_cell_area_set_property;
538
539   /* general */
540   class->add              = NULL;
541   class->remove           = NULL;
542   class->forall           = NULL;
543   class->event            = gtk_cell_area_real_event;
544   class->render           = NULL;
545   class->apply_attributes = gtk_cell_area_real_apply_attributes;
546
547   /* geometry */
548   class->create_context                 = NULL;
549   class->get_request_mode               = NULL;
550   class->get_preferred_width            = NULL;
551   class->get_preferred_height           = NULL;
552   class->get_preferred_height_for_width = gtk_cell_area_real_get_preferred_height_for_width;
553   class->get_preferred_width_for_height = gtk_cell_area_real_get_preferred_width_for_height;
554
555   /* focus */
556   class->can_focus  = gtk_cell_area_real_can_focus;
557   class->focus      = NULL;
558   class->activate   = gtk_cell_area_real_activate;
559
560   /* Signals */
561   /**
562    * GtkCellArea::apply-attributes:
563    * @area: the #GtkCellArea to apply the attributes to
564    * @model: the #GtkTreeModel to apply the attributes from
565    * @iter: the #GtkTreeIter indicating which row to apply the attributes of
566    * @is_expander: whether the view shows children for this row
567    * @is_expanded: whether the view is currently showing the children of this row
568    *
569    * This signal is emitted whenever applying attributes to @area from @model
570    */
571   cell_area_signals[SIGNAL_APPLY_ATTRIBUTES] =
572     g_signal_new (I_("apply-attributes"),
573                   G_OBJECT_CLASS_TYPE (object_class),
574                   G_SIGNAL_RUN_FIRST,
575                   G_STRUCT_OFFSET (GtkCellAreaClass, apply_attributes),
576                   NULL, NULL,
577                   _gtk_marshal_VOID__OBJECT_BOXED_BOOLEAN_BOOLEAN,
578                   G_TYPE_NONE, 4,
579                   GTK_TYPE_TREE_MODEL,
580                   GTK_TYPE_TREE_ITER,
581                   G_TYPE_BOOLEAN,
582                   G_TYPE_BOOLEAN);
583
584   /**
585    * GtkCellArea::add-editable:
586    * @area: the #GtkCellArea where editing started
587    * @renderer: the #GtkCellRenderer that started the edited
588    * @editable: the #GtkCellEditable widget to add
589    * @cell_area: the #GtkWidget relative #GdkRectangle coordinates
590    *             where @editable should be added
591    * @path:      the #GtkTreePath string this edit was initiated for
592    *
593    * Indicates that editing has started on @renderer and that @editable
594    * should be added to the owning cell layouting widget at @cell_area.
595    */
596   cell_area_signals[SIGNAL_ADD_EDITABLE] =
597     g_signal_new (I_("add-editable"),
598                   G_OBJECT_CLASS_TYPE (object_class),
599                   G_SIGNAL_RUN_FIRST,
600                   0, /* No class closure here */
601                   NULL, NULL,
602                   _gtk_marshal_VOID__OBJECT_OBJECT_BOXED_STRING,
603                   G_TYPE_NONE, 4,
604                   GTK_TYPE_CELL_RENDERER,
605                   GTK_TYPE_CELL_EDITABLE,
606                   GDK_TYPE_RECTANGLE,
607                   G_TYPE_STRING);
608
609
610   /**
611    * GtkCellArea::remove-editable:
612    * @area: the #GtkCellArea where editing finished
613    * @renderer: the #GtkCellRenderer that finished editeding
614    * @editable: the #GtkCellEditable widget to remove
615    *
616    * Indicates that editing finished on @renderer and that @editable
617    * should be removed from the owning cell layouting widget.
618    */
619   cell_area_signals[SIGNAL_REMOVE_EDITABLE] =
620     g_signal_new (I_("remove-editable"),
621                   G_OBJECT_CLASS_TYPE (object_class),
622                   G_SIGNAL_RUN_FIRST,
623                   0, /* No class closure here */
624                   NULL, NULL,
625                   _gtk_marshal_VOID__OBJECT_OBJECT,
626                   G_TYPE_NONE, 2,
627                   GTK_TYPE_CELL_RENDERER,
628                   GTK_TYPE_CELL_EDITABLE);
629
630   /**
631    * GtkCellArea::focus-changed:
632    * @area: the #GtkCellArea where focus changed
633    * @renderer: the #GtkCellRenderer that has focus
634    * @path: the current #GtkTreePath string set for @area
635    *
636    * Indicates that focus changed on this @area. This signal
637    * is emitted either as a result of focus handling or event
638    * handling.
639    *
640    * It's possible that the signal is emitted even if the
641    * currently focused renderer did not change, this is
642    * because focus may change to the same renderer in the
643    * same cell area for a different row of data.
644    */
645   cell_area_signals[SIGNAL_FOCUS_CHANGED] =
646     g_signal_new (I_("focus-changed"),
647                   G_OBJECT_CLASS_TYPE (object_class),
648                   G_SIGNAL_RUN_FIRST,
649                   0, /* No class closure here */
650                   NULL, NULL,
651                   _gtk_marshal_VOID__OBJECT_STRING,
652                   G_TYPE_NONE, 2,
653                   GTK_TYPE_CELL_RENDERER,
654                   G_TYPE_STRING);
655
656   /* Properties */
657   /**
658    * GtkCellArea:focus-cell:
659    *
660    * The cell in the area that currently has focus
661    */
662   g_object_class_install_property (object_class,
663                                    PROP_FOCUS_CELL,
664                                    g_param_spec_object
665                                    ("focus-cell",
666                                     P_("Focus Cell"),
667                                     P_("The cell which currently has focus"),
668                                     GTK_TYPE_CELL_RENDERER,
669                                     GTK_PARAM_READWRITE));
670
671   /**
672    * GtkCellArea:edited-cell:
673    *
674    * The cell in the area that is currently edited
675    *
676    * This property is read-only and only changes as
677    * a result of a call gtk_cell_area_activate_cell().
678    */
679   g_object_class_install_property (object_class,
680                                    PROP_EDITED_CELL,
681                                    g_param_spec_object
682                                    ("edited-cell",
683                                     P_("Edited Cell"),
684                                     P_("The cell which is currently being edited"),
685                                     GTK_TYPE_CELL_RENDERER,
686                                     G_PARAM_READABLE));
687
688   /**
689    * GtkCellArea:edit-widget:
690    *
691    * The widget currently editing the edited cell
692    *
693    * This property is read-only and only changes as
694    * a result of a call gtk_cell_area_activate_cell().
695    */
696   g_object_class_install_property (object_class,
697                                    PROP_EDIT_WIDGET,
698                                    g_param_spec_object
699                                    ("edit-widget",
700                                     P_("Edit Widget"),
701                                     P_("The widget currently editing the edited cell"),
702                                     GTK_TYPE_CELL_RENDERER,
703                                     G_PARAM_READABLE));
704
705   /* Pool for Cell Properties */
706   if (!cell_property_pool)
707     cell_property_pool = g_param_spec_pool_new (FALSE);
708
709   g_type_class_add_private (object_class, sizeof (GtkCellAreaPrivate));
710 }
711
712 /*************************************************************
713  *                    CellInfo Basics                        *
714  *************************************************************/
715 static CellInfo *
716 cell_info_new (GtkCellLayoutDataFunc  func,
717                gpointer               data,
718                GDestroyNotify         destroy)
719 {
720   CellInfo *info = g_slice_new0 (CellInfo);
721
722   info->func     = func;
723   info->data     = data;
724   info->destroy  = destroy;
725
726   return info;
727 }
728
729 static void
730 cell_info_free (CellInfo *info)
731 {
732   if (info->destroy)
733     info->destroy (info->data);
734
735   g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
736   g_slist_free (info->attributes);
737
738   g_slice_free (CellInfo, info);
739 }
740
741 static CellAttribute  *
742 cell_attribute_new  (GtkCellRenderer       *renderer,
743                      const gchar           *attribute,
744                      gint                   column)
745 {
746   GParamSpec *pspec;
747
748   /* Check if the attribute really exists and point to
749    * the property string installed on the cell renderer
750    * class (dont dup the string) 
751    */
752   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (renderer), attribute);
753
754   if (pspec)
755     {
756       CellAttribute *cell_attribute = g_slice_new (CellAttribute);
757
758       cell_attribute->attribute = pspec->name;
759       cell_attribute->column    = column;
760
761       return cell_attribute;
762     }
763
764   return NULL;
765 }
766
767 static void
768 cell_attribute_free (CellAttribute *attribute)
769 {
770   g_slice_free (CellAttribute, attribute);
771 }
772
773 /* GCompareFunc for g_slist_find_custom() */
774 static gint
775 cell_attribute_find (CellAttribute *cell_attribute,
776                      const gchar   *attribute)
777 {
778   return g_strcmp0 (cell_attribute->attribute, attribute);
779 }
780
781 /*************************************************************
782  *                      GObjectClass                         *
783  *************************************************************/
784 static void
785 gtk_cell_area_finalize (GObject *object)
786 {
787   GtkCellArea        *area   = GTK_CELL_AREA (object);
788   GtkCellAreaPrivate *priv   = area->priv;
789
790   /* All cell renderers should already be removed at this point,
791    * just kill our (empty) hash tables here. 
792    */
793   g_hash_table_destroy (priv->cell_info);
794   g_hash_table_destroy (priv->focus_siblings);
795
796   g_free (priv->current_path);
797
798   G_OBJECT_CLASS (gtk_cell_area_parent_class)->finalize (object);
799 }
800
801
802 static void
803 gtk_cell_area_dispose (GObject *object)
804 {
805   /* This removes every cell renderer that may be added to the GtkCellArea,
806    * subclasses should be breaking references to the GtkCellRenderers 
807    * at this point.
808    */
809   gtk_cell_layout_clear (GTK_CELL_LAYOUT (object));
810
811   /* Remove any ref to a focused/edited cell */
812   gtk_cell_area_set_focus_cell (GTK_CELL_AREA (object), NULL);
813   gtk_cell_area_set_edited_cell (GTK_CELL_AREA (object), NULL);
814   gtk_cell_area_set_edit_widget (GTK_CELL_AREA (object), NULL);
815
816   G_OBJECT_CLASS (gtk_cell_area_parent_class)->dispose (object);
817 }
818
819 static void
820 gtk_cell_area_set_property (GObject       *object,
821                             guint          prop_id,
822                             const GValue  *value,
823                             GParamSpec    *pspec)
824 {
825   GtkCellArea *area = GTK_CELL_AREA (object);
826
827   switch (prop_id)
828     {
829     case PROP_FOCUS_CELL:
830       gtk_cell_area_set_focus_cell (area, (GtkCellRenderer *)g_value_get_object (value));
831       break;
832     default:
833       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
834       break;
835     }
836 }
837
838 static void
839 gtk_cell_area_get_property (GObject     *object,
840                             guint        prop_id,
841                             GValue      *value,
842                             GParamSpec  *pspec)
843 {
844   GtkCellArea        *area = GTK_CELL_AREA (object);
845   GtkCellAreaPrivate *priv = area->priv;
846
847   switch (prop_id)
848     {
849     case PROP_FOCUS_CELL:
850       g_value_set_object (value, priv->focus_cell);
851       break;
852     case PROP_EDITED_CELL:
853       g_value_set_object (value, priv->edited_cell);
854       break;
855     case PROP_EDIT_WIDGET:
856       g_value_set_object (value, priv->edit_widget);
857       break;
858     default:
859       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
860       break;
861     }
862 }
863
864 /*************************************************************
865  *                    GtkCellAreaClass                       *
866  *************************************************************/
867 static gint
868 gtk_cell_area_real_event (GtkCellArea          *area,
869                           GtkCellAreaContext   *context,
870                           GtkWidget            *widget,
871                           GdkEvent             *event,
872                           const GdkRectangle   *cell_area,
873                           GtkCellRendererState  flags)
874 {
875   GtkCellAreaPrivate *priv = area->priv;
876
877   if (event->type == GDK_KEY_PRESS && (flags & GTK_CELL_RENDERER_FOCUSED) != 0)
878     {
879       GdkEventKey *key_event = (GdkEventKey *)event;
880
881       /* Cancel any edits in progress */
882       if (priv->edited_cell && (key_event->keyval == GDK_KEY_Escape))
883         {
884           gtk_cell_area_stop_editing (area, TRUE);
885           return TRUE;
886         }
887     }
888
889   return FALSE;
890 }
891
892 static void
893 apply_cell_attributes (GtkCellRenderer *renderer,
894                        CellInfo        *info,
895                        AttributeData   *data)
896 {
897   CellAttribute *attribute;
898   GSList        *list;
899   GValue         value = { 0, };
900   gboolean       is_expander;
901   gboolean       is_expanded;
902
903   g_object_freeze_notify (G_OBJECT (renderer));
904
905   /* Whether a row expands or is presently expanded can only be 
906    * provided by the view (as these states can vary across views
907    * accessing the same model).
908    */
909   g_object_get (renderer, "is-expander", &is_expander, NULL);
910   if (is_expander != data->is_expander)
911     g_object_set (renderer, "is-expander", data->is_expander, NULL);
912   
913   g_object_get (renderer, "is-expanded", &is_expanded, NULL);
914   if (is_expanded != data->is_expanded)
915     g_object_set (renderer, "is-expanded", data->is_expanded, NULL);
916
917   /* Apply the attributes directly to the renderer */
918   for (list = info->attributes; list; list = list->next)
919     {
920       attribute = list->data;
921
922       gtk_tree_model_get_value (data->model, data->iter, attribute->column, &value);
923       g_object_set_property (G_OBJECT (renderer), attribute->attribute, &value);
924       g_value_unset (&value);
925     }
926
927   /* Call any GtkCellLayoutDataFunc that may have been set by the user
928    */
929   if (info->func)
930     info->func (GTK_CELL_LAYOUT (data->area), renderer,
931                 data->model, data->iter, info->data);
932
933   g_object_thaw_notify (G_OBJECT (renderer));
934 }
935
936 static void
937 gtk_cell_area_real_apply_attributes (GtkCellArea           *area,
938                                      GtkTreeModel          *tree_model,
939                                      GtkTreeIter           *iter,
940                                      gboolean               is_expander,
941                                      gboolean               is_expanded)
942 {
943
944   GtkCellAreaPrivate *priv;
945   AttributeData       data;
946   GtkTreePath        *path;
947
948   priv = area->priv;
949
950   /* Feed in data needed to apply to every renderer */
951   data.area        = area;
952   data.model       = tree_model;
953   data.iter        = iter;
954   data.is_expander = is_expander;
955   data.is_expanded = is_expanded;
956
957   /* Go over any cells that have attributes or custom GtkCellLayoutDataFuncs and
958    * apply the data from the treemodel */
959   g_hash_table_foreach (priv->cell_info, (GHFunc)apply_cell_attributes, &data);
960
961   /* Update the currently applied path */
962   g_free (priv->current_path);
963   path               = gtk_tree_model_get_path (tree_model, iter);
964   priv->current_path = gtk_tree_path_to_string (path);
965   gtk_tree_path_free (path);
966 }
967
968 static void
969 gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea        *area,
970                                                    GtkCellAreaContext *context,
971                                                    GtkWidget          *widget,
972                                                    gint                width,
973                                                    gint               *minimum_height,
974                                                    gint               *natural_height)
975 {
976   /* If the area doesnt do height-for-width, fallback on base preferred height */
977   GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_height, natural_height);
978 }
979
980 static void
981 gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea        *area,
982                                                    GtkCellAreaContext *context,
983                                                    GtkWidget          *widget,
984                                                    gint                height,
985                                                    gint               *minimum_width,
986                                                    gint               *natural_width)
987 {
988   /* If the area doesnt do width-for-height, fallback on base preferred width */
989   GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_width, natural_width);
990 }
991
992 static void
993 get_can_focus (GtkCellRenderer *renderer,
994                gboolean        *can_focus)
995 {
996
997   if (gtk_cell_renderer_can_focus (renderer))
998     *can_focus = TRUE;
999 }
1000
1001 static gboolean
1002 gtk_cell_area_real_can_focus (GtkCellArea *area)
1003 {
1004   gboolean can_focus = FALSE;
1005
1006   /* Checks if any renderer can focus for the currently applied
1007    * attributes.
1008    *
1009    * Subclasses can override this in the case that they are also
1010    * rendering widgets as well as renderers.
1011    */
1012   gtk_cell_area_forall (area, (GtkCellCallback)get_can_focus, &can_focus);
1013
1014   return can_focus;
1015 }
1016
1017 static gboolean
1018 gtk_cell_area_real_activate (GtkCellArea         *area,
1019                              GtkCellAreaContext  *context,
1020                              GtkWidget           *widget,
1021                              const GdkRectangle  *cell_area,
1022                              GtkCellRendererState flags)
1023 {
1024   GtkCellAreaPrivate *priv = area->priv;
1025   GdkRectangle        background_area;
1026
1027   if (priv->focus_cell)
1028     {
1029       /* Get the allocation of the focused cell.
1030        */
1031       gtk_cell_area_get_cell_allocation (area, context, widget, priv->focus_cell,
1032                                          cell_area, &background_area);
1033       
1034       /* Activate or Edit the currently focused cell 
1035        *
1036        * Currently just not sending an event, renderers afaics dont use
1037        * the event argument anyway, worst case is we can synthesize one.
1038        */
1039       if (gtk_cell_area_activate_cell (area, widget, priv->focus_cell, NULL,
1040                                        &background_area, flags))
1041         return TRUE;
1042     }
1043
1044   return FALSE;
1045 }
1046
1047 /*************************************************************
1048  *                   GtkCellLayoutIface                      *
1049  *************************************************************/
1050 static void
1051 gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface)
1052 {
1053   iface->pack_start         = gtk_cell_area_pack_default;
1054   iface->pack_end           = gtk_cell_area_pack_default;
1055   iface->clear              = gtk_cell_area_clear;
1056   iface->add_attribute      = gtk_cell_area_add_attribute;
1057   iface->set_cell_data_func = gtk_cell_area_set_cell_data_func;
1058   iface->clear_attributes   = gtk_cell_area_clear_attributes;
1059   iface->reorder            = gtk_cell_area_reorder;
1060   iface->get_cells          = gtk_cell_area_get_cells;
1061 }
1062
1063 static void
1064 gtk_cell_area_pack_default (GtkCellLayout         *cell_layout,
1065                             GtkCellRenderer       *renderer,
1066                             gboolean               expand)
1067 {
1068   gtk_cell_area_add (GTK_CELL_AREA (cell_layout), renderer);
1069 }
1070
1071 static void
1072 gtk_cell_area_clear (GtkCellLayout *cell_layout)
1073 {
1074   GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1075   GList *l, *cells  =
1076     gtk_cell_layout_get_cells (cell_layout);
1077
1078   for (l = cells; l; l = l->next)
1079     {
1080       GtkCellRenderer *renderer = l->data;
1081       gtk_cell_area_remove (area, renderer);
1082     }
1083
1084   g_list_free (cells);
1085 }
1086
1087 static void
1088 gtk_cell_area_add_attribute (GtkCellLayout         *cell_layout,
1089                              GtkCellRenderer       *renderer,
1090                              const gchar           *attribute,
1091                              gint                   column)
1092 {
1093   gtk_cell_area_attribute_connect (GTK_CELL_AREA (cell_layout),
1094                                    renderer, attribute, column);
1095 }
1096
1097 static void
1098 gtk_cell_area_set_cell_data_func (GtkCellLayout         *cell_layout,
1099                                   GtkCellRenderer       *renderer,
1100                                   GtkCellLayoutDataFunc  func,
1101                                   gpointer               func_data,
1102                                   GDestroyNotify         destroy)
1103 {
1104   GtkCellArea        *area   = GTK_CELL_AREA (cell_layout);
1105   GtkCellAreaPrivate *priv   = area->priv;
1106   CellInfo           *info;
1107
1108   info = g_hash_table_lookup (priv->cell_info, renderer);
1109
1110   if (info)
1111     {
1112       if (info->destroy && info->data)
1113         info->destroy (info->data);
1114
1115       if (func)
1116         {
1117           info->func    = func;
1118           info->data    = func_data;
1119           info->destroy = destroy;
1120         }
1121       else
1122         {
1123           info->func    = NULL;
1124           info->data    = NULL;
1125           info->destroy = NULL;
1126         }
1127     }
1128   else
1129     {
1130       info = cell_info_new (func, func_data, destroy);
1131
1132       g_hash_table_insert (priv->cell_info, renderer, info);
1133     }
1134 }
1135
1136 static void
1137 gtk_cell_area_clear_attributes (GtkCellLayout         *cell_layout,
1138                                 GtkCellRenderer       *renderer)
1139 {
1140   GtkCellArea        *area = GTK_CELL_AREA (cell_layout);
1141   GtkCellAreaPrivate *priv = area->priv;
1142   CellInfo           *info;
1143
1144   info = g_hash_table_lookup (priv->cell_info, renderer);
1145
1146   if (info)
1147     {
1148       g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
1149       g_slist_free (info->attributes);
1150
1151       info->attributes = NULL;
1152     }
1153 }
1154
1155 static void 
1156 gtk_cell_area_reorder (GtkCellLayout   *cell_layout,
1157                        GtkCellRenderer *cell,
1158                        gint             position)
1159 {
1160   g_warning ("GtkCellLayout::reorder not implemented for `%s'", 
1161              g_type_name (G_TYPE_FROM_INSTANCE (cell_layout)));
1162 }
1163
1164 static void
1165 accum_cells (GtkCellRenderer *renderer,
1166              GList          **accum)
1167 {
1168   *accum = g_list_prepend (*accum, renderer);
1169 }
1170
1171 static GList *
1172 gtk_cell_area_get_cells (GtkCellLayout *cell_layout)
1173 {
1174   GList *cells = NULL;
1175
1176   gtk_cell_area_forall (GTK_CELL_AREA (cell_layout), 
1177                         (GtkCellCallback)accum_cells,
1178                         &cells);
1179
1180   return g_list_reverse (cells);
1181 }
1182
1183
1184 /*************************************************************
1185  *                            API                            *
1186  *************************************************************/
1187
1188 /**
1189  * gtk_cell_area_add:
1190  * @area: a #GtkCellArea
1191  * @renderer: the #GtkCellRenderer to add to @area
1192  *
1193  * Adds @renderer to @area with the default child cell properties.
1194  */
1195 void
1196 gtk_cell_area_add (GtkCellArea        *area,
1197                    GtkCellRenderer    *renderer)
1198 {
1199   GtkCellAreaClass *class;
1200
1201   g_return_if_fail (GTK_IS_CELL_AREA (area));
1202   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1203
1204   class = GTK_CELL_AREA_GET_CLASS (area);
1205
1206   if (class->add)
1207     class->add (area, renderer);
1208   else
1209     g_warning ("GtkCellAreaClass::add not implemented for `%s'", 
1210                g_type_name (G_TYPE_FROM_INSTANCE (area)));
1211 }
1212
1213 /**
1214  * gtk_cell_area_remove:
1215  * @area: a #GtkCellArea
1216  * @renderer: the #GtkCellRenderer to add to @area
1217  *
1218  * Removes @renderer from @area.
1219  */
1220 void
1221 gtk_cell_area_remove (GtkCellArea        *area,
1222                       GtkCellRenderer    *renderer)
1223 {
1224   GtkCellAreaClass   *class;
1225   GtkCellAreaPrivate *priv;
1226   GList              *renderers, *l;
1227
1228   g_return_if_fail (GTK_IS_CELL_AREA (area));
1229   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1230
1231   class = GTK_CELL_AREA_GET_CLASS (area);
1232   priv  = area->priv;
1233
1234   /* Remove any custom attributes and custom cell data func here first */
1235   g_hash_table_remove (priv->cell_info, renderer);
1236
1237   /* Remove focus siblings of this renderer */
1238   g_hash_table_remove (priv->focus_siblings, renderer);
1239
1240   /* Remove this renderer from any focus renderer's sibling list */ 
1241   renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1242
1243   for (l = renderers; l; l = l->next)
1244     {
1245       GtkCellRenderer *focus_renderer = l->data;
1246
1247       if (gtk_cell_area_is_focus_sibling (area, focus_renderer, renderer))
1248         {
1249           gtk_cell_area_remove_focus_sibling (area, focus_renderer, renderer);
1250           break;
1251         }
1252     }
1253
1254   g_list_free (renderers);
1255
1256   if (class->remove)
1257     class->remove (area, renderer);
1258   else
1259     g_warning ("GtkCellAreaClass::remove not implemented for `%s'", 
1260                g_type_name (G_TYPE_FROM_INSTANCE (area)));
1261 }
1262
1263 static void
1264 get_has_renderer (GtkCellRenderer  *renderer,
1265                   HasRendererCheck *check)
1266 {
1267   if (renderer == check->renderer)
1268     check->has_renderer = TRUE;
1269 }
1270
1271 /**
1272  * gtk_cell_area_has_renderer:
1273  * @area: a #GtkCellArea
1274  * @renderer: the #GtkCellRenderer to check
1275  *
1276  * Checks if @area contains @renderer.
1277  *
1278  * Returns: %TRUE if @renderer is in the @area.
1279  */
1280 gboolean
1281 gtk_cell_area_has_renderer (GtkCellArea     *area,
1282                             GtkCellRenderer *renderer)
1283 {
1284   HasRendererCheck check = { renderer, FALSE };
1285
1286   g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
1287   g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
1288
1289   gtk_cell_area_forall (area, (GtkCellCallback)get_has_renderer, &check);
1290
1291   return check.has_renderer;
1292 }
1293
1294 /**
1295  * gtk_cell_area_forall:
1296  * @area: a #GtkCellArea
1297  * @callback: the #GtkCellCallback to call
1298  * @callback_data: user provided data pointer
1299  *
1300  * Calls @callback for every #GtkCellRenderer in @area.
1301  */
1302 void
1303 gtk_cell_area_forall (GtkCellArea        *area,
1304                       GtkCellCallback     callback,
1305                       gpointer            callback_data)
1306 {
1307   GtkCellAreaClass *class;
1308
1309   g_return_if_fail (GTK_IS_CELL_AREA (area));
1310   g_return_if_fail (callback != NULL);
1311
1312   class = GTK_CELL_AREA_GET_CLASS (area);
1313
1314   if (class->forall)
1315     class->forall (area, callback, callback_data);
1316   else
1317     g_warning ("GtkCellAreaClass::forall not implemented for `%s'", 
1318                g_type_name (G_TYPE_FROM_INSTANCE (area)));
1319 }
1320
1321 /**
1322  * gtk_cell_area_get_cell_allocation:
1323  * @area: a #GtkCellArea
1324  * @context: the #GtkCellAreaContext used to hold sizes for @area.
1325  * @widget: the #GtkWidget that @area is rendering on
1326  * @renderer: the #GtkCellRenderer to get the allocation for
1327  * @cell_area: the whole allocated area for @area in @widget
1328  *             for this row
1329  * @allocation: where to store the allocation for @renderer
1330  *
1331  * Derives the allocation of @renderer inside @area if @area
1332  * were to be renderered in @cell_area.
1333  */
1334 void
1335 gtk_cell_area_get_cell_allocation (GtkCellArea          *area,
1336                                    GtkCellAreaContext   *context,       
1337                                    GtkWidget            *widget,
1338                                    GtkCellRenderer      *renderer,
1339                                    const GdkRectangle   *cell_area,
1340                                    GdkRectangle         *allocation)
1341 {
1342   GtkCellAreaClass *class;
1343
1344   g_return_if_fail (GTK_IS_CELL_AREA (area));
1345   g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1346   g_return_if_fail (GTK_IS_WIDGET (widget));
1347   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1348   g_return_if_fail (cell_area != NULL);
1349   g_return_if_fail (allocation != NULL);
1350
1351   class = GTK_CELL_AREA_GET_CLASS (area);
1352
1353   if (class->get_cell_allocation)
1354     class->get_cell_allocation (area, context, widget, renderer, cell_area, allocation);
1355   else
1356     g_warning ("GtkCellAreaClass::get_cell_allocation not implemented for `%s'", 
1357                g_type_name (G_TYPE_FROM_INSTANCE (area)));
1358 }
1359
1360 /**
1361  * gtk_cell_area_event:
1362  * @area: a #GtkCellArea
1363  * @context: the #GtkCellAreaContext for this row of data.
1364  * @widget: the #GtkWidget that @area is rendering to
1365  * @event: the #GdkEvent to handle
1366  * @cell_area: the @widget relative coordinates for @area
1367  * @flags: the #GtkCellRendererState for @area in this row.
1368  *
1369  * Delegates event handling to a #GtkCellArea.
1370  *
1371  * Returns: %TRUE if the event was handled by @area.
1372  */
1373 gint
1374 gtk_cell_area_event (GtkCellArea          *area,
1375                      GtkCellAreaContext   *context,
1376                      GtkWidget            *widget,
1377                      GdkEvent             *event,
1378                      const GdkRectangle   *cell_area,
1379                      GtkCellRendererState  flags)
1380 {
1381   GtkCellAreaClass *class;
1382
1383   g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1384   g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), 0);
1385   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
1386   g_return_val_if_fail (event != NULL, 0);
1387   g_return_val_if_fail (cell_area != NULL, 0);
1388
1389   class = GTK_CELL_AREA_GET_CLASS (area);
1390
1391   if (class->event)
1392     return class->event (area, context, widget, event, cell_area, flags);
1393
1394   g_warning ("GtkCellAreaClass::event not implemented for `%s'", 
1395              g_type_name (G_TYPE_FROM_INSTANCE (area)));
1396   return 0;
1397 }
1398
1399 /**
1400  * gtk_cell_area_render:
1401  * @area: a #GtkCellArea
1402  * @context: the #GtkCellAreaContext for this row of data.
1403  * @widget: the #GtkWidget that @area is rendering to
1404  * @cr: the #cairo_t to render with
1405  * @background_area: the @widget relative coordinates for @area's background
1406  * @cell_area: the @widget relative coordinates for @area
1407  * @flags: the #GtkCellRendererState for @area in this row.
1408  * @paint_focus: whether @area should paint focus on focused cells for focused rows or not.
1409  *
1410  * Renders @area's cells according to @area's layout onto @widget at
1411  * the given coordinates.
1412  */
1413 void
1414 gtk_cell_area_render (GtkCellArea          *area,
1415                       GtkCellAreaContext   *context,
1416                       GtkWidget            *widget,
1417                       cairo_t              *cr,
1418                       const GdkRectangle   *background_area,
1419                       const GdkRectangle   *cell_area,
1420                       GtkCellRendererState  flags,
1421                       gboolean              paint_focus)
1422 {
1423   GtkCellAreaClass *class;
1424
1425   g_return_if_fail (GTK_IS_CELL_AREA (area));
1426   g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1427   g_return_if_fail (GTK_IS_WIDGET (widget));
1428   g_return_if_fail (cr != NULL);
1429   g_return_if_fail (background_area != NULL);
1430   g_return_if_fail (cell_area != NULL);
1431
1432   class = GTK_CELL_AREA_GET_CLASS (area);
1433
1434   if (class->render)
1435     class->render (area, context, widget, cr, background_area, cell_area, flags, paint_focus);
1436   else
1437     g_warning ("GtkCellAreaClass::render not implemented for `%s'", 
1438                g_type_name (G_TYPE_FROM_INSTANCE (area)));
1439 }
1440
1441 /**
1442  * gtk_cell_area_set_style_detail:
1443  * @area: a #GtkCellArea
1444  * @detail: the #GtkStyle detail string to set
1445  *
1446  * Sets the detail string used in any gtk_paint_*() functions
1447  * used by @area.
1448  */
1449 void
1450 gtk_cell_area_set_style_detail (GtkCellArea *area,
1451                                 const gchar *detail)
1452 {
1453   GtkCellAreaPrivate *priv;
1454
1455   g_return_if_fail (GTK_IS_CELL_AREA (area));
1456
1457   priv = area->priv;
1458
1459   if (g_strcmp0 (priv->style_detail, detail) != 0)
1460     {
1461       g_free (priv->style_detail);
1462       priv->style_detail = g_strdup (detail);
1463     }
1464 }
1465
1466 /**
1467  * gtk_cell_area_get_style_detail:
1468  * @area: a #GtkCellArea
1469  *
1470  * Gets the detail string used in any gtk_paint_*() functions
1471  * used by @area.
1472  *
1473  * Returns: the detail string.
1474  */
1475 G_CONST_RETURN gchar *
1476 gtk_cell_area_get_style_detail (GtkCellArea *area)
1477 {
1478   GtkCellAreaPrivate *priv;
1479
1480   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1481
1482   priv = area->priv;
1483
1484   return priv->style_detail;
1485 }
1486
1487 /*************************************************************
1488  *                      API: Geometry                        *
1489  *************************************************************/
1490 /**
1491  * gtk_cell_area_create_context:
1492  * @area: a #GtkCellArea
1493  *
1494  * Creates a #GtkCellAreaContext to be used with @area for
1495  * all purposes. #GtkCellAreaContext stores geometry information
1496  * for rows for which it was operated on, it is important to use
1497  * the same context for the same row of data at all times (i.e.
1498  * one should render and handle events with the same #GtkCellAreaContext
1499  * which was used to request the size of those rows of data).
1500  *
1501  * Returns: a newly created #GtkCellAreaContext which can be used with @area.
1502  */
1503 GtkCellAreaContext *
1504 gtk_cell_area_create_context (GtkCellArea *area)
1505 {
1506   GtkCellAreaClass *class;
1507
1508   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1509
1510   class = GTK_CELL_AREA_GET_CLASS (area);
1511
1512   if (class->create_context)
1513     return class->create_context (area);
1514
1515   g_warning ("GtkCellAreaClass::create_context not implemented for `%s'", 
1516              g_type_name (G_TYPE_FROM_INSTANCE (area)));
1517   
1518   return NULL;
1519 }
1520
1521
1522 /**
1523  * gtk_cell_area_get_request_mode:
1524  * @area: a #GtkCellArea
1525  *
1526  * Gets whether the area prefers a height-for-width layout
1527  * or a width-for-height layout.
1528  *
1529  * Returns: The #GtkSizeRequestMode preferred by @area.
1530  *
1531  * Since: 3.0
1532  */
1533 GtkSizeRequestMode 
1534 gtk_cell_area_get_request_mode (GtkCellArea *area)
1535 {
1536   GtkCellAreaClass *class;
1537
1538   g_return_val_if_fail (GTK_IS_CELL_AREA (area), 
1539                         GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
1540
1541   class = GTK_CELL_AREA_GET_CLASS (area);
1542
1543   if (class->get_request_mode)
1544     return class->get_request_mode (area);
1545
1546   g_warning ("GtkCellAreaClass::get_request_mode not implemented for `%s'", 
1547              g_type_name (G_TYPE_FROM_INSTANCE (area)));
1548   
1549   return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1550 }
1551
1552 /**
1553  * gtk_cell_area_get_preferred_width:
1554  * @area: a #GtkCellArea
1555  * @context: the #GtkCellAreaContext to perform this request with
1556  * @widget: the #GtkWidget where @area will be rendering
1557  * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1558  * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1559  *
1560  * Retrieves a cell area's initial minimum and natural width.
1561  *
1562  * @area will store some geometrical information in @context along the way,
1563  * when requesting sizes over an arbitrary number of rows, its not important
1564  * to check the @minimum_width and @natural_width of this call but rather to
1565  * consult gtk_cell_area_context_get_preferred_width() after a series of
1566  * requests.
1567  *
1568  *
1569  * Since: 3.0
1570  */
1571 void
1572 gtk_cell_area_get_preferred_width (GtkCellArea        *area,
1573                                    GtkCellAreaContext *context,
1574                                    GtkWidget          *widget,
1575                                    gint               *minimum_width,
1576                                    gint               *natural_width)
1577 {
1578   GtkCellAreaClass *class;
1579
1580   g_return_if_fail (GTK_IS_CELL_AREA (area));
1581   g_return_if_fail (GTK_IS_WIDGET (widget));
1582
1583   class = GTK_CELL_AREA_GET_CLASS (area);
1584
1585   if (class->get_preferred_width)
1586     class->get_preferred_width (area, context, widget, minimum_width, natural_width);
1587   else
1588     g_warning ("GtkCellAreaClass::get_preferred_width not implemented for `%s'", 
1589                g_type_name (G_TYPE_FROM_INSTANCE (area)));
1590 }
1591
1592 /**
1593  * gtk_cell_area_get_preferred_height_for_width:
1594  * @area: a #GtkCellArea
1595  * @context: the #GtkCellAreaContext which has already been requested for widths.
1596  * @widget: the #GtkWidget where @area will be rendering
1597  * @width: the width for which to check the height of this area
1598  * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1599  * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1600  *
1601  * Retrieves a cell area's minimum and natural height if it would be given
1602  * the specified @width.
1603  *
1604  * @area stores some geometrical information in @context along the way
1605  * while calling gtk_cell_area_get_preferred_width(), it's important to
1606  * perform a series of gtk_cell_area_get_preferred_width() requests with
1607  * @context first and then call gtk_cell_area_get_preferred_height_for_width()
1608  * on each cell area individually to get the height for width of each
1609  * fully requested row.
1610  *
1611  * If at some point, the width of a single row changes, it should be
1612  * requested with gtk_cell_area_get_preferred_width() again and then
1613  * the full width of the requested rows checked again with
1614  * gtk_cell_area_context_get_preferred_width().
1615  *
1616  * Since: 3.0
1617  */
1618 void
1619 gtk_cell_area_get_preferred_height_for_width (GtkCellArea        *area,
1620                                               GtkCellAreaContext *context,
1621                                               GtkWidget          *widget,
1622                                               gint                width,
1623                                               gint               *minimum_height,
1624                                               gint               *natural_height)
1625 {
1626   GtkCellAreaClass *class;
1627
1628   g_return_if_fail (GTK_IS_CELL_AREA (area));
1629   g_return_if_fail (GTK_IS_WIDGET (widget));
1630
1631   class = GTK_CELL_AREA_GET_CLASS (area);
1632   class->get_preferred_height_for_width (area, context, widget, width, minimum_height, natural_height);
1633 }
1634
1635
1636 /**
1637  * gtk_cell_area_get_preferred_height:
1638  * @area: a #GtkCellArea
1639  * @context: the #GtkCellAreaContext to perform this request with
1640  * @widget: the #GtkWidget where @area will be rendering
1641  * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1642  * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1643  *
1644  * Retrieves a cell area's initial minimum and natural height.
1645  *
1646  * @area will store some geometrical information in @context along the way,
1647  * when requesting sizes over an arbitrary number of rows, its not important
1648  * to check the @minimum_height and @natural_height of this call but rather to
1649  * consult gtk_cell_area_context_get_preferred_height() after a series of
1650  * requests.
1651  *
1652  * Since: 3.0
1653  */
1654 void
1655 gtk_cell_area_get_preferred_height (GtkCellArea        *area,
1656                                     GtkCellAreaContext *context,
1657                                     GtkWidget          *widget,
1658                                     gint               *minimum_height,
1659                                     gint               *natural_height)
1660 {
1661   GtkCellAreaClass *class;
1662
1663   g_return_if_fail (GTK_IS_CELL_AREA (area));
1664   g_return_if_fail (GTK_IS_WIDGET (widget));
1665
1666   class = GTK_CELL_AREA_GET_CLASS (area);
1667
1668   if (class->get_preferred_height)
1669     class->get_preferred_height (area, context, widget, minimum_height, natural_height);
1670   else
1671     g_warning ("GtkCellAreaClass::get_preferred_height not implemented for `%s'", 
1672                g_type_name (G_TYPE_FROM_INSTANCE (area)));
1673 }
1674
1675 /**
1676  * gtk_cell_area_get_preferred_width_for_height:
1677  * @area: a #GtkCellArea
1678  * @context: the #GtkCellAreaContext which has already been requested for widths.
1679  * @widget: the #GtkWidget where @area will be rendering
1680  * @height: the height for which to check the width of this area
1681  * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1682  * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1683  *
1684  * Retrieves a cell area's minimum and natural width if it would be given
1685  * the specified @height.
1686  *
1687  * @area stores some geometrical information in @context along the way
1688  * while calling gtk_cell_area_get_preferred_height(), it's important to
1689  * perform a series of gtk_cell_area_get_preferred_height() requests with
1690  * @context first and then call gtk_cell_area_get_preferred_width_for_height()
1691  * on each cell area individually to get the height for width of each
1692  * fully requested row.
1693  *
1694  * If at some point, the height of a single row changes, it should be
1695  * requested with gtk_cell_area_get_preferred_height() again and then
1696  * the full height of the requested rows checked again with
1697  * gtk_cell_area_context_get_preferred_height().
1698  *
1699  * Since: 3.0
1700  */
1701 void
1702 gtk_cell_area_get_preferred_width_for_height (GtkCellArea        *area,
1703                                               GtkCellAreaContext *context,
1704                                               GtkWidget          *widget,
1705                                               gint                height,
1706                                               gint               *minimum_width,
1707                                               gint               *natural_width)
1708 {
1709   GtkCellAreaClass *class;
1710
1711   g_return_if_fail (GTK_IS_CELL_AREA (area));
1712   g_return_if_fail (GTK_IS_WIDGET (widget));
1713
1714   class = GTK_CELL_AREA_GET_CLASS (area);
1715   class->get_preferred_width_for_height (area, context, widget, height, minimum_width, natural_width);
1716 }
1717
1718 /*************************************************************
1719  *                      API: Attributes                      *
1720  *************************************************************/
1721
1722 /**
1723  * gtk_cell_area_attribute_connect:
1724  * @area: a #GtkCellArea
1725  * @renderer: the #GtkCellRenderer to connect an attribute for
1726  * @attribute: the attribute name
1727  * @column: the #GtkTreeModel column to fetch attribute values from
1728  *
1729  * Connects an @attribute to apply values from @column for the
1730  * #GtkTreeModel in use.
1731  */
1732 void
1733 gtk_cell_area_attribute_connect (GtkCellArea        *area,
1734                                  GtkCellRenderer    *renderer,
1735                                  const gchar        *attribute,
1736                                  gint                column)
1737
1738   GtkCellAreaPrivate *priv;
1739   CellInfo           *info;
1740   CellAttribute      *cell_attribute;
1741
1742   g_return_if_fail (GTK_IS_CELL_AREA (area));
1743   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1744   g_return_if_fail (attribute != NULL);
1745   g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1746
1747   priv = area->priv;
1748   info = g_hash_table_lookup (priv->cell_info, renderer);
1749
1750   if (!info)
1751     {
1752       info = cell_info_new (NULL, NULL, NULL);
1753
1754       g_hash_table_insert (priv->cell_info, renderer, info);
1755     }
1756   else
1757     {
1758       GSList *node;
1759
1760       /* Check we are not adding the same attribute twice */
1761       if ((node = g_slist_find_custom (info->attributes, attribute,
1762                                        (GCompareFunc)cell_attribute_find)) != NULL)
1763         {
1764           cell_attribute = node->data;
1765
1766           g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1767                      "since `%s' is already attributed to column %d", 
1768                      attribute,
1769                      g_type_name (G_TYPE_FROM_INSTANCE (area)),
1770                      attribute, cell_attribute->column);
1771           return;
1772         }
1773     }
1774
1775   cell_attribute = cell_attribute_new (renderer, attribute, column);
1776
1777   if (!cell_attribute)
1778     {
1779       g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1780                  "since attribute does not exist", 
1781                  attribute,
1782                  g_type_name (G_TYPE_FROM_INSTANCE (area)));
1783       return;
1784     }
1785
1786   info->attributes = g_slist_prepend (info->attributes, cell_attribute);
1787 }
1788
1789 /**
1790  * gtk_cell_area_attribute_disconnect:
1791  * @area: a #GtkCellArea
1792  * @renderer: the #GtkCellRenderer to disconnect an attribute for
1793  * @attribute: the attribute name
1794  *
1795  * Disconnects @attribute for the @renderer in @area so that
1796  * attribute will no longer be updated with values from the
1797  * model.
1798  */
1799 void 
1800 gtk_cell_area_attribute_disconnect (GtkCellArea        *area,
1801                                     GtkCellRenderer    *renderer,
1802                                     const gchar        *attribute)
1803 {
1804   GtkCellAreaPrivate *priv;
1805   CellInfo           *info;
1806   CellAttribute      *cell_attribute;
1807   GSList             *node;
1808
1809   g_return_if_fail (GTK_IS_CELL_AREA (area));
1810   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1811   g_return_if_fail (attribute != NULL);
1812   g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1813
1814   priv = area->priv;
1815   info = g_hash_table_lookup (priv->cell_info, renderer);
1816
1817   if (info)
1818     {
1819       node = g_slist_find_custom (info->attributes, attribute,
1820                                   (GCompareFunc)cell_attribute_find);
1821       if (node)
1822         {
1823           cell_attribute = node->data;
1824
1825           cell_attribute_free (cell_attribute);
1826
1827           info->attributes = g_slist_delete_link (info->attributes, node);
1828         }
1829     }
1830 }
1831
1832 /**
1833  * gtk_cell_area_apply_attributes
1834  * @area: a #GtkCellArea
1835  * @tree_model: a #GtkTreeModel to pull values from
1836  * @iter: the #GtkTreeIter in @tree_model to apply values for
1837  * @is_expander: whether @iter has children
1838  * @is_expanded: whether @iter is expanded in the view and
1839  *               children are visible
1840  *
1841  * Applies any connected attributes to the renderers in 
1842  * @area by pulling the values from @tree_model.
1843  */
1844 void
1845 gtk_cell_area_apply_attributes (GtkCellArea  *area,
1846                                 GtkTreeModel *tree_model,
1847                                 GtkTreeIter  *iter,
1848                                 gboolean      is_expander,
1849                                 gboolean      is_expanded)
1850 {
1851   g_return_if_fail (GTK_IS_CELL_AREA (area));
1852   g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
1853   g_return_if_fail (iter != NULL);
1854
1855   g_signal_emit (area, cell_area_signals[SIGNAL_APPLY_ATTRIBUTES], 0, 
1856                  tree_model, iter, is_expander, is_expanded);
1857 }
1858
1859 /**
1860  * gtk_cell_area_get_current_path_string:
1861  * @area: a #GtkCellArea
1862  *
1863  * Gets the current #GtkTreePath string for the currently
1864  * applied #GtkTreeIter, this is implicitly updated when
1865  * gtk_cell_area_apply_attributes() is called and can be
1866  * used to interact with renderers from #GtkCellArea
1867  * subclasses.
1868  */
1869 const gchar *
1870 gtk_cell_area_get_current_path_string (GtkCellArea *area)
1871 {
1872   GtkCellAreaPrivate *priv;
1873
1874   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1875
1876   priv = area->priv;
1877
1878   return priv->current_path;
1879 }
1880
1881
1882 /*************************************************************
1883  *                    API: Cell Properties                   *
1884  *************************************************************/
1885 /**
1886  * gtk_cell_area_class_install_cell_property:
1887  * @aclass: a #GtkCellAreaClass
1888  * @property_id: the id for the property
1889  * @pspec: the #GParamSpec for the property
1890  *
1891  * Installs a cell property on a cell area class.
1892  */
1893 void
1894 gtk_cell_area_class_install_cell_property (GtkCellAreaClass   *aclass,
1895                                            guint               property_id,
1896                                            GParamSpec         *pspec)
1897 {
1898   g_return_if_fail (GTK_IS_CELL_AREA_CLASS (aclass));
1899   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1900   if (pspec->flags & G_PARAM_WRITABLE)
1901     g_return_if_fail (aclass->set_cell_property != NULL);
1902   if (pspec->flags & G_PARAM_READABLE)
1903     g_return_if_fail (aclass->get_cell_property != NULL);
1904   g_return_if_fail (property_id > 0);
1905   g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0);  /* paranoid */
1906   g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
1907
1908   if (g_param_spec_pool_lookup (cell_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (aclass), TRUE))
1909     {
1910       g_warning (G_STRLOC ": class `%s' already contains a cell property named `%s'",
1911                  G_OBJECT_CLASS_NAME (aclass), pspec->name);
1912       return;
1913     }
1914   g_param_spec_ref (pspec);
1915   g_param_spec_sink (pspec);
1916   PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
1917   g_param_spec_pool_insert (cell_property_pool, pspec, G_OBJECT_CLASS_TYPE (aclass));
1918 }
1919
1920 /**
1921  * gtk_cell_area_class_find_cell_property:
1922  * @aclass: a #GtkCellAreaClass
1923  * @property_name: the name of the child property to find
1924  * @returns: (allow-none): the #GParamSpec of the child property or %NULL if @aclass has no
1925  *   child property with that name.
1926  *
1927  * Finds a cell property of a cell area class by name.
1928  */
1929 GParamSpec*
1930 gtk_cell_area_class_find_cell_property (GtkCellAreaClass   *aclass,
1931                                         const gchar        *property_name)
1932 {
1933   g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
1934   g_return_val_if_fail (property_name != NULL, NULL);
1935
1936   return g_param_spec_pool_lookup (cell_property_pool,
1937                                    property_name,
1938                                    G_OBJECT_CLASS_TYPE (aclass),
1939                                    TRUE);
1940 }
1941
1942 /**
1943  * gtk_cell_area_class_list_cell_properties:
1944  * @aclass: a #GtkCellAreaClass
1945  * @n_properties: location to return the number of cell properties found
1946  * @returns: a newly allocated %NULL-terminated array of #GParamSpec*.
1947  *           The array must be freed with g_free().
1948  *
1949  * Returns all cell properties of a cell area class.
1950  */
1951 GParamSpec**
1952 gtk_cell_area_class_list_cell_properties (GtkCellAreaClass  *aclass,
1953                                           guint             *n_properties)
1954 {
1955   GParamSpec **pspecs;
1956   guint n;
1957
1958   g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
1959
1960   pspecs = g_param_spec_pool_list (cell_property_pool,
1961                                    G_OBJECT_CLASS_TYPE (aclass),
1962                                    &n);
1963   if (n_properties)
1964     *n_properties = n;
1965
1966   return pspecs;
1967 }
1968
1969 /**
1970  * gtk_cell_area_add_with_properties:
1971  * @area: a #GtkCellArea
1972  * @renderer: a #GtkCellRenderer to be placed inside @area
1973  * @first_prop_name: the name of the first cell property to set
1974  * @Varargs: a %NULL-terminated list of property names and values, starting
1975  *           with @first_prop_name
1976  *
1977  * Adds @renderer to @area, setting cell properties at the same time.
1978  * See gtk_cell_area_add() and gtk_cell_area_child_set() for more details.
1979  **/
1980 void
1981 gtk_cell_area_add_with_properties (GtkCellArea        *area,
1982                                    GtkCellRenderer    *renderer,
1983                                    const gchar        *first_prop_name,
1984                                    ...)
1985 {
1986   GtkCellAreaClass *class;
1987
1988   g_return_if_fail (GTK_IS_CELL_AREA (area));
1989   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1990
1991   class = GTK_CELL_AREA_GET_CLASS (area);
1992
1993   if (class->add)
1994     {
1995       va_list var_args;
1996
1997       class->add (area, renderer);
1998
1999       va_start (var_args, first_prop_name);
2000       gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2001       va_end (var_args);
2002     }
2003   else
2004     g_warning ("GtkCellAreaClass::add not implemented for `%s'", 
2005                g_type_name (G_TYPE_FROM_INSTANCE (area)));
2006 }
2007
2008 /**
2009  * gtk_cell_area_cell_set:
2010  * @area: a #GtkCellArea
2011  * @renderer: a #GtkCellRenderer which is a cell inside @area
2012  * @first_prop_name: the name of the first cell property to set
2013  * @Varargs: a %NULL-terminated list of property names and values, starting
2014  *           with @first_prop_name
2015  *
2016  * Sets one or more cell properties for @cell in @area.
2017  **/
2018 void
2019 gtk_cell_area_cell_set (GtkCellArea        *area,
2020                         GtkCellRenderer    *renderer,
2021                         const gchar        *first_prop_name,
2022                         ...)
2023 {
2024   va_list var_args;
2025
2026   g_return_if_fail (GTK_IS_CELL_AREA (area));
2027   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2028
2029   va_start (var_args, first_prop_name);
2030   gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2031   va_end (var_args);
2032 }
2033
2034 /**
2035  * gtk_cell_area_cell_get:
2036  * @area: a #GtkCellArea
2037  * @renderer: a #GtkCellRenderer which is inside @area
2038  * @first_prop_name: the name of the first cell property to get
2039  * @Varargs: return location for the first cell property, followed
2040  *     optionally by more name/return location pairs, followed by %NULL
2041  *
2042  * Gets the values of one or more cell properties for @renderer in @area.
2043  **/
2044 void
2045 gtk_cell_area_cell_get (GtkCellArea        *area,
2046                         GtkCellRenderer    *renderer,
2047                         const gchar        *first_prop_name,
2048                         ...)
2049 {
2050   va_list var_args;
2051
2052   g_return_if_fail (GTK_IS_CELL_AREA (area));
2053   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2054
2055   va_start (var_args, first_prop_name);
2056   gtk_cell_area_cell_get_valist (area, renderer, first_prop_name, var_args);
2057   va_end (var_args);
2058 }
2059
2060 static inline void
2061 area_get_cell_property (GtkCellArea     *area,
2062                         GtkCellRenderer *renderer,
2063                         GParamSpec      *pspec,
2064                         GValue          *value)
2065 {
2066   GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2067   
2068   class->get_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
2069 }
2070
2071 static inline void
2072 area_set_cell_property (GtkCellArea     *area,
2073                         GtkCellRenderer *renderer,
2074                         GParamSpec      *pspec,
2075                         const GValue    *value)
2076 {
2077   GValue tmp_value = { 0, };
2078   GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2079
2080   /* provide a copy to work from, convert (if necessary) and validate */
2081   g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2082   if (!g_value_transform (value, &tmp_value))
2083     g_warning ("unable to set cell property `%s' of type `%s' from value of type `%s'",
2084                pspec->name,
2085                g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2086                G_VALUE_TYPE_NAME (value));
2087   else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
2088     {
2089       gchar *contents = g_strdup_value_contents (value);
2090
2091       g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
2092                  contents,
2093                  G_VALUE_TYPE_NAME (value),
2094                  pspec->name,
2095                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
2096       g_free (contents);
2097     }
2098   else
2099     {
2100       class->set_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
2101     }
2102   g_value_unset (&tmp_value);
2103 }
2104
2105 /**
2106  * gtk_cell_area_cell_set_valist:
2107  * @area: a #GtkCellArea
2108  * @renderer: a #GtkCellRenderer which inside @area
2109  * @first_property_name: the name of the first cell property to set
2110  * @var_args: a %NULL-terminated list of property names and values, starting
2111  *           with @first_prop_name
2112  *
2113  * Sets one or more cell properties for @renderer in @area.
2114  **/
2115 void
2116 gtk_cell_area_cell_set_valist (GtkCellArea        *area,
2117                                GtkCellRenderer    *renderer,
2118                                const gchar        *first_property_name,
2119                                va_list             var_args)
2120 {
2121   const gchar *name;
2122
2123   g_return_if_fail (GTK_IS_CELL_AREA (area));
2124   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2125
2126   name = first_property_name;
2127   while (name)
2128     {
2129       GValue value = { 0, };
2130       gchar *error = NULL;
2131       GParamSpec *pspec = 
2132         g_param_spec_pool_lookup (cell_property_pool, name,
2133                                   G_OBJECT_TYPE (area), TRUE);
2134       if (!pspec)
2135         {
2136           g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2137                      G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2138           break;
2139         }
2140       if (!(pspec->flags & G_PARAM_WRITABLE))
2141         {
2142           g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2143                      G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2144           break;
2145         }
2146
2147       g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2148       G_VALUE_COLLECT (&value, var_args, 0, &error);
2149       if (error)
2150         {
2151           g_warning ("%s: %s", G_STRLOC, error);
2152           g_free (error);
2153
2154           /* we purposely leak the value here, it might not be
2155            * in a sane state if an error condition occoured
2156            */
2157           break;
2158         }
2159       area_set_cell_property (area, renderer, pspec, &value);
2160       g_value_unset (&value);
2161       name = va_arg (var_args, gchar*);
2162     }
2163 }
2164
2165 /**
2166  * gtk_cell_area_cell_get_valist:
2167  * @area: a #GtkCellArea
2168  * @renderer: a #GtkCellRenderer inside @area
2169  * @first_property_name: the name of the first property to get
2170  * @var_args: return location for the first property, followed
2171  *     optionally by more name/return location pairs, followed by %NULL
2172  *
2173  * Gets the values of one or more cell properties for @renderer in @area.
2174  **/
2175 void
2176 gtk_cell_area_cell_get_valist (GtkCellArea        *area,
2177                                GtkCellRenderer    *renderer,
2178                                const gchar        *first_property_name,
2179                                va_list             var_args)
2180 {
2181   const gchar *name;
2182
2183   g_return_if_fail (GTK_IS_CELL_AREA (area));
2184   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2185
2186   name = first_property_name;
2187   while (name)
2188     {
2189       GValue value = { 0, };
2190       GParamSpec *pspec;
2191       gchar *error;
2192
2193       pspec = g_param_spec_pool_lookup (cell_property_pool, name,
2194                                         G_OBJECT_TYPE (area), TRUE);
2195       if (!pspec)
2196         {
2197           g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2198                      G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2199           break;
2200         }
2201       if (!(pspec->flags & G_PARAM_READABLE))
2202         {
2203           g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2204                      G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2205           break;
2206         }
2207
2208       g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2209       area_get_cell_property (area, renderer, pspec, &value);
2210       G_VALUE_LCOPY (&value, var_args, 0, &error);
2211       if (error)
2212         {
2213           g_warning ("%s: %s", G_STRLOC, error);
2214           g_free (error);
2215           g_value_unset (&value);
2216           break;
2217         }
2218       g_value_unset (&value);
2219       name = va_arg (var_args, gchar*);
2220     }
2221 }
2222
2223 /**
2224  * gtk_cell_area_cell_set_property:
2225  * @area: a #GtkCellArea
2226  * @renderer: a #GtkCellRenderer inside @area
2227  * @property_name: the name of the cell property to set
2228  * @value: the value to set the cell property to
2229  *
2230  * Sets a cell property for @renderer in @area.
2231  **/
2232 void
2233 gtk_cell_area_cell_set_property (GtkCellArea        *area,
2234                                  GtkCellRenderer    *renderer,
2235                                  const gchar        *property_name,
2236                                  const GValue       *value)
2237 {
2238   GParamSpec *pspec;
2239
2240   g_return_if_fail (GTK_IS_CELL_AREA (area));
2241   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2242   g_return_if_fail (property_name != NULL);
2243   g_return_if_fail (G_IS_VALUE (value));
2244   
2245   pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2246                                     G_OBJECT_TYPE (area), TRUE);
2247   if (!pspec)
2248     g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2249                G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2250   else if (!(pspec->flags & G_PARAM_WRITABLE))
2251     g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2252                G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2253   else
2254     {
2255       area_set_cell_property (area, renderer, pspec, value);
2256     }
2257 }
2258
2259 /**
2260  * gtk_cell_area_cell_get_property:
2261  * @area: a #GtkCellArea
2262  * @renderer: a #GtkCellRenderer inside @area
2263  * @property_name: the name of the property to get
2264  * @value: a location to return the value
2265  *
2266  * Gets the value of a cell property for @renderer in @area.
2267  **/
2268 void
2269 gtk_cell_area_cell_get_property (GtkCellArea        *area,
2270                                  GtkCellRenderer    *renderer,
2271                                  const gchar        *property_name,
2272                                  GValue             *value)
2273 {
2274   GParamSpec *pspec;
2275
2276   g_return_if_fail (GTK_IS_CELL_AREA (area));
2277   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2278   g_return_if_fail (property_name != NULL);
2279   g_return_if_fail (G_IS_VALUE (value));
2280   
2281   pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2282                                     G_OBJECT_TYPE (area), TRUE);
2283   if (!pspec)
2284     g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2285                G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2286   else if (!(pspec->flags & G_PARAM_READABLE))
2287     g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2288                G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2289   else
2290     {
2291       GValue *prop_value, tmp_value = { 0, };
2292
2293       /* auto-conversion of the callers value type
2294        */
2295       if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
2296         {
2297           g_value_reset (value);
2298           prop_value = value;
2299         }
2300       else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
2301         {
2302           g_warning ("can't retrieve cell property `%s' of type `%s' as value of type `%s'",
2303                      pspec->name,
2304                      g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2305                      G_VALUE_TYPE_NAME (value));
2306           return;
2307         }
2308       else
2309         {
2310           g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2311           prop_value = &tmp_value;
2312         }
2313
2314       area_get_cell_property (area, renderer, pspec, prop_value);
2315
2316       if (prop_value != value)
2317         {
2318           g_value_transform (prop_value, value);
2319           g_value_unset (&tmp_value);
2320         }
2321     }
2322 }
2323
2324 /*************************************************************
2325  *                         API: Focus                        *
2326  *************************************************************/
2327
2328 /**
2329  * gtk_cell_area_can_focus:
2330  * @area: a #GtkCellArea
2331  *
2332  * Returns whether the area can receive keyboard focus,
2333  * after applying new attributes to @area.
2334  *
2335  * Returns: whether @area can receive focus.
2336  */
2337 gboolean
2338 gtk_cell_area_can_focus (GtkCellArea *area)
2339 {
2340   g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2341
2342   return GTK_CELL_AREA_GET_CLASS (area)->can_focus (area);
2343 }
2344
2345 /**
2346  * gtk_cell_area_focus:
2347  * @area: a #GtkCellArea
2348  * @direction: the #GtkDirectionType
2349  *
2350  * This should be called by the @area's owning layout widget
2351  * when focus is to be passed to @area, or moved within @area
2352  * for a given @direction and row data.
2353  *
2354  * Implementing #GtkCellArea classes should implement this
2355  * method to receive and navigate focus in it's own way particular
2356  * to how it lays out cells.
2357  *
2358  * Returns: %TRUE if focus remains inside @area as a result of this call.
2359  */
2360 gboolean
2361 gtk_cell_area_focus (GtkCellArea      *area,
2362                      GtkDirectionType  direction)
2363 {
2364   GtkCellAreaClass *class;
2365
2366   g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2367
2368   class = GTK_CELL_AREA_GET_CLASS (area);
2369
2370   if (class->focus)
2371     return class->focus (area, direction);
2372
2373   g_warning ("GtkCellAreaClass::focus not implemented for `%s'", 
2374              g_type_name (G_TYPE_FROM_INSTANCE (area)));
2375
2376   return FALSE;
2377 }
2378
2379 /**
2380  * gtk_cell_area_activate:
2381  * @area: a #GtkCellArea
2382  * @context: the #GtkCellAreaContext in context with the current row data
2383  * @widget: the #GtkWidget that @area is rendering on
2384  * @cell_area: the size and location of @area relative to @widget's allocation
2385  * @flags: the #GtkCellRendererState flags for @area for this row of data.
2386  *
2387  * Activates @area, usually by activating the currently focused
2388  * cell, however some subclasses which embed widgets in the area
2389  * can also activate a widget if it currently has the focus.
2390  *
2391  * Returns: Whether @area was successfully activated.
2392  */
2393 gboolean
2394 gtk_cell_area_activate (GtkCellArea         *area,
2395                         GtkCellAreaContext  *context,
2396                         GtkWidget           *widget,
2397                         const GdkRectangle  *cell_area,
2398                         GtkCellRendererState flags)
2399 {
2400   g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2401
2402   return GTK_CELL_AREA_GET_CLASS (area)->activate (area, context, widget, cell_area, flags);
2403 }
2404
2405
2406 /**
2407  * gtk_cell_area_set_focus_cell:
2408  * @area: a #GtkCellArea
2409  * @focus_cell: the #GtkCellRenderer to give focus to
2410  *
2411  * This is generally called from #GtkCellArea implementations
2412  * either gtk_cell_area_grab_focus() or gtk_cell_area_update_focus()
2413  * is called. It's also up to the #GtkCellArea implementation
2414  * to update the focused cell when receiving events from
2415  * gtk_cell_area_event() appropriately.
2416  */
2417 void
2418 gtk_cell_area_set_focus_cell (GtkCellArea     *area,
2419                               GtkCellRenderer *renderer)
2420 {
2421   GtkCellAreaPrivate *priv;
2422
2423   g_return_if_fail (GTK_IS_CELL_AREA (area));
2424   g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2425
2426   priv = area->priv;
2427
2428   if (priv->focus_cell != renderer)
2429     {
2430       if (priv->focus_cell)
2431         g_object_unref (priv->focus_cell);
2432
2433       priv->focus_cell = renderer;
2434
2435       if (priv->focus_cell)
2436         g_object_ref (priv->focus_cell);
2437
2438       g_object_notify (G_OBJECT (area), "focus-cell");
2439     }
2440
2441   /* Signal that the current focus renderer for this path changed
2442    * (it may be that the focus cell did not change, but the row
2443    * may have changed so we need to signal it) */
2444   g_signal_emit (area, cell_area_signals[SIGNAL_FOCUS_CHANGED], 0, 
2445                  priv->focus_cell, priv->current_path);
2446
2447 }
2448
2449 /**
2450  * gtk_cell_area_get_focus_cell:
2451  * @area: a #GtkCellArea
2452  *
2453  * Retrieves the currently focused cell for @area
2454  *
2455  * Returns: the currently focused cell in @area.
2456  */
2457 GtkCellRenderer *
2458 gtk_cell_area_get_focus_cell (GtkCellArea *area)
2459 {
2460   GtkCellAreaPrivate *priv;
2461
2462   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2463
2464   priv = area->priv;
2465
2466   return priv->focus_cell;
2467 }
2468
2469
2470 /*************************************************************
2471  *                    API: Focus Siblings                    *
2472  *************************************************************/
2473
2474 /**
2475  * gtk_cell_area_add_focus_sibling:
2476  * @area: a #GtkCellArea
2477  * @renderer: the #GtkCellRenderer expected to have focus
2478  * @sibling: the #GtkCellRenderer to add to @renderer's focus area
2479  *
2480  * Adds @sibling to @renderer's focusable area, focus will be drawn
2481  * around @renderer and all of it's siblings if @renderer can 
2482  * focus for a given row.
2483  *
2484  * Events handled by focus siblings can also activate the given
2485  * focusable @renderer.
2486  */
2487 void
2488 gtk_cell_area_add_focus_sibling (GtkCellArea     *area,
2489                                  GtkCellRenderer *renderer,
2490                                  GtkCellRenderer *sibling)
2491 {
2492   GtkCellAreaPrivate *priv;
2493   GList              *siblings;
2494
2495   g_return_if_fail (GTK_IS_CELL_AREA (area));
2496   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2497   g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2498   g_return_if_fail (renderer != sibling);
2499   g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2500   g_return_if_fail (gtk_cell_area_has_renderer (area, sibling));
2501   g_return_if_fail (!gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2502
2503   /* XXX We should also check that sibling is not in any other renderer's sibling
2504    * list already, a renderer can be sibling of only one focusable renderer
2505    * at a time.
2506    */
2507
2508   priv = area->priv;
2509
2510   siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2511
2512   if (siblings)
2513     siblings = g_list_append (siblings, sibling);
2514   else
2515     {
2516       siblings = g_list_append (siblings, sibling);
2517       g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2518     }
2519 }
2520
2521 /**
2522  * gtk_cell_area_remove_focus_sibling:
2523  * @area: a #GtkCellArea
2524  * @renderer: the #GtkCellRenderer expected to have focus
2525  * @sibling: the #GtkCellRenderer to remove from @renderer's focus area
2526  * 
2527  * Removes @sibling from @renderer's focus sibling list 
2528  * (see gtk_cell_area_add_focus_sibling()).
2529  */
2530 void
2531 gtk_cell_area_remove_focus_sibling (GtkCellArea     *area,
2532                                     GtkCellRenderer *renderer,
2533                                     GtkCellRenderer *sibling)
2534 {
2535   GtkCellAreaPrivate *priv;
2536   GList              *siblings;
2537
2538   g_return_if_fail (GTK_IS_CELL_AREA (area));
2539   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2540   g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2541   g_return_if_fail (gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2542
2543   priv = area->priv;
2544
2545   siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2546
2547   siblings = g_list_copy (siblings);
2548   siblings = g_list_remove (siblings, sibling);
2549
2550   if (!siblings)
2551     g_hash_table_remove (priv->focus_siblings, renderer);
2552   else
2553     g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2554 }
2555
2556 /**
2557  * gtk_cell_area_is_focus_sibling:
2558  * @area: a #GtkCellArea
2559  * @renderer: the #GtkCellRenderer expected to have focus
2560  * @sibling: the #GtkCellRenderer to check against @renderer's sibling list
2561  * 
2562  * Returns %TRUE if @sibling is one of @renderer's focus siblings
2563  * (see gtk_cell_area_add_focus_sibling()).
2564  */
2565 gboolean
2566 gtk_cell_area_is_focus_sibling (GtkCellArea     *area,
2567                                 GtkCellRenderer *renderer,
2568                                 GtkCellRenderer *sibling)
2569 {
2570   GtkCellAreaPrivate *priv;
2571   GList              *siblings, *l;
2572
2573   g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2574   g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2575   g_return_val_if_fail (GTK_IS_CELL_RENDERER (sibling), FALSE);
2576
2577   priv = area->priv;
2578
2579   siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2580
2581   for (l = siblings; l; l = l->next)
2582     {
2583       GtkCellRenderer *a_sibling = l->data;
2584
2585       if (a_sibling == sibling)
2586         return TRUE;
2587     }
2588
2589   return FALSE;
2590 }
2591
2592 /**
2593  * gtk_cell_area_get_focus_siblings:
2594  * @area: a #GtkCellArea
2595  * @renderer: the #GtkCellRenderer expected to have focus
2596  *
2597  * Gets the focus sibling cell renderers for @renderer.
2598  *
2599  * Returns: A #GList of #GtkCellRenderers. The returned list is internal and should not be freed.
2600  */
2601 const GList *
2602 gtk_cell_area_get_focus_siblings (GtkCellArea     *area,
2603                                   GtkCellRenderer *renderer)
2604 {
2605   GtkCellAreaPrivate *priv;
2606
2607   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2608   g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2609
2610   priv = area->priv;
2611
2612   return g_hash_table_lookup (priv->focus_siblings, renderer);  
2613 }
2614
2615 /**
2616  * gtk_cell_area_get_focus_from_sibling:
2617  * @area: a #GtkCellArea
2618  * @renderer: the #GtkCellRenderer
2619  *
2620  * Gets the #GtkCellRenderer which is expected to be focusable
2621  * for which @renderer is, or may be a sibling.
2622  *
2623  * This is handy for #GtkCellArea subclasses when handling events,
2624  * after determining the renderer at the event location it can
2625  * then chose to activate the focus cell for which the event
2626  * cell may have been a sibling.
2627  *
2628  * Returns: the #GtkCellRenderer for which @renderer is a sibling, or %NULL.
2629  */
2630 GtkCellRenderer *
2631 gtk_cell_area_get_focus_from_sibling (GtkCellArea          *area,
2632                                       GtkCellRenderer      *renderer)
2633 {
2634   GtkCellRenderer *ret_renderer = NULL;
2635   GList           *renderers, *l;
2636
2637   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2638   g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2639
2640   renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
2641
2642   for (l = renderers; l; l = l->next)
2643     {
2644       GtkCellRenderer *a_renderer = l->data;
2645       const GList     *list;
2646
2647       for (list = gtk_cell_area_get_focus_siblings (area, a_renderer); 
2648            list; list = list->next)
2649         {
2650           GtkCellRenderer *sibling_renderer = list->data;
2651
2652           if (sibling_renderer == renderer)
2653             {
2654               ret_renderer = a_renderer;
2655               break;
2656             }
2657         }
2658     }
2659   g_list_free (renderers);
2660
2661   return ret_renderer;
2662 }
2663
2664 /*************************************************************
2665  *              API: Cell Activation/Editing                 *
2666  *************************************************************/
2667 static void
2668 gtk_cell_area_add_editable (GtkCellArea        *area,
2669                             GtkCellRenderer    *renderer,
2670                             GtkCellEditable    *editable,
2671                             GdkRectangle       *cell_area)
2672 {
2673   g_signal_emit (area, cell_area_signals[SIGNAL_ADD_EDITABLE], 0, 
2674                  renderer, editable, cell_area, area->priv->current_path);
2675 }
2676
2677 static void
2678 gtk_cell_area_remove_editable  (GtkCellArea        *area,
2679                                 GtkCellRenderer    *renderer,
2680                                 GtkCellEditable    *editable)
2681 {
2682   g_signal_emit (area, cell_area_signals[SIGNAL_REMOVE_EDITABLE], 0, renderer, editable);
2683 }
2684
2685 static void
2686 cell_area_remove_widget_cb (GtkCellEditable *editable,
2687                             GtkCellArea     *area)
2688 {
2689   GtkCellAreaPrivate *priv = area->priv;
2690
2691   g_assert (priv->edit_widget == editable);
2692   g_assert (priv->edited_cell != NULL);
2693
2694   gtk_cell_area_remove_editable (area, priv->edited_cell, priv->edit_widget);
2695
2696   /* Now that we're done with editing the widget and it can be removed,
2697    * remove our references to the widget and disconnect handlers */
2698   gtk_cell_area_set_edited_cell (area, NULL);
2699   gtk_cell_area_set_edit_widget (area, NULL);
2700 }
2701
2702 static void
2703 gtk_cell_area_set_edited_cell (GtkCellArea     *area,
2704                                GtkCellRenderer *renderer)
2705 {
2706   GtkCellAreaPrivate *priv;
2707
2708   g_return_if_fail (GTK_IS_CELL_AREA (area));
2709   g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2710
2711   priv = area->priv;
2712
2713   if (priv->edited_cell != renderer)
2714     {
2715       if (priv->edited_cell)
2716         g_object_unref (priv->edited_cell);
2717
2718       priv->edited_cell = renderer;
2719
2720       if (priv->edited_cell)
2721         g_object_ref (priv->edited_cell);
2722
2723       g_object_notify (G_OBJECT (area), "edited-cell");
2724     }
2725 }
2726
2727 static void
2728 gtk_cell_area_set_edit_widget (GtkCellArea     *area,
2729                                GtkCellEditable *editable)
2730 {
2731   GtkCellAreaPrivate *priv;
2732
2733   g_return_if_fail (GTK_IS_CELL_AREA (area));
2734   g_return_if_fail (editable == NULL || GTK_IS_CELL_EDITABLE (editable));
2735
2736   priv = area->priv;
2737
2738   if (priv->edit_widget != editable)
2739     {
2740       if (priv->edit_widget)
2741         {
2742           g_signal_handler_disconnect (priv->edit_widget, priv->remove_widget_id);
2743
2744           g_object_unref (priv->edit_widget);
2745         }
2746
2747       priv->edit_widget = editable;
2748
2749       if (priv->edit_widget)
2750         {
2751           priv->remove_widget_id =
2752             g_signal_connect (priv->edit_widget, "remove-widget",
2753                               G_CALLBACK (cell_area_remove_widget_cb), area);
2754
2755           g_object_ref (priv->edit_widget);
2756         }
2757
2758       g_object_notify (G_OBJECT (area), "edit-widget");
2759     }
2760 }
2761
2762 /**
2763  * gtk_cell_area_get_edited_cell:
2764  * @area: a #GtkCellArea
2765  *
2766  * Gets the #GtkCellRenderer in @area that is currently
2767  * being edited.
2768  *
2769  * Returns: The currently edited #GtkCellRenderer
2770  */
2771 GtkCellRenderer   *
2772 gtk_cell_area_get_edited_cell (GtkCellArea *area)
2773 {
2774   GtkCellAreaPrivate *priv;
2775
2776   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2777
2778   priv = area->priv;
2779
2780   return priv->edited_cell;
2781 }
2782
2783 /**
2784  * gtk_cell_area_get_edit_widget:
2785  * @area: a #GtkCellArea
2786  *
2787  * Gets the #GtkCellEditable widget currently used
2788  * to edit the currently edited cell.
2789  *
2790  * Returns: The currently active #GtkCellEditable widget
2791  */
2792 GtkCellEditable *
2793 gtk_cell_area_get_edit_widget (GtkCellArea *area)
2794 {
2795   GtkCellAreaPrivate *priv;
2796
2797   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2798
2799   priv = area->priv;
2800
2801   return priv->edit_widget;
2802 }
2803
2804 /**
2805  * gtk_cell_area_activate_cell:
2806  * @area: a #GtkCellArea
2807  * @widget: the #GtkWidget that @area is rendering onto
2808  * @renderer: the #GtkCellRenderer in @area to activate
2809  * @event: the #GdkEvent for which cell activation should occur
2810  * @cell_area: the #GdkRectangle in @widget relative coordinates
2811  *             of @renderer for the current row.
2812  * @flags: the #GtkCellRendererState for @renderer
2813  *
2814  * This is used by #GtkCellArea subclasses when handling events
2815  * to activate cells, the base #GtkCellArea class activates cells
2816  * for keyboard events for free in it's own GtkCellArea->activate()
2817  * implementation.
2818  *
2819  * Returns: whether cell activation was successful
2820  */
2821 gboolean
2822 gtk_cell_area_activate_cell (GtkCellArea          *area,
2823                              GtkWidget            *widget,
2824                              GtkCellRenderer      *renderer,
2825                              GdkEvent             *event,
2826                              const GdkRectangle   *cell_area,
2827                              GtkCellRendererState  flags)
2828 {
2829   GtkCellRendererMode mode;
2830   GdkRectangle        inner_area;
2831   GtkCellAreaPrivate *priv;
2832   
2833   g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2834   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2835   g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2836   g_return_val_if_fail (cell_area != NULL, FALSE);
2837
2838   priv = area->priv;
2839
2840   /* Remove margins from the background area to produce the cell area.
2841    *
2842    * XXX Maybe have to do some rtl mode treatment here...
2843    */
2844   gtk_cell_area_inner_cell_area (area, widget, cell_area, &inner_area);
2845
2846   g_object_get (renderer, "mode", &mode, NULL);
2847
2848   if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2849     {
2850       if (gtk_cell_renderer_activate (renderer,
2851                                       event, widget,
2852                                       priv->current_path,
2853                                       cell_area,
2854                                       &inner_area,
2855                                       flags))
2856         return TRUE;
2857     }
2858   else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2859     {
2860       GtkCellEditable *editable_widget;
2861       
2862       editable_widget =
2863         gtk_cell_renderer_start_editing (renderer,
2864                                          event, widget,
2865                                          priv->current_path,
2866                                          cell_area,
2867                                          &inner_area,
2868                                          flags);
2869       
2870       if (editable_widget != NULL)
2871         {
2872           g_return_val_if_fail (GTK_IS_CELL_EDITABLE (editable_widget), FALSE);
2873           
2874           gtk_cell_area_set_edited_cell (area, renderer);
2875           gtk_cell_area_set_edit_widget (area, editable_widget);
2876           
2877           /* Signal that editing started so that callers can get 
2878            * a handle on the editable_widget */
2879           gtk_cell_area_add_editable (area, priv->focus_cell, editable_widget, &inner_area);
2880
2881           /* If the signal was successfully handled start the editing */
2882           if (gtk_widget_get_parent (GTK_WIDGET (editable_widget)))
2883             {
2884               gtk_cell_editable_start_editing (editable_widget, NULL);
2885               gtk_widget_grab_focus (GTK_WIDGET (editable_widget));
2886             }
2887           else
2888             {
2889               /* Otherwise clear the editing state and fire a warning */
2890               gtk_cell_area_set_edited_cell (area, NULL);
2891               gtk_cell_area_set_edit_widget (area, NULL);
2892
2893               g_warning ("GtkCellArea::add-editable fired in the dark, no cell editing was started.");
2894             }
2895           
2896           return TRUE;
2897         }
2898     }
2899
2900   return FALSE;
2901 }
2902
2903 /**
2904  * gtk_cell_area_stop_editing:
2905  * @area: a #GtkCellArea
2906  * @canceled: whether editing was canceled.
2907  *
2908  * Explicitly stops the editing of the currently
2909  * edited cell (see gtk_cell_area_get_edited_cell()).
2910  *
2911  * If @canceled is %TRUE, the cell renderer will emit
2912  * the ::editing-canceled signal.
2913  */
2914 void
2915 gtk_cell_area_stop_editing (GtkCellArea *area,
2916                             gboolean     canceled)
2917 {
2918   GtkCellAreaPrivate *priv;
2919
2920   g_return_if_fail (GTK_IS_CELL_AREA (area));
2921
2922   priv = area->priv;
2923
2924   if (priv->edited_cell)
2925     {
2926       GtkCellEditable *edit_widget = g_object_ref (priv->edit_widget);
2927       GtkCellRenderer *edit_cell   = g_object_ref (priv->edited_cell);
2928
2929       /* Stop editing of the cell renderer */
2930       gtk_cell_renderer_stop_editing (priv->edited_cell, canceled);
2931       
2932       /* Remove any references to the editable widget */
2933       gtk_cell_area_set_edited_cell (area, NULL);
2934       gtk_cell_area_set_edit_widget (area, NULL);
2935
2936       /* Send the remove-widget signal explicitly (this is done after setting
2937        * the edit cell/widget NULL to avoid feedback)
2938        */
2939       gtk_cell_area_remove_editable (area, edit_cell, edit_widget);
2940       g_object_unref (edit_cell);
2941       g_object_unref (edit_widget);
2942     }
2943 }
2944
2945 /*************************************************************
2946  *         API: Convenience for area implementations         *
2947  *************************************************************/
2948
2949 void
2950 gtk_cell_area_inner_cell_area (GtkCellArea        *area,
2951                                GtkWidget          *widget,
2952                                const GdkRectangle *cell_area,
2953                                GdkRectangle       *inner_area)
2954 {
2955   gint focus_line_width;
2956
2957   g_return_if_fail (GTK_IS_CELL_AREA (area));
2958   g_return_if_fail (GTK_IS_WIDGET (widget));
2959   g_return_if_fail (cell_area != NULL);
2960   g_return_if_fail (inner_area != NULL);
2961
2962   gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
2963
2964   *inner_area = *cell_area;
2965
2966   inner_area->x      += focus_line_width;
2967   inner_area->width  -= focus_line_width * 2;
2968   inner_area->y      += focus_line_width;
2969   inner_area->height -= focus_line_width * 2;
2970 }
2971
2972 void
2973 gtk_cell_area_request_renderer (GtkCellArea        *area,
2974                                 GtkCellRenderer    *renderer,
2975                                 GtkOrientation      orientation,
2976                                 GtkWidget          *widget,
2977                                 gint                for_size,
2978                                 gint               *minimum_size,
2979                                 gint               *natural_size)
2980 {
2981   GtkCellAreaPrivate *priv;
2982   gint                focus_line_width;
2983
2984   g_return_if_fail (GTK_IS_CELL_AREA (area));
2985   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2986   g_return_if_fail (GTK_IS_WIDGET (widget));
2987   g_return_if_fail (minimum_size != NULL);
2988   g_return_if_fail (natural_size != NULL);
2989
2990   priv = area->priv;
2991
2992   gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
2993
2994   focus_line_width *= 2;
2995
2996   if (orientation == GTK_ORIENTATION_HORIZONTAL)
2997     {
2998       if (for_size < 0)
2999           gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
3000       else
3001         {
3002           for_size = MAX (0, for_size - focus_line_width);
3003
3004           gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size, 
3005                                                             minimum_size, natural_size);
3006         }
3007     }
3008   else /* GTK_ORIENTATION_VERTICAL */
3009     {
3010       if (for_size < 0)
3011         gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
3012       else
3013         {
3014           for_size = MAX (0, for_size - focus_line_width);
3015
3016           gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size, 
3017                                                             minimum_size, natural_size);
3018         }
3019     }
3020
3021   *minimum_size += focus_line_width;
3022   *natural_size += focus_line_width;
3023 }