]> Pileus Git - ~andy/gtk/blob - gtk/gtkcelllayout.c
Migrated GtkCellLayout documentation into the source code.
[~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 (most, of not 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. The
253  * attributes should be in attribute/column order, as in
254  * gtk_cell_layout_add_attribute(). All existing attributes are removed, and
255  * replaced with the new attributes.
256  *
257  * Since: 2.4
258  */
259 void
260 gtk_cell_layout_set_attributes (GtkCellLayout   *cell_layout,
261                                 GtkCellRenderer *cell,
262                                 ...)
263 {
264   va_list args;
265
266   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
267   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
268
269   va_start (args, cell);
270   gtk_cell_layout_set_attributesv (cell_layout, cell, args);
271   va_end (args);
272 }
273
274 /**
275  * gtk_cell_layout_add_attribute:
276  * @cell_layout: A #GtkCellLayout.
277  * @cell: A #GtkCellRenderer.
278  * @attribute: An attribute on the renderer.
279  * @column: The column position on the model to get the attribute from.
280  *
281  * Adds an attribute mapping to the list in @cell_layout. The @column is the
282  * column of the model to get a value from, and the @attribute is the
283  * parameter on @cell to be set from the value. So for example if column 2
284  * of the model contains strings, you could have the "text" attribute of a
285  * #GtkCellRendererText get its values from column 2.
286  *
287  * Since: 2.4
288  */
289 void
290 gtk_cell_layout_add_attribute (GtkCellLayout   *cell_layout,
291                                GtkCellRenderer *cell,
292                                const gchar     *attribute,
293                                gint             column)
294 {
295   GtkCellLayoutIface *iface;
296   GtkCellArea        *area;
297
298   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
299   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
300   g_return_if_fail (attribute != NULL);
301   g_return_if_fail (column >= 0);
302
303   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
304
305   if (iface->add_attribute)
306     iface->add_attribute (cell_layout,
307                           cell,
308                           attribute,
309                           column);
310   else
311     {
312       area = iface->get_area (cell_layout);
313
314       if (area)
315         gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (area), cell, attribute, column);
316     }
317 }
318
319 /**
320  * gtk_cell_layout_set_cell_data_func:
321  * @cell_layout: A #GtkCellLayout.
322  * @cell: A #GtkCellRenderer.
323  * @func: The #GtkCellLayoutDataFunc to use.
324  * @func_data: The user data for @func.
325  * @destroy: The destroy notification for @func_data.
326  *
327  * Sets the #GtkCellLayoutDataFunc to use for @cell_layout. This function
328  * is used instead of the standard attributes mapping for setting the
329  * column value, and should set the value of @cell_layout's cell renderer(s)
330  * as appropriate. @func may be %NULL to remove and older one.
331  *
332  * Since: 2.4
333  */
334 void
335 gtk_cell_layout_set_cell_data_func (GtkCellLayout         *cell_layout,
336                                     GtkCellRenderer       *cell,
337                                     GtkCellLayoutDataFunc  func,
338                                     gpointer               func_data,
339                                     GDestroyNotify         destroy)
340 {
341   GtkCellLayoutIface *iface;
342   GtkCellArea        *area;
343
344   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
345   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
346
347   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
348
349   if (iface->set_cell_data_func)
350     iface->set_cell_data_func (cell_layout,
351                                cell,
352                                func,
353                                func_data,
354                                destroy);
355   else
356     {
357       area = iface->get_area (cell_layout);
358
359       if (area)
360         gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (area), cell, func, func_data, destroy);
361     }
362 }
363
364 /**
365  * gtk_cell_layout_clear_attributes:
366  * @cell_layout: A #GtkCellLayout.
367  * @cell: A #GtkCellRenderer to clear the attribute mapping on.
368  *
369  * Clears all existing attributes previously set with
370  * gtk_cell_layout_set_attributes().
371  *
372  * Since: 2.4
373  */
374 void
375 gtk_cell_layout_clear_attributes (GtkCellLayout   *cell_layout,
376                                   GtkCellRenderer *cell)
377 {
378   GtkCellLayoutIface *iface;
379   GtkCellArea        *area;
380
381   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
382   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
383
384   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
385
386   if (iface->clear_attributes)
387     iface->clear_attributes (cell_layout, cell);
388   else
389     {
390       area = iface->get_area (cell_layout);
391       
392       if (area)
393         gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (area), cell);
394     }
395 }
396
397 /**
398  * gtk_cell_layout_reorder:
399  * @cell_layout: A #GtkCellLayout.
400  * @cell: A #GtkCellRenderer to reorder.
401  * @position: New position to insert @cell at.
402  *
403  * Re-inserts @cell at @position. Note that @cell has already to be packed
404  * into @cell_layout for this to function properly.
405  *
406  * Since: 2.4
407  */
408 void
409 gtk_cell_layout_reorder (GtkCellLayout   *cell_layout,
410                          GtkCellRenderer *cell,
411                          gint             position)
412 {
413   GtkCellLayoutIface *iface;
414   GtkCellArea        *area;
415
416   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
417   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
418
419   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
420
421   if (iface->reorder)
422     iface->reorder (cell_layout, cell, position);
423   else
424     {
425       area = iface->get_area (cell_layout);
426       
427       if (area)
428         gtk_cell_layout_reorder (GTK_CELL_LAYOUT (area), cell, position);
429     }
430 }
431
432 /**
433  * gtk_cell_layout_get_cells:
434  * @cell_layout: a #GtkCellLayout
435  * 
436  * Returns the cell renderers which have been added to @cell_layout.
437  *
438  * Return value: (element-type GtkCellRenderer) (transfer container): a list of cell renderers. The list, but not the
439  *   renderers has been newly allocated and should be freed with
440  *   g_list_free() when no longer needed.
441  *
442  * Since: 2.12
443  */
444 GList *
445 gtk_cell_layout_get_cells (GtkCellLayout *cell_layout)
446 {
447   GtkCellLayoutIface *iface;
448   GtkCellArea        *area;
449
450   g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL);
451
452   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);  
453   if (iface->get_cells)
454     return iface->get_cells (cell_layout);
455   else
456     {
457       area = iface->get_area (cell_layout);
458       
459       if (area)
460         return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
461     }
462
463   return NULL;
464 }
465
466 /**
467  * gtk_cell_layout_get_area:
468  * @cell_layout: a #GtkCellLayout
469  * 
470  * Returns the underlying #GtkCellArea which might be @cell_layout if called on a #GtkCellArea or
471  * might be %NULL if no #GtkCellArea is used by @cell_layout.
472  *
473  * Return value: (transfer none): a list of cell renderers. The list, but not the
474  *   renderers has been newly allocated and should be freed with
475  *   g_list_free() when no longer needed.
476  *
477  * Since: 3.0
478  */
479 GtkCellArea *
480 gtk_cell_layout_get_area (GtkCellLayout *cell_layout)
481 {
482   GtkCellLayoutIface *iface;
483
484   g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL);
485
486   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);  
487   if (iface->get_area)
488     return iface->get_area (cell_layout);
489
490   return NULL;
491 }
492
493 /* Attribute parsing */
494 typedef struct {
495   GtkCellLayout   *cell_layout;
496   GtkCellRenderer *renderer;
497   gchar           *attr_name;
498 } AttributesSubParserData;
499
500 static void
501 attributes_start_element (GMarkupParseContext *context,
502                           const gchar         *element_name,
503                           const gchar        **names,
504                           const gchar        **values,
505                           gpointer             user_data,
506                           GError             **error)
507 {
508   AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
509   guint i;
510
511   if (strcmp (element_name, "attribute") == 0)
512     {
513       for (i = 0; names[i]; i++)
514         if (strcmp (names[i], "name") == 0)
515           parser_data->attr_name = g_strdup (values[i]);
516     }
517   else if (strcmp (element_name, "attributes") == 0)
518     return;
519   else
520     g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
521 }
522
523 static void
524 attributes_text_element (GMarkupParseContext *context,
525                          const gchar         *text,
526                          gsize                text_len,
527                          gpointer             user_data,
528                          GError             **error)
529 {
530   AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
531   glong l;
532   gchar *endptr;
533   gchar *string;
534   
535   if (!parser_data->attr_name)
536     return;
537
538   string = g_strndup (text, text_len);
539   errno = 0;
540   l = g_ascii_strtoll (string, &endptr, 0);
541   if (errno || endptr == string)
542     {
543       g_set_error (error, 
544                    GTK_BUILDER_ERROR,
545                    GTK_BUILDER_ERROR_INVALID_VALUE,
546                    "Could not parse integer `%s'",
547                    string);
548       g_free (string);
549       return;
550     }
551   g_free (string);
552
553   gtk_cell_layout_add_attribute (parser_data->cell_layout,
554                                  parser_data->renderer,
555                                  parser_data->attr_name, l);
556   g_free (parser_data->attr_name);
557   parser_data->attr_name = NULL;
558 }
559
560 static const GMarkupParser attributes_parser =
561   {
562     attributes_start_element,
563     NULL,
564     attributes_text_element,
565   };
566
567
568 /* Cell packing parsing */
569 static void
570 gtk_cell_layout_buildable_set_cell_property (GtkCellArea     *area,
571                                              GtkBuilder      *builder,
572                                              GtkCellRenderer *cell,
573                                              gchar           *name,
574                                              const gchar     *value)
575 {
576   GParamSpec *pspec;
577   GValue gvalue = { 0, };
578   GError *error = NULL;
579
580   pspec = gtk_cell_area_class_find_cell_property (GTK_CELL_AREA_GET_CLASS (area), name);
581   if (!pspec)
582     {
583       g_warning ("%s does not have a property called %s",
584                  g_type_name (G_OBJECT_TYPE (area)), name);
585       return;
586     }
587
588   if (!gtk_builder_value_from_string (builder, pspec, value, &gvalue, &error))
589     {
590       g_warning ("Could not read property %s:%s with value %s of type %s: %s",
591                  g_type_name (G_OBJECT_TYPE (area)),
592                  name,
593                  value,
594                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
595                  error->message);
596       g_error_free (error);
597       return;
598     }
599
600   gtk_cell_area_cell_set_property (area, cell, name, &gvalue);
601   g_value_unset (&gvalue);
602 }
603
604 typedef struct {
605   GtkBuilder      *builder;
606   GtkCellLayout   *cell_layout;
607   GtkCellRenderer *renderer;
608   gchar           *cell_prop_name;
609   gchar           *context;
610   gboolean         translatable;
611 } CellPackingSubParserData;
612
613 static void
614 cell_packing_start_element (GMarkupParseContext *context,
615                             const gchar         *element_name,
616                             const gchar        **names,
617                             const gchar        **values,
618                             gpointer             user_data,
619                             GError             **error)
620 {
621   CellPackingSubParserData *parser_data = (CellPackingSubParserData*)user_data;
622   guint i;
623
624   if (strcmp (element_name, "property") == 0)
625     {
626       for (i = 0; names[i]; i++)
627         if (strcmp (names[i], "name") == 0)
628           parser_data->cell_prop_name = g_strdup (values[i]);
629         else if (strcmp (names[i], "translatable") == 0)
630           {
631             if (!_gtk_builder_boolean_from_string (values[i],
632                                                    &parser_data->translatable,
633                                                    error))
634               return;
635           }
636         else if (strcmp (names[i], "comments") == 0)
637           ; /* for translators */
638         else if (strcmp (names[i], "context") == 0)
639           parser_data->context = g_strdup (values[i]);
640         else
641           g_warning ("Unsupported attribute for GtkCellLayout Cell "
642                      "property: %s\n", names[i]);
643     }
644   else if (strcmp (element_name, "cell-packing") == 0)
645     return;
646   else
647     g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
648 }
649
650 static void
651 cell_packing_text_element (GMarkupParseContext *context,
652                            const gchar         *text,
653                            gsize                text_len,
654                            gpointer             user_data,
655                            GError             **error)
656 {
657   CellPackingSubParserData *parser_data = (CellPackingSubParserData*)user_data;
658   GtkCellArea *area;
659   gchar* value;
660
661   if (!parser_data->cell_prop_name)
662     return;
663
664   if (parser_data->translatable && text_len)
665     {
666       const gchar* domain;
667       domain = gtk_builder_get_translation_domain (parser_data->builder);
668
669       value = _gtk_builder_parser_translate (domain,
670                                              parser_data->context,
671                                              text);
672     }
673   else
674     {
675       value = g_strdup (text);
676     }
677
678   area = gtk_cell_layout_get_area (parser_data->cell_layout);
679
680   if (!area)
681     {
682       g_warning ("%s does not have an internal GtkCellArea class and cannot apply child cell properties",
683                  g_type_name (G_OBJECT_TYPE (parser_data->cell_layout)));
684       return;
685     }
686
687   gtk_cell_layout_buildable_set_cell_property (area, 
688                                                parser_data->builder,
689                                                parser_data->renderer,
690                                                parser_data->cell_prop_name,
691                                                value);
692
693   g_free (parser_data->cell_prop_name);
694   g_free (parser_data->context);
695   g_free (value);
696   parser_data->cell_prop_name = NULL;
697   parser_data->context = NULL;
698   parser_data->translatable = FALSE;
699 }
700
701 static const GMarkupParser cell_packing_parser =
702   {
703     cell_packing_start_element,
704     NULL,
705     cell_packing_text_element,
706   };
707
708 gboolean
709 _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable  *buildable,
710                                              GtkBuilder    *builder,
711                                              GObject       *child,
712                                              const gchar   *tagname,
713                                              GMarkupParser *parser,
714                                              gpointer      *data)
715 {
716   AttributesSubParserData  *attr_data;
717   CellPackingSubParserData *packing_data;
718
719   if (!child)
720     return FALSE;
721
722   if (strcmp (tagname, "attributes") == 0)
723     {
724       attr_data = g_slice_new0 (AttributesSubParserData);
725       attr_data->cell_layout = GTK_CELL_LAYOUT (buildable);
726       attr_data->renderer = GTK_CELL_RENDERER (child);
727       attr_data->attr_name = NULL;
728
729       *parser = attributes_parser;
730       *data = attr_data;
731       return TRUE;
732     }
733   else if (strcmp (tagname, "cell-packing") == 0)
734     {
735       packing_data = g_slice_new0 (CellPackingSubParserData);
736       packing_data->builder = builder;
737       packing_data->cell_layout = GTK_CELL_LAYOUT (buildable);
738       packing_data->renderer = GTK_CELL_RENDERER (child);
739
740       *parser = cell_packing_parser;
741       *data = packing_data;
742       return TRUE;
743     }
744
745   return FALSE;
746 }
747
748 void
749 _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
750                                            GtkBuilder   *builder,
751                                            GObject      *child,
752                                            const gchar  *tagname,
753                                            gpointer     *data)
754 {
755   AttributesSubParserData *attr_data;
756
757   if (strcmp (tagname, "attributes") == 0)
758     {
759       attr_data = (AttributesSubParserData*)data;
760       g_assert (!attr_data->attr_name);
761       g_slice_free (AttributesSubParserData, attr_data);
762       return;
763     }
764   else if (strcmp (tagname, "cell-packing") == 0)
765     {
766       g_slice_free (CellPackingSubParserData, (gpointer)data);
767       return;
768     }
769 }
770
771 void
772 _gtk_cell_layout_buildable_add_child (GtkBuildable      *buildable,
773                                       GtkBuilder        *builder,
774                                       GObject           *child,
775                                       const gchar       *type)
776 {
777   g_return_if_fail (GTK_IS_CELL_LAYOUT (buildable));
778   g_return_if_fail (GTK_IS_CELL_RENDERER (child));
779
780   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (buildable), GTK_CELL_RENDERER (child), FALSE);
781 }