]> Pileus Git - ~andy/gtk/blob - gtk/gtkcelllayout.c
New function to get the cell renderers of a cell layout.
[~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 #include <config.h>
21 #include "gtkcelllayout.h"
22 #include "gtkintl.h"
23 #include "gtkalias.h"
24
25 GType
26 gtk_cell_layout_get_type (void)
27 {
28   static GType cell_layout_type = 0;
29
30   if (! cell_layout_type)
31     {
32       const GTypeInfo cell_layout_info =
33       {
34         sizeof (GtkCellLayoutIface),
35         NULL,
36         NULL,
37         NULL,
38         NULL,
39         NULL,
40         0,
41         0,
42         NULL
43       };
44
45       cell_layout_type =
46         g_type_register_static (G_TYPE_INTERFACE, I_("GtkCellLayout"),
47                                 &cell_layout_info, 0);
48
49       g_type_interface_add_prerequisite (cell_layout_type, G_TYPE_OBJECT);
50     }
51
52   return cell_layout_type;
53 }
54
55 /**
56  * gtk_cell_layout_pack_start:
57  * @cell_layout: A #GtkCellLayout.
58  * @cell: A #GtkCellRenderer.
59  * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout.
60  *
61  * Packs the @cell into the beginning of @cell_layout. If @expand is %FALSE,
62  * then the @cell is allocated no more space than it needs. Any unused space
63  * is divided evenly between cells for which @expand is %TRUE.
64  *
65  * Note that reusing the same cell renderer is not supported. 
66  *
67  * Since: 2.4
68  */
69 void
70 gtk_cell_layout_pack_start (GtkCellLayout   *cell_layout,
71                             GtkCellRenderer *cell,
72                             gboolean         expand)
73 {
74   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
75   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
76
77   (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_start) (cell_layout,
78                                                            cell,
79                                                            expand);
80 }
81
82 /**
83  * gtk_cell_layout_pack_end:
84  * @cell_layout: A #GtkCellLayout.
85  * @cell: A #GtkCellRenderer.
86  * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout.
87  *
88  * Adds the @cell to the end of @cell_layout. If @expand is %FALSE, then the
89  * @cell is allocated no more space than it needs. Any unused space is
90  * divided evenly between cells for which @expand is %TRUE.
91  *
92  * Note that reusing the same cell renderer is not supported. 
93  *
94  * Since: 2.4
95  */
96 void
97 gtk_cell_layout_pack_end (GtkCellLayout   *cell_layout,
98                           GtkCellRenderer *cell,
99                           gboolean         expand)
100 {
101   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
102   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
103
104   (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_end) (cell_layout,
105                                                          cell,
106                                                          expand);
107 }
108
109 /**
110  * gtk_cell_layout_clear:
111  * @cell_layout: A #GtkCellLayout.
112  *
113  * Unsets all the mappings on all renderers on @cell_layout and
114  * removes all renderers from @cell_layout.
115  *
116  * Since: 2.4
117  */
118 void
119 gtk_cell_layout_clear (GtkCellLayout *cell_layout)
120 {
121   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
122
123   (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear) (cell_layout);
124 }
125
126 static void
127 gtk_cell_layout_set_attributesv (GtkCellLayout   *cell_layout,
128                                  GtkCellRenderer *cell,
129                                  va_list          args)
130 {
131   gchar *attribute;
132   gint column;
133   GtkCellLayoutIface *iface;
134
135   attribute = va_arg (args, gchar *);
136
137   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);
138
139   (* iface->clear_attributes) (cell_layout, cell);
140
141   while (attribute != NULL)
142     {
143       column = va_arg (args, gint);
144       (* iface->add_attribute) (cell_layout, cell, attribute, column);
145       attribute = va_arg (args, gchar *);
146     }
147 }
148
149 /**
150  * gtk_cell_layout_set_attributes:
151  * @cell_layout: A #GtkCellLayout.
152  * @cell: A #GtkCellRenderer.
153  * @Varargs: A %NULL-terminated list of attributes.
154  *
155  * Sets the attributes in list as the attributes of @cell_layout. The
156  * attributes should be in attribute/column order, as in
157  * gtk_cell_layout_add_attribute(). All existing attributes are removed, and
158  * replaced with the new attributes.
159  *
160  * Since: 2.4
161  */
162 void
163 gtk_cell_layout_set_attributes (GtkCellLayout   *cell_layout,
164                                 GtkCellRenderer *cell,
165                                 ...)
166 {
167   va_list args;
168
169   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
170   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
171
172   va_start (args, cell);
173   gtk_cell_layout_set_attributesv (cell_layout, cell, args);
174   va_end (args);
175 }
176
177 /**
178  * gtk_cell_layout_add_attribute:
179  * @cell_layout: A #GtkCellLayout.
180  * @cell: A #GtkCellRenderer.
181  * @attribute: An attribute on the renderer.
182  * @column: The column position on the model to get the attribute from.
183  *
184  * Adds an attribute mapping to the list in @cell_layout. The @column is the
185  * column of the model to get a value from, and the @attribute is the
186  * parameter on @cell to be set from the value. So for example if column 2
187  * of the model contains strings, you could have the "text" attribute of a
188  * #GtkCellRendererText get its values from column 2.
189  *
190  * Since: 2.4
191  */
192 void
193 gtk_cell_layout_add_attribute (GtkCellLayout   *cell_layout,
194                                GtkCellRenderer *cell,
195                                const gchar     *attribute,
196                                gint             column)
197 {
198   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
199   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
200   g_return_if_fail (attribute != NULL);
201   g_return_if_fail (column >= 0);
202
203   (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->add_attribute) (cell_layout,
204                                                               cell,
205                                                               attribute,
206                                                               column);
207 }
208
209 /**
210  * gtk_cell_layout_set_cell_data_func:
211  * @cell_layout: A #GtkCellLayout.
212  * @cell: A #GtkCellRenderer.
213  * @func: The #GtkCellLayoutDataFunc to use.
214  * @func_data: The user data for @func.
215  * @destroy: The destroy notification for @func_data.
216  *
217  * Sets the #GtkCellLayoutDataFunc to use for @cell_layout. This function
218  * is used instead of the standard attributes mapping for setting the
219  * column value, and should set the value of @cell_layout's cell renderer(s)
220  * as appropriate. @func may be %NULL to remove and older one.
221  *
222  * Since: 2.4
223  */
224 void
225 gtk_cell_layout_set_cell_data_func (GtkCellLayout         *cell_layout,
226                                     GtkCellRenderer       *cell,
227                                     GtkCellLayoutDataFunc  func,
228                                     gpointer               func_data,
229                                     GDestroyNotify         destroy)
230 {
231   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
232   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
233
234   (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->set_cell_data_func) (cell_layout,
235                                                                    cell,
236                                                                    func,
237                                                                    func_data,
238                                                                    destroy);
239 }
240
241 /**
242  * gtk_cell_layout_clear_attributes:
243  * @cell_layout: A #GtkCellLayout.
244  * @cell: A #GtkCellRenderer to clear the attribute mapping on.
245  *
246  * Clears all existing attributes previously set with
247  * gtk_cell_layout_set_attributes().
248  *
249  * Since: 2.4
250  */
251 void
252 gtk_cell_layout_clear_attributes (GtkCellLayout   *cell_layout,
253                                   GtkCellRenderer *cell)
254 {
255   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
256   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
257
258   (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear_attributes) (cell_layout,
259                                                                  cell);
260 }
261
262 /**
263  * gtk_cell_layout_reorder:
264  * @cell_layout: A #GtkCellLayout.
265  * @cell: A #GtkCellRenderer to reorder.
266  * @position: New position to insert @cell at.
267  *
268  * Re-inserts @cell at @position. Note that @cell has already to be packed
269  * into @cell_layout for this to function properly.
270  *
271  * Since: 2.4
272  */
273 void
274 gtk_cell_layout_reorder (GtkCellLayout   *cell_layout,
275                          GtkCellRenderer *cell,
276                          gint             position)
277 {
278   g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout));
279   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
280
281   (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->reorder) (cell_layout,
282                                                         cell,
283                                                         position);
284 }
285
286 /**
287  * gtk_cell_layout_get_cells:
288  * @cell_layout: a #GtkCellLayout
289  * 
290  * Returns the cell renderers which have been added to @cell_layout.
291  *
292  * Return value: a list of cell renderers. The list, but not the
293  *   renderers has been newly allocated and should be freed with
294  *   g_list_free() when no longer needed.
295  * 
296  * Since: 2.12
297  */
298 GList *
299 gtk_cell_layout_get_cells (GtkCellLayout *cell_layout)
300 {
301   GtkCellLayoutIface *iface;
302
303   g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL);
304
305   iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout);  
306   if (iface->get_cells)
307     return iface->get_cells (cell_layout);
308
309   return NULL;
310 }
311
312 #define __GTK_CELL_LAYOUT_C__
313 #include "gtkaliasdef.c"