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.
24 #include "gtkcelllayout.h"
29 gtk_cell_layout_get_type (void)
31 static GType cell_layout_type = 0;
33 if (! cell_layout_type)
35 const GTypeInfo cell_layout_info =
37 sizeof (GtkCellLayoutIface),
49 g_type_register_static (G_TYPE_INTERFACE, I_("GtkCellLayout"),
50 &cell_layout_info, 0);
52 g_type_interface_add_prerequisite (cell_layout_type, G_TYPE_OBJECT);
55 return cell_layout_type;
59 * gtk_cell_layout_pack_start:
60 * @cell_layout: A #GtkCellLayout.
61 * @cell: A #GtkCellRenderer.
62 * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout.
64 * Packs the @cell into the beginning of @cell_layout. If @expand is %FALSE,
65 * then the @cell is allocated no more space than it needs. Any unused space
66 * is divided evenly between cells for which @expand is %TRUE.
68 * Note that reusing the same cell renderer is not supported.
73 gtk_cell_layout_pack_start (GtkCellLayout *cell_layout,
74 GtkCellRenderer *cell,
77 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
78 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
80 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_start) (cell_layout,
86 * gtk_cell_layout_pack_end:
87 * @cell_layout: A #GtkCellLayout.
88 * @cell: A #GtkCellRenderer.
89 * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout.
91 * Adds the @cell to the end of @cell_layout. If @expand is %FALSE, then the
92 * @cell is allocated no more space than it needs. Any unused space is
93 * divided evenly between cells for which @expand is %TRUE.
95 * Note that reusing the same cell renderer is not supported.
100 gtk_cell_layout_pack_end (GtkCellLayout *cell_layout,
101 GtkCellRenderer *cell,
104 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
105 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
107 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_end) (cell_layout,
113 * gtk_cell_layout_clear:
114 * @cell_layout: A #GtkCellLayout.
116 * Unsets all the mappings on all renderers on @cell_layout and
117 * removes all renderers from @cell_layout.
122 gtk_cell_layout_clear (GtkCellLayout *cell_layout)
124 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
126 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear) (cell_layout);
130 gtk_cell_layout_set_attributesv (GtkCellLayout *cell_layout,
131 GtkCellRenderer *cell,
136 GtkCellLayoutIface *iface;
138 attribute = va_arg (args, gchar *);
140 iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
142 (* iface->clear_attributes) (cell_layout, cell);
144 while (attribute != NULL)
146 column = va_arg (args, gint);
147 (* iface->add_attribute) (cell_layout, cell, attribute, column);
148 attribute = va_arg (args, gchar *);
153 * gtk_cell_layout_set_attributes:
154 * @cell_layout: A #GtkCellLayout.
155 * @cell: A #GtkCellRenderer.
156 * @Varargs: A %NULL-terminated list of attributes.
158 * Sets the attributes in list as the attributes of @cell_layout. The
159 * attributes should be in attribute/column order, as in
160 * gtk_cell_layout_add_attribute(). All existing attributes are removed, and
161 * replaced with the new attributes.
166 gtk_cell_layout_set_attributes (GtkCellLayout *cell_layout,
167 GtkCellRenderer *cell,
172 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
173 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
175 va_start (args, cell);
176 gtk_cell_layout_set_attributesv (cell_layout, cell, args);
181 * gtk_cell_layout_add_attribute:
182 * @cell_layout: A #GtkCellLayout.
183 * @cell: A #GtkCellRenderer.
184 * @attribute: An attribute on the renderer.
185 * @column: The column position on the model to get the attribute from.
187 * Adds an attribute mapping to the list in @cell_layout. The @column is the
188 * column of the model to get a value from, and the @attribute is the
189 * parameter on @cell to be set from the value. So for example if column 2
190 * of the model contains strings, you could have the "text" attribute of a
191 * #GtkCellRendererText get its values from column 2.
196 gtk_cell_layout_add_attribute (GtkCellLayout *cell_layout,
197 GtkCellRenderer *cell,
198 const gchar *attribute,
201 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
202 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
203 g_return_if_fail (attribute != NULL);
204 g_return_if_fail (column >= 0);
206 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->add_attribute) (cell_layout,
213 * gtk_cell_layout_set_cell_data_func:
214 * @cell_layout: A #GtkCellLayout.
215 * @cell: A #GtkCellRenderer.
216 * @func: The #GtkCellLayoutDataFunc to use.
217 * @func_data: The user data for @func.
218 * @destroy: The destroy notification for @func_data.
220 * Sets the #GtkCellLayoutDataFunc to use for @cell_layout. This function
221 * is used instead of the standard attributes mapping for setting the
222 * column value, and should set the value of @cell_layout's cell renderer(s)
223 * as appropriate. @func may be %NULL to remove and older one.
228 gtk_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
229 GtkCellRenderer *cell,
230 GtkCellLayoutDataFunc func,
232 GDestroyNotify destroy)
234 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
235 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
237 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->set_cell_data_func) (cell_layout,
245 * gtk_cell_layout_clear_attributes:
246 * @cell_layout: A #GtkCellLayout.
247 * @cell: A #GtkCellRenderer to clear the attribute mapping on.
249 * Clears all existing attributes previously set with
250 * gtk_cell_layout_set_attributes().
255 gtk_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
256 GtkCellRenderer *cell)
258 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
259 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
261 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear_attributes) (cell_layout,
266 * gtk_cell_layout_reorder:
267 * @cell_layout: A #GtkCellLayout.
268 * @cell: A #GtkCellRenderer to reorder.
269 * @position: New position to insert @cell at.
271 * Re-inserts @cell at @position. Note that @cell has already to be packed
272 * into @cell_layout for this to function properly.
277 gtk_cell_layout_reorder (GtkCellLayout *cell_layout,
278 GtkCellRenderer *cell,
281 g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
282 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
284 (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->reorder) (cell_layout,
290 * gtk_cell_layout_get_cells:
291 * @cell_layout: a #GtkCellLayout
293 * Returns the cell renderers which have been added to @cell_layout.
295 * Return value: (element-type GtkCellRenderer) (transfer container): a list of cell renderers. The list, but not the
296 * renderers has been newly allocated and should be freed with
297 * g_list_free() when no longer needed.
302 gtk_cell_layout_get_cells (GtkCellLayout *cell_layout)
304 GtkCellLayoutIface *iface;
306 g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL);
308 iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
309 if (iface->get_cells)
310 return iface->get_cells (cell_layout);
316 GtkCellLayout *cell_layout;
317 GtkCellRenderer *renderer;
319 } AttributesSubParserData;
322 attributes_start_element (GMarkupParseContext *context,
323 const gchar *element_name,
325 const gchar **values,
329 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
332 if (strcmp (element_name, "attribute") == 0)
334 for (i = 0; names[i]; i++)
335 if (strcmp (names[i], "name") == 0)
336 parser_data->attr_name = g_strdup (values[i]);
338 else if (strcmp (element_name, "attributes") == 0)
341 g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
345 attributes_text_element (GMarkupParseContext *context,
351 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
356 if (!parser_data->attr_name)
360 string = g_strndup (text, text_len);
361 l = strtol (string, &endptr, 0);
362 if (errno || endptr == string)
366 GTK_BUILDER_ERROR_INVALID_VALUE,
367 "Could not parse integer `%s'",
374 gtk_cell_layout_add_attribute (parser_data->cell_layout,
375 parser_data->renderer,
376 parser_data->attr_name, l);
377 g_free (parser_data->attr_name);
378 parser_data->attr_name = NULL;
381 static const GMarkupParser attributes_parser =
383 attributes_start_element,
385 attributes_text_element,
389 _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable *buildable,
392 const gchar *tagname,
393 GMarkupParser *parser,
396 AttributesSubParserData *parser_data;
401 if (strcmp (tagname, "attributes") == 0)
403 parser_data = g_slice_new0 (AttributesSubParserData);
404 parser_data->cell_layout = GTK_CELL_LAYOUT (buildable);
405 parser_data->renderer = GTK_CELL_RENDERER (child);
406 parser_data->attr_name = NULL;
408 *parser = attributes_parser;
417 _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
420 const gchar *tagname,
423 AttributesSubParserData *parser_data;
425 parser_data = (AttributesSubParserData*)data;
426 g_assert (!parser_data->attr_name);
427 g_slice_free (AttributesSubParserData, parser_data);
431 _gtk_cell_layout_buildable_add_child (GtkBuildable *buildable,
436 GtkCellLayoutIface *iface;
438 g_return_if_fail (GTK_IS_CELL_LAYOUT (buildable));
439 g_return_if_fail (GTK_IS_CELL_RENDERER (child));
441 iface = GTK_CELL_LAYOUT_GET_IFACE (buildable);
442 g_return_if_fail (iface->pack_start != NULL);
443 iface->pack_start (GTK_CELL_LAYOUT (buildable), GTK_CELL_RENDERER (child), FALSE);
446 #define __GTK_CELL_LAYOUT_C__
447 #include "gtkaliasdef.c"