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