2 * Copyright (C) 2003 Kristian Rietveld <kris@gtk.org>
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.
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.
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.
23 #include "gtkcelllayout.h"
28 gtk_cell_layout_get_type (void)
30 static GType cell_layout_type = 0;
32 if (! cell_layout_type)
34 const GTypeInfo cell_layout_info =
36 sizeof (GtkCellLayoutIface),
48 g_type_register_static (G_TYPE_INTERFACE, I_("GtkCellLayout"),
49 &cell_layout_info, 0);
51 g_type_interface_add_prerequisite (cell_layout_type, G_TYPE_OBJECT);
54 return cell_layout_type;
58 * gtk_cell_layout_pack_start:
59 * @cell_layout: A #GtkCellLayout.
60 * @cell: A #GtkCellRenderer.
61 * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout.
63 * Packs the @cell into the beginning of @cell_layout. If @expand is %FALSE,
64 * then the @cell is allocated no more space than it needs. Any unused space
65 * is divided evenly between cells for which @expand is %TRUE.
67 * Note that reusing the same cell renderer is not supported.
72 gtk_cell_layout_pack_start (GtkCellLayout *cell_layout,
73 GtkCellRenderer *cell,
76 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
77 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
79 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_start) (cell_layout,
85 * gtk_cell_layout_pack_end:
86 * @cell_layout: A #GtkCellLayout.
87 * @cell: A #GtkCellRenderer.
88 * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout.
90 * Adds the @cell to the end of @cell_layout. If @expand is %FALSE, then the
91 * @cell is allocated no more space than it needs. Any unused space is
92 * divided evenly between cells for which @expand is %TRUE.
94 * Note that reusing the same cell renderer is not supported.
99 gtk_cell_layout_pack_end (GtkCellLayout *cell_layout,
100 GtkCellRenderer *cell,
103 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
104 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
106 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_end) (cell_layout,
112 * gtk_cell_layout_clear:
113 * @cell_layout: A #GtkCellLayout.
115 * Unsets all the mappings on all renderers on @cell_layout and
116 * removes all renderers from @cell_layout.
121 gtk_cell_layout_clear (GtkCellLayout *cell_layout)
123 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
125 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear) (cell_layout);
129 gtk_cell_layout_set_attributesv (GtkCellLayout *cell_layout,
130 GtkCellRenderer *cell,
135 GtkCellLayoutIface *iface;
137 attribute = va_arg (args, gchar *);
139 iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
141 (* iface->clear_attributes) (cell_layout, cell);
143 while (attribute != NULL)
145 column = va_arg (args, gint);
146 (* iface->add_attribute) (cell_layout, cell, attribute, column);
147 attribute = va_arg (args, gchar *);
152 * gtk_cell_layout_set_attributes:
153 * @cell_layout: A #GtkCellLayout.
154 * @cell: A #GtkCellRenderer.
155 * @Varargs: A %NULL-terminated list of attributes.
157 * Sets the attributes in list as the attributes of @cell_layout. The
158 * attributes should be in attribute/column order, as in
159 * gtk_cell_layout_add_attribute(). All existing attributes are removed, and
160 * replaced with the new attributes.
165 gtk_cell_layout_set_attributes (GtkCellLayout *cell_layout,
166 GtkCellRenderer *cell,
171 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
172 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
174 va_start (args, cell);
175 gtk_cell_layout_set_attributesv (cell_layout, cell, args);
180 * gtk_cell_layout_add_attribute:
181 * @cell_layout: A #GtkCellLayout.
182 * @cell: A #GtkCellRenderer.
183 * @attribute: An attribute on the renderer.
184 * @column: The column position on the model to get the attribute from.
186 * Adds an attribute mapping to the list in @cell_layout. The @column is the
187 * column of the model to get a value from, and the @attribute is the
188 * parameter on @cell to be set from the value. So for example if column 2
189 * of the model contains strings, you could have the "text" attribute of a
190 * #GtkCellRendererText get its values from column 2.
195 gtk_cell_layout_add_attribute (GtkCellLayout *cell_layout,
196 GtkCellRenderer *cell,
197 const gchar *attribute,
200 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
201 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
202 g_return_if_fail (attribute != NULL);
203 g_return_if_fail (column >= 0);
205 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->add_attribute) (cell_layout,
212 * gtk_cell_layout_set_cell_data_func:
213 * @cell_layout: A #GtkCellLayout.
214 * @cell: A #GtkCellRenderer.
215 * @func: The #GtkCellLayoutDataFunc to use.
216 * @func_data: The user data for @func.
217 * @destroy: The destroy notification for @func_data.
219 * Sets the #GtkCellLayoutDataFunc to use for @cell_layout. This function
220 * is used instead of the standard attributes mapping for setting the
221 * column value, and should set the value of @cell_layout's cell renderer(s)
222 * as appropriate. @func may be %NULL to remove and older one.
227 gtk_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
228 GtkCellRenderer *cell,
229 GtkCellLayoutDataFunc func,
231 GDestroyNotify destroy)
233 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
234 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
236 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->set_cell_data_func) (cell_layout,
244 * gtk_cell_layout_clear_attributes:
245 * @cell_layout: A #GtkCellLayout.
246 * @cell: A #GtkCellRenderer to clear the attribute mapping on.
248 * Clears all existing attributes previously set with
249 * gtk_cell_layout_set_attributes().
254 gtk_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
255 GtkCellRenderer *cell)
257 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
258 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
260 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear_attributes) (cell_layout,
265 * gtk_cell_layout_reorder:
266 * @cell_layout: A #GtkCellLayout.
267 * @cell: A #GtkCellRenderer to reorder.
268 * @position: New position to insert @cell at.
270 * Re-inserts @cell at @position. Note that @cell has already to be packed
271 * into @cell_layout for this to function properly.
276 gtk_cell_layout_reorder (GtkCellLayout *cell_layout,
277 GtkCellRenderer *cell,
280 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
281 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
283 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->reorder) (cell_layout,
289 * gtk_cell_layout_get_cells:
290 * @cell_layout: a #GtkCellLayout
292 * Returns the cell renderers which have been added to @cell_layout.
294 * Return value: a list of cell renderers. The list, but not the
295 * renderers has been newly allocated and should be freed with
296 * g_list_free() when no longer needed.
301 gtk_cell_layout_get_cells (GtkCellLayout *cell_layout)
303 GtkCellLayoutIface *iface;
305 g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL);
307 iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
308 if (iface->get_cells)
309 return iface->get_cells (cell_layout);
315 GtkCellLayout *cell_layout;
316 GtkCellRenderer *renderer;
318 } AttributesSubParserData;
321 attributes_start_element (GMarkupParseContext *context,
322 const gchar *element_name,
324 const gchar **values,
328 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
331 if (strcmp (element_name, "attribute") == 0)
332 for (i = 0; names[i]; i++)
333 if (strcmp (names[i], "name") == 0)
334 parser_data->attr_name = g_strdup (values[i]);
335 else if (strcmp (element_name, "attributes") == 0)
338 g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
342 attributes_text_element (GMarkupParseContext *context,
348 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
350 if (!parser_data->attr_name)
352 gtk_cell_layout_add_attribute (parser_data->cell_layout,
353 parser_data->renderer,
354 parser_data->attr_name, atoi (text));
355 g_free (parser_data->attr_name);
356 parser_data->attr_name = NULL;
359 static const GMarkupParser attributes_parser =
361 attributes_start_element,
363 attributes_text_element,
367 _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable *buildable,
370 const gchar *tagname,
371 GMarkupParser *parser,
374 AttributesSubParserData *parser_data;
379 if (strcmp (tagname, "attributes") == 0)
381 parser_data = g_slice_new0 (AttributesSubParserData);
382 parser_data->cell_layout = GTK_CELL_LAYOUT (buildable);
383 parser_data->renderer = GTK_CELL_RENDERER (child);
384 parser_data->attr_name = NULL;
386 *parser = attributes_parser;
395 _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
398 const gchar *tagname,
401 AttributesSubParserData *parser_data;
403 parser_data = (AttributesSubParserData*)data;
404 g_assert (!parser_data->attr_name);
405 g_slice_free (AttributesSubParserData, parser_data);
409 _gtk_cell_layout_buildable_add (GtkBuildable *buildable,
414 GtkCellLayoutIface *iface;
416 g_return_if_fail (GTK_IS_CELL_LAYOUT (buildable));
417 g_return_if_fail (GTK_IS_CELL_RENDERER (child));
419 iface = GTK_CELL_LAYOUT_GET_IFACE (buildable);
420 g_return_if_fail (iface->pack_end != NULL);
421 iface->pack_end (GTK_CELL_LAYOUT (buildable), GTK_CELL_RENDERER (child), FALSE);
424 #define __GTK_CELL_LAYOUT_C__
425 #include "gtkaliasdef.c"