]> Pileus Git - ~andy/gtk/blob - gtk/gtkcelllayout.c
Reduced code size in GtkTreeMenu by only implementing GtkCellLayout->get_area method...
[~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. 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         {
361           /* Ensure that the correct proxy object is sent to 'func' */
362           if (GTK_CELL_LAYOUT (area) != cell_layout)
363             _gtk_cell_area_set_cell_data_func_with_proxy (area, cell, 
364                                                           (GFunc)func, func_data, destroy, 
365                                                           cell_layout);
366           else
367             gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (area), cell, 
368                                                 func, func_data, destroy);
369         }
370     }
371 }
372
373 /**
374  * gtk_cell_layout_clear_attributes:
375  * @cell_layout: A #GtkCellLayout.
376  * @cell: A #GtkCellRenderer to clear the attribute mapping on.
377  *
378  * Clears all existing attributes previously set with
379  * gtk_cell_layout_set_attributes().
380  *
381  * Since: 2.4
382  */
383 void
384 gtk_cell_layout_clear_attributes (GtkCellLayout   *cell_layout,
385                                   GtkCellRenderer *cell)
386 {
387   GtkCellLayoutIface *iface;
388   GtkCellArea        *area;
389
390   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
391   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
392
393   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
394
395   if (iface->clear_attributes)
396     iface->clear_attributes (cell_layout, cell);
397   else
398     {
399       area = iface->get_area (cell_layout);
400       
401       if (area)
402         gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (area), cell);
403     }
404 }
405
406 /**
407  * gtk_cell_layout_reorder:
408  * @cell_layout: A #GtkCellLayout.
409  * @cell: A #GtkCellRenderer to reorder.
410  * @position: New position to insert @cell at.
411  *
412  * Re-inserts @cell at @position. Note that @cell has already to be packed
413  * into @cell_layout for this to function properly.
414  *
415  * Since: 2.4
416  */
417 void
418 gtk_cell_layout_reorder (GtkCellLayout   *cell_layout,
419                          GtkCellRenderer *cell,
420                          gint             position)
421 {
422   GtkCellLayoutIface *iface;
423   GtkCellArea        *area;
424
425   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
426   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
427
428   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
429
430   if (iface->reorder)
431     iface->reorder (cell_layout, cell, position);
432   else
433     {
434       area = iface->get_area (cell_layout);
435       
436       if (area)
437         gtk_cell_layout_reorder (GTK_CELL_LAYOUT (area), cell, position);
438     }
439 }
440
441 /**
442  * gtk_cell_layout_get_cells:
443  * @cell_layout: a #GtkCellLayout
444  * 
445  * Returns the cell renderers which have been added to @cell_layout.
446  *
447  * Return value: (element-type GtkCellRenderer) (transfer container): a list of cell renderers. The list, but not the
448  *   renderers has been newly allocated and should be freed with
449  *   g_list_free() when no longer needed.
450  *
451  * Since: 2.12
452  */
453 GList *
454 gtk_cell_layout_get_cells (GtkCellLayout *cell_layout)
455 {
456   GtkCellLayoutIface *iface;
457   GtkCellArea        *area;
458
459   g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL);
460
461   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);  
462   if (iface->get_cells)
463     return iface->get_cells (cell_layout);
464   else
465     {
466       area = iface->get_area (cell_layout);
467       
468       if (area)
469         return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
470     }
471
472   return NULL;
473 }
474
475 /**
476  * gtk_cell_layout_get_area:
477  * @cell_layout: a #GtkCellLayout
478  * 
479  * Returns the underlying #GtkCellArea which might be @cell_layout if called on a #GtkCellArea or
480  * might be %NULL if no #GtkCellArea is used by @cell_layout.
481  *
482  * Return value: (transfer none): a list of cell renderers. The list, but not the
483  *   renderers has been newly allocated and should be freed with
484  *   g_list_free() when no longer needed.
485  *
486  * Since: 3.0
487  */
488 GtkCellArea *
489 gtk_cell_layout_get_area (GtkCellLayout *cell_layout)
490 {
491   GtkCellLayoutIface *iface;
492
493   g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL);
494
495   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);  
496   if (iface->get_area)
497     return iface->get_area (cell_layout);
498
499   return NULL;
500 }
501
502 /* Attribute parsing */
503 typedef struct {
504   GtkCellLayout   *cell_layout;
505   GtkCellRenderer *renderer;
506   gchar           *attr_name;
507 } AttributesSubParserData;
508
509 static void
510 attributes_start_element (GMarkupParseContext *context,
511                           const gchar         *element_name,
512                           const gchar        **names,
513                           const gchar        **values,
514                           gpointer             user_data,
515                           GError             **error)
516 {
517   AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
518   guint i;
519
520   if (strcmp (element_name, "attribute") == 0)
521     {
522       for (i = 0; names[i]; i++)
523         if (strcmp (names[i], "name") == 0)
524           parser_data->attr_name = g_strdup (values[i]);
525     }
526   else if (strcmp (element_name, "attributes") == 0)
527     return;
528   else
529     g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
530 }
531
532 static void
533 attributes_text_element (GMarkupParseContext *context,
534                          const gchar         *text,
535                          gsize                text_len,
536                          gpointer             user_data,
537                          GError             **error)
538 {
539   AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
540   glong l;
541   gchar *endptr;
542   gchar *string;
543   
544   if (!parser_data->attr_name)
545     return;
546
547   string = g_strndup (text, text_len);
548   errno = 0;
549   l = g_ascii_strtoll (string, &endptr, 0);
550   if (errno || endptr == string)
551     {
552       g_set_error (error, 
553                    GTK_BUILDER_ERROR,
554                    GTK_BUILDER_ERROR_INVALID_VALUE,
555                    "Could not parse integer `%s'",
556                    string);
557       g_free (string);
558       return;
559     }
560   g_free (string);
561
562   gtk_cell_layout_add_attribute (parser_data->cell_layout,
563                                  parser_data->renderer,
564                                  parser_data->attr_name, l);
565   g_free (parser_data->attr_name);
566   parser_data->attr_name = NULL;
567 }
568
569 static const GMarkupParser attributes_parser =
570   {
571     attributes_start_element,
572     NULL,
573     attributes_text_element,
574   };
575
576
577 /* Cell packing parsing */
578 static void
579 gtk_cell_layout_buildable_set_cell_property (GtkCellArea     *area,
580                                              GtkBuilder      *builder,
581                                              GtkCellRenderer *cell,
582                                              gchar           *name,
583                                              const gchar     *value)
584 {
585   GParamSpec *pspec;
586   GValue gvalue = { 0, };
587   GError *error = NULL;
588
589   pspec = gtk_cell_area_class_find_cell_property (GTK_CELL_AREA_GET_CLASS (area), name);
590   if (!pspec)
591     {
592       g_warning ("%s does not have a property called %s",
593                  g_type_name (G_OBJECT_TYPE (area)), name);
594       return;
595     }
596
597   if (!gtk_builder_value_from_string (builder, pspec, value, &gvalue, &error))
598     {
599       g_warning ("Could not read property %s:%s with value %s of type %s: %s",
600                  g_type_name (G_OBJECT_TYPE (area)),
601                  name,
602                  value,
603                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
604                  error->message);
605       g_error_free (error);
606       return;
607     }
608
609   gtk_cell_area_cell_set_property (area, cell, name, &gvalue);
610   g_value_unset (&gvalue);
611 }
612
613 typedef struct {
614   GtkBuilder      *builder;
615   GtkCellLayout   *cell_layout;
616   GtkCellRenderer *renderer;
617   gchar           *cell_prop_name;
618   gchar           *context;
619   gboolean         translatable;
620 } CellPackingSubParserData;
621
622 static void
623 cell_packing_start_element (GMarkupParseContext *context,
624                             const gchar         *element_name,
625                             const gchar        **names,
626                             const gchar        **values,
627                             gpointer             user_data,
628                             GError             **error)
629 {
630   CellPackingSubParserData *parser_data = (CellPackingSubParserData*)user_data;
631   guint i;
632
633   if (strcmp (element_name, "property") == 0)
634     {
635       for (i = 0; names[i]; i++)
636         if (strcmp (names[i], "name") == 0)
637           parser_data->cell_prop_name = g_strdup (values[i]);
638         else if (strcmp (names[i], "translatable") == 0)
639           {
640             if (!_gtk_builder_boolean_from_string (values[i],
641                                                    &parser_data->translatable,
642                                                    error))
643               return;
644           }
645         else if (strcmp (names[i], "comments") == 0)
646           ; /* for translators */
647         else if (strcmp (names[i], "context") == 0)
648           parser_data->context = g_strdup (values[i]);
649         else
650           g_warning ("Unsupported attribute for GtkCellLayout Cell "
651                      "property: %s\n", names[i]);
652     }
653   else if (strcmp (element_name, "cell-packing") == 0)
654     return;
655   else
656     g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
657 }
658
659 static void
660 cell_packing_text_element (GMarkupParseContext *context,
661                            const gchar         *text,
662                            gsize                text_len,
663                            gpointer             user_data,
664                            GError             **error)
665 {
666   CellPackingSubParserData *parser_data = (CellPackingSubParserData*)user_data;
667   GtkCellArea *area;
668   gchar* value;
669
670   if (!parser_data->cell_prop_name)
671     return;
672
673   if (parser_data->translatable && text_len)
674     {
675       const gchar* domain;
676       domain = gtk_builder_get_translation_domain (parser_data->builder);
677
678       value = _gtk_builder_parser_translate (domain,
679                                              parser_data->context,
680                                              text);
681     }
682   else
683     {
684       value = g_strdup (text);
685     }
686
687   area = gtk_cell_layout_get_area (parser_data->cell_layout);
688
689   if (!area)
690     {
691       g_warning ("%s does not have an internal GtkCellArea class and cannot apply child cell properties",
692                  g_type_name (G_OBJECT_TYPE (parser_data->cell_layout)));
693       return;
694     }
695
696   gtk_cell_layout_buildable_set_cell_property (area, 
697                                                parser_data->builder,
698                                                parser_data->renderer,
699                                                parser_data->cell_prop_name,
700                                                value);
701
702   g_free (parser_data->cell_prop_name);
703   g_free (parser_data->context);
704   g_free (value);
705   parser_data->cell_prop_name = NULL;
706   parser_data->context = NULL;
707   parser_data->translatable = FALSE;
708 }
709
710 static const GMarkupParser cell_packing_parser =
711   {
712     cell_packing_start_element,
713     NULL,
714     cell_packing_text_element,
715   };
716
717 gboolean
718 _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable  *buildable,
719                                              GtkBuilder    *builder,
720                                              GObject       *child,
721                                              const gchar   *tagname,
722                                              GMarkupParser *parser,
723                                              gpointer      *data)
724 {
725   AttributesSubParserData  *attr_data;
726   CellPackingSubParserData *packing_data;
727
728   if (!child)
729     return FALSE;
730
731   if (strcmp (tagname, "attributes") == 0)
732     {
733       attr_data = g_slice_new0 (AttributesSubParserData);
734       attr_data->cell_layout = GTK_CELL_LAYOUT (buildable);
735       attr_data->renderer = GTK_CELL_RENDERER (child);
736       attr_data->attr_name = NULL;
737
738       *parser = attributes_parser;
739       *data = attr_data;
740       return TRUE;
741     }
742   else if (strcmp (tagname, "cell-packing") == 0)
743     {
744       packing_data = g_slice_new0 (CellPackingSubParserData);
745       packing_data->builder = builder;
746       packing_data->cell_layout = GTK_CELL_LAYOUT (buildable);
747       packing_data->renderer = GTK_CELL_RENDERER (child);
748
749       *parser = cell_packing_parser;
750       *data = packing_data;
751       return TRUE;
752     }
753
754   return FALSE;
755 }
756
757 gboolean
758 _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
759                                            GtkBuilder   *builder,
760                                            GObject      *child,
761                                            const gchar  *tagname,
762                                            gpointer     *data)
763 {
764   AttributesSubParserData *attr_data;
765
766   if (strcmp (tagname, "attributes") == 0)
767     {
768       attr_data = (AttributesSubParserData*)data;
769       g_assert (!attr_data->attr_name);
770       g_slice_free (AttributesSubParserData, attr_data);
771       return TRUE;
772     }
773   else if (strcmp (tagname, "cell-packing") == 0)
774     {
775       g_slice_free (CellPackingSubParserData, (gpointer)data);
776       return TRUE;
777     }
778   return FALSE;
779 }
780
781 void
782 _gtk_cell_layout_buildable_add_child (GtkBuildable      *buildable,
783                                       GtkBuilder        *builder,
784                                       GObject           *child,
785                                       const gchar       *type)
786 {
787   g_return_if_fail (GTK_IS_CELL_LAYOUT (buildable));
788   g_return_if_fail (GTK_IS_CELL_RENDERER (child));
789
790   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (buildable), GTK_CELL_RENDERER (child), FALSE);
791 }