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