]> Pileus Git - ~andy/gtk/blob - gtk/gtkcelllayout.c
Fix doc about gtk_cell_layout_get_area()
[~andy/gtk] / gtk / gtkcelllayout.c
1 /* gtkcelllayout.c
2  * Copyright (C) 2003  Kristian Rietveld  <kris@gtk.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /**
21  * SECTION:gtkcelllayout
22  * @Short_Description: An interface for packing cells
23  * @Title: GtkCellLayout
24  *
25  * #GtkCellLayout is an interface to be implemented by all objects which
26  * want to provide a #GtkTreeViewColumn-like API for packing cells, setting
27  * attributes and data funcs.
28  *
29  * One of the notable features provided by implementations of GtkCellLayout
30  * are <emphasis>attributes</emphasis>. Attributes let you set the properties
31  * in flexible ways. They can just be set to constant values like regular
32  * properties. But they can also be mapped to a column of the underlying
33  * tree model with gtk_cell_layout_set_attributes(), which means that the value
34  * of the attribute can change from cell to cell as they are rendered by the
35  * cell renderer. Finally, it is possible to specify a function with
36  * gtk_cell_layout_set_cell_data_func() that is called to determine the value
37  * of the attribute for each cell that is rendered.
38  *
39  * <refsect2 id="GtkCellLayout-BUILDER-UI">
40  * <title>GtkCellLayouts as GtkBuildable</title>
41  * <para>
42  * Implementations of GtkCellLayout which also implement the GtkBuildable
43  * interface (#GtkCellView, #GtkIconView, #GtkComboBox, #GtkComboBoxEntry,
44  * #GtkEntryCompletion, #GtkTreeViewColumn) accept GtkCellRenderer objects
45  * as &lt;child&gt; elements in UI definitions. They support a custom
46  * &lt;attributes&gt; element for their children, which can contain
47  * multiple &lt;attribute&gt; elements. Each &lt;attribute&gt; element has
48  * a name attribute which specifies a property of the cell renderer; the
49  * content of the element is the attribute value.
50  *
51  * <example>
52  * <title>A UI definition fragment specifying attributes</title>
53  * <programlisting><![CDATA[
54  * <object class="GtkCellView">
55  *   <child>
56  *     <object class="GtkCellRendererText"/>
57  *     <attributes>
58  *       <attribute name="text">0</attribute>
59  *     </attributes>
60  *   </child>"
61  * </object>
62  * ]]></programlisting>
63  * </example>
64  *
65  * Furthermore for implementations of GtkCellLayout that use a #GtkCellArea
66  * to lay out cells (all GtkCellLayouts in GTK+ use a GtkCellArea)
67  * <link linkend="cell-properties">cell properties</link> can also be defined
68  * in the format by specifying the custom &lt;cell-packing&gt; attribute which
69  * can contain multiple &lt;property&gt; elements defined in the normal way.
70  * <example>
71  * <title>A UI definition fragment specifying cell properties</title>
72  * <programlisting><![CDATA[
73  * <object class="GtkTreeViewColumn">
74  *   <child>
75  *     <object class="GtkCellRendererText"/>
76  *     <cell-packing>
77  *       <property name="align">True</property>
78  *       <property name="expand">False</property>
79  *     </cell-packing>
80  *   </child>"
81  * </object>
82  * ]]></programlisting>
83  * </example>
84  * </para>
85  * </refsect2>
86  */
87
88 #include "config.h"
89 #include <string.h>
90 #include <stdlib.h>
91 #include <errno.h>
92 #include "gtkcelllayout.h"
93 #include "gtkbuilderprivate.h"
94 #include "gtkintl.h"
95
96
97 typedef GtkCellLayoutIface GtkCellLayoutInterface;
98 G_DEFINE_INTERFACE (GtkCellLayout, gtk_cell_layout, G_TYPE_OBJECT);
99
100
101 static void
102 gtk_cell_layout_default_init (GtkCellLayoutInterface *iface)
103 {
104 }
105
106 /**
107  * gtk_cell_layout_pack_start:
108  * @cell_layout: a #GtkCellLayout
109  * @cell: a #GtkCellRenderer
110  * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout
111  *
112  * Packs the @cell into the beginning of @cell_layout. If @expand is %FALSE,
113  * then the @cell is allocated no more space than it needs. Any unused space
114  * is divided evenly between cells for which @expand is %TRUE.
115  *
116  * Note that reusing the same cell renderer is not supported.
117  *
118  * Since: 2.4
119  */
120 void
121 gtk_cell_layout_pack_start (GtkCellLayout   *cell_layout,
122                             GtkCellRenderer *cell,
123                             gboolean         expand)
124 {
125   GtkCellLayoutIface *iface;
126   GtkCellArea        *area;
127
128   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
129   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
130
131   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
132
133   if (iface->pack_start)
134     iface->pack_start (cell_layout, cell, expand);
135   else
136     {
137       area = iface->get_area (cell_layout);
138
139       if (area)
140         gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (area), cell, expand);
141     }
142 }
143
144 /**
145  * gtk_cell_layout_pack_end:
146  * @cell_layout: a #GtkCellLayout
147  * @cell: a #GtkCellRenderer
148  * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout
149  *
150  * Adds the @cell to the end of @cell_layout. If @expand is %FALSE, then the
151  * @cell is allocated no more space than it needs. Any unused space is
152  * divided evenly between cells for which @expand is %TRUE.
153  *
154  * Note that reusing the same cell renderer is not supported.
155  *
156  * Since: 2.4
157  */
158 void
159 gtk_cell_layout_pack_end (GtkCellLayout   *cell_layout,
160                           GtkCellRenderer *cell,
161                           gboolean         expand)
162 {
163   GtkCellLayoutIface *iface;
164   GtkCellArea        *area;
165
166   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
167   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
168
169   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
170
171   if (iface->pack_end)
172     iface->pack_end (cell_layout, cell, expand);
173   else
174     {
175       area = iface->get_area (cell_layout);
176
177       if (area)
178         gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (area), cell, expand);
179     }
180 }
181
182 /**
183  * gtk_cell_layout_clear:
184  * @cell_layout: a #GtkCellLayout
185  *
186  * Unsets all the mappings on all renderers on @cell_layout and
187  * removes all renderers from @cell_layout.
188  *
189  * Since: 2.4
190  */
191 void
192 gtk_cell_layout_clear (GtkCellLayout *cell_layout)
193 {
194   GtkCellLayoutIface *iface;
195   GtkCellArea        *area;
196
197   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
198
199   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
200
201   if (iface->clear)
202     iface->clear (cell_layout);
203   else
204     {
205       area = iface->get_area (cell_layout);
206
207       if (area)
208         gtk_cell_layout_clear (GTK_CELL_LAYOUT (area));
209     }
210 }
211
212 static void
213 gtk_cell_layout_set_attributesv (GtkCellLayout   *cell_layout,
214                                  GtkCellRenderer *cell,
215                                  va_list          args)
216 {
217   gchar *attribute;
218   gint column;
219   GtkCellLayoutIface *iface;
220   GtkCellArea        *area;
221
222   attribute = va_arg (args, gchar *);
223
224   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
225
226   if (iface->get_area)
227     area = iface->get_area (cell_layout);
228
229   if (iface->clear_attributes)
230     iface->clear_attributes (cell_layout, cell);
231   else if (area)
232     gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (area), cell);
233
234   while (attribute != NULL)
235     {
236       column = va_arg (args, gint);
237       if (iface->add_attribute)
238         iface->add_attribute (cell_layout, cell, attribute, column);
239       else if (area)
240         gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (area), cell, attribute, column);
241
242       attribute = va_arg (args, gchar *);
243     }
244 }
245
246 /**
247  * gtk_cell_layout_set_attributes:
248  * @cell_layout: a #GtkCellLayout
249  * @cell: a #GtkCellRenderer
250  * @Varargs: a %NULL-terminated list of attributes
251  *
252  * Sets the attributes in list as the attributes of @cell_layout.
253  *
254  * The attributes should be in attribute/column order, as in
255  * gtk_cell_layout_add_attribute(). All existing attributes are
256  * removed, and replaced with the new attributes.
257  *
258  * Since: 2.4
259  */
260 void
261 gtk_cell_layout_set_attributes (GtkCellLayout   *cell_layout,
262                                 GtkCellRenderer *cell,
263                                 ...)
264 {
265   va_list args;
266
267   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
268   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
269
270   va_start (args, cell);
271   gtk_cell_layout_set_attributesv (cell_layout, cell, args);
272   va_end (args);
273 }
274
275 /**
276  * gtk_cell_layout_add_attribute:
277  * @cell_layout: a #GtkCellLayout
278  * @cell: a #GtkCellRenderer
279  * @attribute: an attribute on the renderer
280  * @column: the column position on the model to get the attribute from
281  *
282  * Adds an attribute mapping to the list in @cell_layout.
283  *
284  * The @column is the column of the model to get a value from, and the
285  * @attribute is the parameter on @cell to be set from the value. So for
286  * example if column 2 of the model contains strings, you could have the
287  * "text" attribute of a #GtkCellRendererText get its values from column 2.
288  *
289  * Since: 2.4
290  */
291 void
292 gtk_cell_layout_add_attribute (GtkCellLayout   *cell_layout,
293                                GtkCellRenderer *cell,
294                                const gchar     *attribute,
295                                gint             column)
296 {
297   GtkCellLayoutIface *iface;
298   GtkCellArea        *area;
299
300   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
301   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
302   g_return_if_fail (attribute != NULL);
303   g_return_if_fail (column >= 0);
304
305   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
306
307   if (iface->add_attribute)
308     iface->add_attribute (cell_layout,
309                           cell,
310                           attribute,
311                           column);
312   else
313     {
314       area = iface->get_area (cell_layout);
315
316       if (area)
317         gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (area), cell, attribute, column);
318     }
319 }
320
321 /**
322  * gtk_cell_layout_set_cell_data_func:
323  * @cell_layout: a #GtkCellLayout
324  * @cell: a #GtkCellRenderer
325  * @func (allow-none: the #GtkCellLayoutDataFunc to use, or %NULL
326  * @func_data: user data for @func
327  * @destroy: destroy notify for @func_data
328  *
329  * Sets the #GtkCellLayoutDataFunc to use for @cell_layout.
330  *
331  * This function is used instead of the standard attributes mapping
332  * for setting the column value, and should set the value of @cell_layout's
333  * cell renderer(s) as appropriate.
334  *
335  * @func may be %NULL to remove a previously set function.
336  *
337  * Since: 2.4
338  */
339 void
340 gtk_cell_layout_set_cell_data_func (GtkCellLayout         *cell_layout,
341                                     GtkCellRenderer       *cell,
342                                     GtkCellLayoutDataFunc  func,
343                                     gpointer               func_data,
344                                     GDestroyNotify         destroy)
345 {
346   GtkCellLayoutIface *iface;
347   GtkCellArea        *area;
348
349   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
350   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
351
352   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
353
354   if (iface->set_cell_data_func)
355     iface->set_cell_data_func (cell_layout,
356                                cell,
357                                func,
358                                func_data,
359                                destroy);
360   else
361     {
362       area = iface->get_area (cell_layout);
363
364       if (area)
365         {
366           /* Ensure that the correct proxy object is sent to 'func' */
367           if (GTK_CELL_LAYOUT (area) != cell_layout)
368             _gtk_cell_area_set_cell_data_func_with_proxy (area, cell, 
369                                                           (GFunc)func, func_data, destroy, 
370                                                           cell_layout);
371           else
372             gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (area), cell, 
373                                                 func, func_data, destroy);
374         }
375     }
376 }
377
378 /**
379  * gtk_cell_layout_clear_attributes:
380  * @cell_layout: a #GtkCellLayout
381  * @cell: a #GtkCellRenderer to clear the attribute mapping on
382  *
383  * Clears all existing attributes previously set with
384  * gtk_cell_layout_set_attributes().
385  *
386  * Since: 2.4
387  */
388 void
389 gtk_cell_layout_clear_attributes (GtkCellLayout   *cell_layout,
390                                   GtkCellRenderer *cell)
391 {
392   GtkCellLayoutIface *iface;
393   GtkCellArea        *area;
394
395   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
396   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
397
398   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
399
400   if (iface->clear_attributes)
401     iface->clear_attributes (cell_layout, cell);
402   else
403     {
404       area = iface->get_area (cell_layout);
405       
406       if (area)
407         gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (area), cell);
408     }
409 }
410
411 /**
412  * gtk_cell_layout_reorder:
413  * @cell_layout: a #GtkCellLayout
414  * @cell: a #GtkCellRenderer to reorder
415  * @position: new position to insert @cell at
416  *
417  * Re-inserts @cell at @position.
418  *
419  * Note that @cell has already to be packed into @cell_layout
420  * for this to function properly.
421  *
422  * Since: 2.4
423  */
424 void
425 gtk_cell_layout_reorder (GtkCellLayout   *cell_layout,
426                          GtkCellRenderer *cell,
427                          gint             position)
428 {
429   GtkCellLayoutIface *iface;
430   GtkCellArea        *area;
431
432   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
433   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
434
435   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
436
437   if (iface->reorder)
438     iface->reorder (cell_layout, cell, position);
439   else
440     {
441       area = iface->get_area (cell_layout);
442       
443       if (area)
444         gtk_cell_layout_reorder (GTK_CELL_LAYOUT (area), cell, position);
445     }
446 }
447
448 /**
449  * gtk_cell_layout_get_cells:
450  * @cell_layout: a #GtkCellLayout
451  *
452  * Returns the cell renderers which have been added to @cell_layout.
453  *
454  * Return value: (element-type GtkCellRenderer) (transfer container):
455  *     a list of cell renderers. The list, but not the renderers has
456  *     been newly allocated and should be freed with g_list_free()
457  *     when no longer needed.
458  *
459  * Since: 2.12
460  */
461 GList *
462 gtk_cell_layout_get_cells (GtkCellLayout *cell_layout)
463 {
464   GtkCellLayoutIface *iface;
465   GtkCellArea        *area;
466
467   g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL);
468
469   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);  
470   if (iface->get_cells)
471     return iface->get_cells (cell_layout);
472   else
473     {
474       area = iface->get_area (cell_layout);
475       
476       if (area)
477         return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
478     }
479
480   return NULL;
481 }
482
483 /**
484  * gtk_cell_layout_get_area:
485  * @cell_layout: a #GtkCellLayout
486  *
487  * Returns the underlying #GtkCellArea which might be @cell_layout
488  * if called on a #GtkCellArea or might be %NULL if no #GtkCellArea
489  * is used by @cell_layout.
490  *
491  * Return value: (transfer none): the cell area used by @cell_layout.
492  *
493  * Since: 3.0
494  */
495 GtkCellArea *
496 gtk_cell_layout_get_area (GtkCellLayout *cell_layout)
497 {
498   GtkCellLayoutIface *iface;
499
500   g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL);
501
502   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);  
503   if (iface->get_area)
504     return iface->get_area (cell_layout);
505
506   return NULL;
507 }
508
509 /* Attribute parsing */
510 typedef struct {
511   GtkCellLayout   *cell_layout;
512   GtkCellRenderer *renderer;
513   gchar           *attr_name;
514 } AttributesSubParserData;
515
516 static void
517 attributes_start_element (GMarkupParseContext *context,
518                           const gchar         *element_name,
519                           const gchar        **names,
520                           const gchar        **values,
521                           gpointer             user_data,
522                           GError             **error)
523 {
524   AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
525   guint i;
526
527   if (strcmp (element_name, "attribute") == 0)
528     {
529       for (i = 0; names[i]; i++)
530         if (strcmp (names[i], "name") == 0)
531           parser_data->attr_name = g_strdup (values[i]);
532     }
533   else if (strcmp (element_name, "attributes") == 0)
534     return;
535   else
536     g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
537 }
538
539 static void
540 attributes_text_element (GMarkupParseContext *context,
541                          const gchar         *text,
542                          gsize                text_len,
543                          gpointer             user_data,
544                          GError             **error)
545 {
546   AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
547   glong l;
548   gchar *endptr;
549   gchar *string;
550   
551   if (!parser_data->attr_name)
552     return;
553
554   string = g_strndup (text, text_len);
555   errno = 0;
556   l = g_ascii_strtoll (string, &endptr, 0);
557   if (errno || endptr == string)
558     {
559       g_set_error (error, 
560                    GTK_BUILDER_ERROR,
561                    GTK_BUILDER_ERROR_INVALID_VALUE,
562                    "Could not parse integer `%s'",
563                    string);
564       g_free (string);
565       return;
566     }
567   g_free (string);
568
569   gtk_cell_layout_add_attribute (parser_data->cell_layout,
570                                  parser_data->renderer,
571                                  parser_data->attr_name, l);
572   g_free (parser_data->attr_name);
573   parser_data->attr_name = NULL;
574 }
575
576 static const GMarkupParser attributes_parser =
577   {
578     attributes_start_element,
579     NULL,
580     attributes_text_element,
581   };
582
583
584 /* Cell packing parsing */
585 static void
586 gtk_cell_layout_buildable_set_cell_property (GtkCellArea     *area,
587                                              GtkBuilder      *builder,
588                                              GtkCellRenderer *cell,
589                                              gchar           *name,
590                                              const gchar     *value)
591 {
592   GParamSpec *pspec;
593   GValue gvalue = { 0, };
594   GError *error = NULL;
595
596   pspec = gtk_cell_area_class_find_cell_property (GTK_CELL_AREA_GET_CLASS (area), name);
597   if (!pspec)
598     {
599       g_warning ("%s does not have a property called %s",
600                  g_type_name (G_OBJECT_TYPE (area)), name);
601       return;
602     }
603
604   if (!gtk_builder_value_from_string (builder, pspec, value, &gvalue, &error))
605     {
606       g_warning ("Could not read property %s:%s with value %s of type %s: %s",
607                  g_type_name (G_OBJECT_TYPE (area)),
608                  name,
609                  value,
610                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
611                  error->message);
612       g_error_free (error);
613       return;
614     }
615
616   gtk_cell_area_cell_set_property (area, cell, name, &gvalue);
617   g_value_unset (&gvalue);
618 }
619
620 typedef struct {
621   GtkBuilder      *builder;
622   GtkCellLayout   *cell_layout;
623   GtkCellRenderer *renderer;
624   gchar           *cell_prop_name;
625   gchar           *context;
626   gboolean         translatable;
627 } CellPackingSubParserData;
628
629 static void
630 cell_packing_start_element (GMarkupParseContext *context,
631                             const gchar         *element_name,
632                             const gchar        **names,
633                             const gchar        **values,
634                             gpointer             user_data,
635                             GError             **error)
636 {
637   CellPackingSubParserData *parser_data = (CellPackingSubParserData*)user_data;
638   guint i;
639
640   if (strcmp (element_name, "property") == 0)
641     {
642       for (i = 0; names[i]; i++)
643         if (strcmp (names[i], "name") == 0)
644           parser_data->cell_prop_name = g_strdup (values[i]);
645         else if (strcmp (names[i], "translatable") == 0)
646           {
647             if (!_gtk_builder_boolean_from_string (values[i],
648                                                    &parser_data->translatable,
649                                                    error))
650               return;
651           }
652         else if (strcmp (names[i], "comments") == 0)
653           ; /* for translators */
654         else if (strcmp (names[i], "context") == 0)
655           parser_data->context = g_strdup (values[i]);
656         else
657           g_warning ("Unsupported attribute for GtkCellLayout Cell "
658                      "property: %s\n", names[i]);
659     }
660   else if (strcmp (element_name, "cell-packing") == 0)
661     return;
662   else
663     g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
664 }
665
666 static void
667 cell_packing_text_element (GMarkupParseContext *context,
668                            const gchar         *text,
669                            gsize                text_len,
670                            gpointer             user_data,
671                            GError             **error)
672 {
673   CellPackingSubParserData *parser_data = (CellPackingSubParserData*)user_data;
674   GtkCellArea *area;
675   gchar* value;
676
677   if (!parser_data->cell_prop_name)
678     return;
679
680   if (parser_data->translatable && text_len)
681     {
682       const gchar* domain;
683       domain = gtk_builder_get_translation_domain (parser_data->builder);
684
685       value = _gtk_builder_parser_translate (domain,
686                                              parser_data->context,
687                                              text);
688     }
689   else
690     {
691       value = g_strdup (text);
692     }
693
694   area = gtk_cell_layout_get_area (parser_data->cell_layout);
695
696   if (!area)
697     {
698       g_warning ("%s does not have an internal GtkCellArea class and cannot apply child cell properties",
699                  g_type_name (G_OBJECT_TYPE (parser_data->cell_layout)));
700       return;
701     }
702
703   gtk_cell_layout_buildable_set_cell_property (area, 
704                                                parser_data->builder,
705                                                parser_data->renderer,
706                                                parser_data->cell_prop_name,
707                                                value);
708
709   g_free (parser_data->cell_prop_name);
710   g_free (parser_data->context);
711   g_free (value);
712   parser_data->cell_prop_name = NULL;
713   parser_data->context = NULL;
714   parser_data->translatable = FALSE;
715 }
716
717 static const GMarkupParser cell_packing_parser =
718   {
719     cell_packing_start_element,
720     NULL,
721     cell_packing_text_element,
722   };
723
724 gboolean
725 _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable  *buildable,
726                                              GtkBuilder    *builder,
727                                              GObject       *child,
728                                              const gchar   *tagname,
729                                              GMarkupParser *parser,
730                                              gpointer      *data)
731 {
732   AttributesSubParserData  *attr_data;
733   CellPackingSubParserData *packing_data;
734
735   if (!child)
736     return FALSE;
737
738   if (strcmp (tagname, "attributes") == 0)
739     {
740       attr_data = g_slice_new0 (AttributesSubParserData);
741       attr_data->cell_layout = GTK_CELL_LAYOUT (buildable);
742       attr_data->renderer = GTK_CELL_RENDERER (child);
743       attr_data->attr_name = NULL;
744
745       *parser = attributes_parser;
746       *data = attr_data;
747       return TRUE;
748     }
749   else if (strcmp (tagname, "cell-packing") == 0)
750     {
751       packing_data = g_slice_new0 (CellPackingSubParserData);
752       packing_data->builder = builder;
753       packing_data->cell_layout = GTK_CELL_LAYOUT (buildable);
754       packing_data->renderer = GTK_CELL_RENDERER (child);
755
756       *parser = cell_packing_parser;
757       *data = packing_data;
758       return TRUE;
759     }
760
761   return FALSE;
762 }
763
764 gboolean
765 _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
766                                            GtkBuilder   *builder,
767                                            GObject      *child,
768                                            const gchar  *tagname,
769                                            gpointer     *data)
770 {
771   AttributesSubParserData *attr_data;
772
773   if (strcmp (tagname, "attributes") == 0)
774     {
775       attr_data = (AttributesSubParserData*)data;
776       g_assert (!attr_data->attr_name);
777       g_slice_free (AttributesSubParserData, attr_data);
778       return TRUE;
779     }
780   else if (strcmp (tagname, "cell-packing") == 0)
781     {
782       g_slice_free (CellPackingSubParserData, (gpointer)data);
783       return TRUE;
784     }
785   return FALSE;
786 }
787
788 void
789 _gtk_cell_layout_buildable_add_child (GtkBuildable      *buildable,
790                                       GtkBuilder        *builder,
791                                       GObject           *child,
792                                       const gchar       *type)
793 {
794   g_return_if_fail (GTK_IS_CELL_LAYOUT (buildable));
795   g_return_if_fail (GTK_IS_CELL_RENDERER (child));
796
797   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (buildable), GTK_CELL_RENDERER (child), FALSE);
798 }