1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.CellLayoutT;
26 
27 public  import glib.ListG;
28 public  import glib.Str;
29 public  import gobject.ObjectG;
30 public  import gtk.CellArea;
31 public  import gtk.CellRenderer;
32 public  import gtk.c.functions;
33 public  import gtk.c.types;
34 public  import gtkc.gtktypes;
35 
36 
37 /**
38  * #GtkCellLayout is an interface to be implemented by all objects which
39  * want to provide a #GtkTreeViewColumn like API for packing cells,
40  * setting attributes and data funcs.
41  * 
42  * One of the notable features provided by implementations of
43  * GtkCellLayout are attributes. Attributes let you set the properties
44  * in flexible ways. They can just be set to constant values like regular
45  * properties. But they can also be mapped to a column of the underlying
46  * tree model with gtk_cell_layout_set_attributes(), which means that the value
47  * of the attribute can change from cell to cell as they are rendered by
48  * the cell renderer. Finally, it is possible to specify a function with
49  * gtk_cell_layout_set_cell_data_func() that is called to determine the
50  * value of the attribute for each cell that is rendered.
51  * 
52  * # GtkCellLayouts as GtkBuildable
53  * 
54  * Implementations of GtkCellLayout which also implement the GtkBuildable
55  * interface (#GtkCellView, #GtkIconView, #GtkComboBox,
56  * #GtkEntryCompletion, #GtkTreeViewColumn) accept GtkCellRenderer objects
57  * as <child> elements in UI definitions. They support a custom <attributes>
58  * element for their children, which can contain multiple <attribute>
59  * elements. Each <attribute> element has a name attribute which specifies
60  * a property of the cell renderer; the content of the element is the
61  * attribute value.
62  * 
63  * This is an example of a UI definition fragment specifying attributes:
64  * |[
65  * <object class="GtkCellView">
66  * <child>
67  * <object class="GtkCellRendererText"/>
68  * <attributes>
69  * <attribute name="text">0</attribute>
70  * </attributes>
71  * </child>"
72  * </object>
73  * ]|
74  * 
75  * Furthermore for implementations of GtkCellLayout that use a #GtkCellArea
76  * to lay out cells (all GtkCellLayouts in GTK+ use a GtkCellArea)
77  * [cell properties][cell-properties] can also be defined in the format by
78  * specifying the custom <cell-packing> attribute which can contain multiple
79  * <property> elements defined in the normal way.
80  * 
81  * Here is a UI definition fragment specifying cell properties:
82  * 
83  * |[
84  * <object class="GtkTreeViewColumn">
85  * <child>
86  * <object class="GtkCellRendererText"/>
87  * <cell-packing>
88  * <property name="align">True</property>
89  * <property name="expand">False</property>
90  * </cell-packing>
91  * </child>"
92  * </object>
93  * ]|
94  * 
95  * # Subclassing GtkCellLayout implementations
96  * 
97  * When subclassing a widget that implements #GtkCellLayout like
98  * #GtkIconView or #GtkComboBox, there are some considerations related
99  * to the fact that these widgets internally use a #GtkCellArea.
100  * The cell area is exposed as a construct-only property by these
101  * widgets. This means that it is possible to e.g. do
102  * 
103  * |[<!-- language="C" -->
104  * combo = g_object_new (GTK_TYPE_COMBO_BOX, "cell-area", my_cell_area, NULL);
105  * ]|
106  * 
107  * to use a custom cell area with a combo box. But construct properties
108  * are only initialized after instance init()
109  * functions have run, which means that using functions which rely on
110  * the existence of the cell area in your subclass’ init() function will
111  * cause the default cell area to be instantiated. In this case, a provided
112  * construct property value will be ignored (with a warning, to alert
113  * you to the problem).
114  * 
115  * |[<!-- language="C" -->
116  * static void
117  * my_combo_box_init (MyComboBox *b)
118  * {
119  * GtkCellRenderer *cell;
120  * 
121  * cell = gtk_cell_renderer_pixbuf_new ();
122  * // The following call causes the default cell area for combo boxes,
123  * // a GtkCellAreaBox, to be instantiated
124  * gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (b), cell, FALSE);
125  * ...
126  * }
127  * 
128  * GtkWidget *
129  * my_combo_box_new (GtkCellArea *area)
130  * {
131  * // This call is going to cause a warning about area being ignored
132  * return g_object_new (MY_TYPE_COMBO_BOX, "cell-area", area, NULL);
133  * }
134  * ]|
135  * 
136  * If supporting alternative cell areas with your derived widget is
137  * not important, then this does not have to concern you. If you want
138  * to support alternative cell areas, you can do so by moving the
139  * problematic calls out of init() and into a constructor()
140  * for your class.
141  */
142 public template CellLayoutT(TStruct)
143 {
144 	/** Get the main Gtk struct */
145 	public GtkCellLayout* getCellLayoutStruct(bool transferOwnership = false)
146 	{
147 		if (transferOwnership)
148 			ownedRef = false;
149 		return cast(GtkCellLayout*)getStruct();
150 	}
151 
152 
153 	/**
154 	 * Adds an attribute mapping to the list in @cell_layout.
155 	 *
156 	 * The @column is the column of the model to get a value from, and the
157 	 * @attribute is the parameter on @cell to be set from the value. So for
158 	 * example if column 2 of the model contains strings, you could have the
159 	 * “text” attribute of a #GtkCellRendererText get its values from column 2.
160 	 *
161 	 * Params:
162 	 *     cell = a #GtkCellRenderer
163 	 *     attribute = an attribute on the renderer
164 	 *     column = the column position on the model to get the attribute from
165 	 *
166 	 * Since: 2.4
167 	 */
168 	public void addAttribute(CellRenderer cell, string attribute, int column)
169 	{
170 		gtk_cell_layout_add_attribute(getCellLayoutStruct(), (cell is null) ? null : cell.getCellRendererStruct(), Str.toStringz(attribute), column);
171 	}
172 
173 	/**
174 	 * Unsets all the mappings on all renderers on @cell_layout and
175 	 * removes all renderers from @cell_layout.
176 	 *
177 	 * Since: 2.4
178 	 */
179 	public void clear()
180 	{
181 		gtk_cell_layout_clear(getCellLayoutStruct());
182 	}
183 
184 	/**
185 	 * Clears all existing attributes previously set with
186 	 * gtk_cell_layout_set_attributes().
187 	 *
188 	 * Params:
189 	 *     cell = a #GtkCellRenderer to clear the attribute mapping on
190 	 *
191 	 * Since: 2.4
192 	 */
193 	public void clearAttributes(CellRenderer cell)
194 	{
195 		gtk_cell_layout_clear_attributes(getCellLayoutStruct(), (cell is null) ? null : cell.getCellRendererStruct());
196 	}
197 
198 	/**
199 	 * Returns the underlying #GtkCellArea which might be @cell_layout
200 	 * if called on a #GtkCellArea or might be %NULL if no #GtkCellArea
201 	 * is used by @cell_layout.
202 	 *
203 	 * Returns: the cell area used by @cell_layout,
204 	 *     or %NULL in case no cell area is used.
205 	 *
206 	 * Since: 3.0
207 	 */
208 	public CellArea getArea()
209 	{
210 		auto p = gtk_cell_layout_get_area(getCellLayoutStruct());
211 
212 		if(p is null)
213 		{
214 			return null;
215 		}
216 
217 		return ObjectG.getDObject!(CellArea)(cast(GtkCellArea*) p);
218 	}
219 
220 	/**
221 	 * Returns the cell renderers which have been added to @cell_layout.
222 	 *
223 	 * Returns: a list of cell renderers. The list, but not the renderers has
224 	 *     been newly allocated and should be freed with g_list_free()
225 	 *     when no longer needed.
226 	 *
227 	 * Since: 2.12
228 	 */
229 	public ListG getCells()
230 	{
231 		auto p = gtk_cell_layout_get_cells(getCellLayoutStruct());
232 
233 		if(p is null)
234 		{
235 			return null;
236 		}
237 
238 		return new ListG(cast(GList*) p);
239 	}
240 
241 	/**
242 	 * Adds the @cell to the end of @cell_layout. If @expand is %FALSE, then the
243 	 * @cell is allocated no more space than it needs. Any unused space is
244 	 * divided evenly between cells for which @expand is %TRUE.
245 	 *
246 	 * Note that reusing the same cell renderer is not supported.
247 	 *
248 	 * Params:
249 	 *     cell = a #GtkCellRenderer
250 	 *     expand = %TRUE if @cell is to be given extra space allocated to @cell_layout
251 	 *
252 	 * Since: 2.4
253 	 */
254 	public void packEnd(CellRenderer cell, bool expand)
255 	{
256 		gtk_cell_layout_pack_end(getCellLayoutStruct(), (cell is null) ? null : cell.getCellRendererStruct(), expand);
257 	}
258 
259 	/**
260 	 * Packs the @cell into the beginning of @cell_layout. If @expand is %FALSE,
261 	 * then the @cell is allocated no more space than it needs. Any unused space
262 	 * is divided evenly between cells for which @expand is %TRUE.
263 	 *
264 	 * Note that reusing the same cell renderer is not supported.
265 	 *
266 	 * Params:
267 	 *     cell = a #GtkCellRenderer
268 	 *     expand = %TRUE if @cell is to be given extra space allocated to @cell_layout
269 	 *
270 	 * Since: 2.4
271 	 */
272 	public void packStart(CellRenderer cell, bool expand)
273 	{
274 		gtk_cell_layout_pack_start(getCellLayoutStruct(), (cell is null) ? null : cell.getCellRendererStruct(), expand);
275 	}
276 
277 	/**
278 	 * Re-inserts @cell at @position.
279 	 *
280 	 * Note that @cell has already to be packed into @cell_layout
281 	 * for this to function properly.
282 	 *
283 	 * Params:
284 	 *     cell = a #GtkCellRenderer to reorder
285 	 *     position = new position to insert @cell at
286 	 *
287 	 * Since: 2.4
288 	 */
289 	public void reorder(CellRenderer cell, int position)
290 	{
291 		gtk_cell_layout_reorder(getCellLayoutStruct(), (cell is null) ? null : cell.getCellRendererStruct(), position);
292 	}
293 
294 	/**
295 	 * Sets the #GtkCellLayoutDataFunc to use for @cell_layout.
296 	 *
297 	 * This function is used instead of the standard attributes mapping
298 	 * for setting the column value, and should set the value of @cell_layout’s
299 	 * cell renderer(s) as appropriate.
300 	 *
301 	 * @func may be %NULL to remove a previously set function.
302 	 *
303 	 * Params:
304 	 *     cell = a #GtkCellRenderer
305 	 *     func = the #GtkCellLayoutDataFunc to use, or %NULL
306 	 *     funcData = user data for @func
307 	 *     destroy = destroy notify for @func_data
308 	 *
309 	 * Since: 2.4
310 	 */
311 	public void setCellDataFunc(CellRenderer cell, GtkCellLayoutDataFunc func, void* funcData, GDestroyNotify destroy)
312 	{
313 		gtk_cell_layout_set_cell_data_func(getCellLayoutStruct(), (cell is null) ? null : cell.getCellRendererStruct(), func, funcData, destroy);
314 	}
315 }