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