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  * Conversion parameters:
26  * inFile  = GtkTable.html
27  * outPack = gtk
28  * outFile = Table
29  * strct   = GtkTable
30  * realStrct=
31  * ctorStrct=
32  * clss    = Table
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_table_
41  * 	- gtk_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * 	- gtk_table_new
46  * omit signals:
47  * imports:
48  * 	- gtk.Widget
49  * structWrap:
50  * 	- GtkWidget* -> Widget
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module gtk.Table;
57 
58 public  import gtkc.gtktypes;
59 
60 private import gtkc.gtk;
61 private import glib.ConstructionException;
62 private import gobject.ObjectG;
63 
64 
65 private import gtk.Widget;
66 
67 
68 
69 private import gtk.Container;
70 
71 /**
72  * Description
73  * The GtkTable functions allow the programmer to arrange widgets in rows and
74  * columns, making it easy to align many widgets next to each other,
75  * horizontally and vertically.
76  * Tables are created with a call to gtk_table_new(), the size of which can
77  * later be changed with gtk_table_resize().
78  * Widgets can be added to a table using gtk_table_attach() or the more
79  * convenient (but slightly less flexible) gtk_table_attach_defaults().
80  * To alter the space next to a specific row, use gtk_table_set_row_spacing(),
81  * and for a column, gtk_table_set_col_spacing().
82  * The gaps between all rows or columns can be changed by calling
83  * gtk_table_set_row_spacings() or gtk_table_set_col_spacings() respectively.
84  * gtk_table_set_homogeneous(), can be used to set whether all cells in the
85  * table will resize themselves to the size of the largest widget in the table.
86  */
87 public class Table : Container
88 {
89 	
90 	/** the main Gtk struct */
91 	protected GtkTable* gtkTable;
92 	
93 	
94 	public GtkTable* getTableStruct()
95 	{
96 		return gtkTable;
97 	}
98 	
99 	
100 	/** the main Gtk struct as a void* */
101 	protected override void* getStruct()
102 	{
103 		return cast(void*)gtkTable;
104 	}
105 	
106 	/**
107 	 * Sets our main struct and passes it to the parent class
108 	 */
109 	public this (GtkTable* gtkTable)
110 	{
111 		super(cast(GtkContainer*)gtkTable);
112 		this.gtkTable = gtkTable;
113 	}
114 	
115 	protected override void setStruct(GObject* obj)
116 	{
117 		super.setStruct(obj);
118 		gtkTable = cast(GtkTable*)obj;
119 	}
120 	
121 	int row;
122 	int col;
123 	int maxRows;
124 	int maxCols;
125 	
126 	public AttachOptions defaultXOption = AttachOptions.SHRINK;
127 	public AttachOptions defaultYOption = AttachOptions.SHRINK;
128 	
129 	/**
130 	 * Removes all children and resizes the table to 1,1
131 	 */
132 	override void removeAll()
133 	{
134 		super.removeAll();
135 		resize(1,1);
136 	}
137 	
138 	/**
139 	 * Used to create a new table widget. An initial size must be given by
140 	 * specifying how many rows and columns the table should have, although
141 	 * this can be changed later with gtk_table_resize(). rows and columns
142 	 * must both be in the range 0 .. 65535.
143 	 * Params:
144 	 *  rows = The number of rows the new table should have.
145 	 *  columns = The number of columns the new table should have.
146 	 *  homogeneous = If set to TRUE, all table cells are resized to the size of the cell
147 	 *  containing the largest widget.
148 	 * Throws: ConstructionException GTK+ fails to create the object.
149 	 */
150 	public this (uint rows, uint columns, int homogeneous)
151 	{
152 		// GtkWidget* gtk_table_new (guint rows,  guint columns,  gboolean homogeneous);
153 		auto p = gtk_table_new(rows, columns, homogeneous);
154 		
155 		if(p is null)
156 		{
157 			throw new ConstructionException("null returned by gtk_table_new");
158 		}
159 		
160 		this(cast(GtkTable*) p);
161 		
162 		row = 0;
163 		col = 0;
164 		maxRows = rows;
165 		maxCols = columns;
166 	}
167 	
168 	
169 	/**
170 	 * Attach a new widget creating a new row if necessary
171 	 */
172 	void attach(Widget child)
173 	{
174 		attach(child, col, col + 1, row, row + 1,
175 		defaultXOption, defaultYOption,
176 		getDefaultColSpacing(), getDefaultRowSpacing());
177 		++col;
178 		if (col >= maxCols)
179 		{
180 			col = 0;
181 			++row;
182 		}
183 	}
184 	
185 	/**
186 	 */
187 	
188 	/**
189 	 * If you need to change a table's size after it has been created, this function allows you to do so.
190 	 * Params:
191 	 * rows = The new number of rows.
192 	 * columns = The new number of columns.
193 	 */
194 	public void resize(uint rows, uint columns)
195 	{
196 		// void gtk_table_resize (GtkTable *table,  guint rows,  guint columns);
197 		gtk_table_resize(gtkTable, rows, columns);
198 	}
199 	
200 	/**
201 	 * Adds a widget to a table. The number of 'cells' that a widget will occupy is
202 	 * specified by left_attach, right_attach, top_attach and bottom_attach.
203 	 * These each represent the leftmost, rightmost, uppermost and lowest column
204 	 * and row numbers of the table. (Columns and rows are indexed from zero).
205 	 * Params:
206 	 * child = The widget to add.
207 	 * leftAttach = the column number to attach the left side of a child widget to.
208 	 * rightAttach = the column number to attach the right side of a child widget to.
209 	 * topAttach = the row number to attach the top of a child widget to.
210 	 * bottomAttach = the row number to attach the bottom of a child widget to.
211 	 * xoptions = Used to specify the properties of the child widget when the table is resized.
212 	 * yoptions = The same as xoptions, except this field determines behaviour of vertical resizing.
213 	 * xpadding = An integer value specifying the padding on the left and right of the widget being added to the table.
214 	 * ypadding = The amount of padding above and below the child widget.
215 	 */
216 	public void attach(Widget child, uint leftAttach, uint rightAttach, uint topAttach, uint bottomAttach, GtkAttachOptions xoptions, GtkAttachOptions yoptions, uint xpadding, uint ypadding)
217 	{
218 		// void gtk_table_attach (GtkTable *table,  GtkWidget *child,  guint left_attach,  guint right_attach,  guint top_attach,  guint bottom_attach,  GtkAttachOptions xoptions,  GtkAttachOptions yoptions,  guint xpadding,  guint ypadding);
219 		gtk_table_attach(gtkTable, (child is null) ? null : child.getWidgetStruct(), leftAttach, rightAttach, topAttach, bottomAttach, xoptions, yoptions, xpadding, ypadding);
220 	}
221 	
222 	/**
223 	 * As there are many options associated with gtk_table_attach(), this convenience function provides the programmer with a means to add children to a table with identical padding and expansion options. The values used for the GtkAttachOptions are GTK_EXPAND | GTK_FILL, and the padding is set to 0.
224 	 * Params:
225 	 * widget = The child widget to add.
226 	 * leftAttach = The column number to attach the left side of the child widget to.
227 	 * rightAttach = The column number to attach the right side of the child widget to.
228 	 * topAttach = The row number to attach the top of the child widget to.
229 	 * bottomAttach = The row number to attach the bottom of the child widget to.
230 	 */
231 	public void attachDefaults(Widget widget, uint leftAttach, uint rightAttach, uint topAttach, uint bottomAttach)
232 	{
233 		// void gtk_table_attach_defaults (GtkTable *table,  GtkWidget *widget,  guint left_attach,  guint right_attach,  guint top_attach,  guint bottom_attach);
234 		gtk_table_attach_defaults(gtkTable, (widget is null) ? null : widget.getWidgetStruct(), leftAttach, rightAttach, topAttach, bottomAttach);
235 	}
236 	
237 	/**
238 	 * Changes the space between a given table row and the subsequent row.
239 	 * Params:
240 	 * row = row number whose spacing will be changed.
241 	 * spacing = number of pixels that the spacing should take up.
242 	 */
243 	public void setRowSpacing(uint row, uint spacing)
244 	{
245 		// void gtk_table_set_row_spacing (GtkTable *table,  guint row,  guint spacing);
246 		gtk_table_set_row_spacing(gtkTable, row, spacing);
247 	}
248 	
249 	/**
250 	 * Alters the amount of space between a given table column and the following
251 	 * column.
252 	 * Params:
253 	 * column = the column whose spacing should be changed.
254 	 * spacing = number of pixels that the spacing should take up.
255 	 */
256 	public void setColSpacing(uint column, uint spacing)
257 	{
258 		// void gtk_table_set_col_spacing (GtkTable *table,  guint column,  guint spacing);
259 		gtk_table_set_col_spacing(gtkTable, column, spacing);
260 	}
261 	
262 	/**
263 	 * Sets the space between every row in table equal to spacing.
264 	 * Params:
265 	 * spacing = the number of pixels of space to place between every row in the table.
266 	 */
267 	public void setRowSpacings(uint spacing)
268 	{
269 		// void gtk_table_set_row_spacings (GtkTable *table,  guint spacing);
270 		gtk_table_set_row_spacings(gtkTable, spacing);
271 	}
272 	
273 	/**
274 	 * Sets the space between every column in table equal to spacing.
275 	 * Params:
276 	 * spacing = the number of pixels of space to place between every column in the table.
277 	 */
278 	public void setColSpacings(uint spacing)
279 	{
280 		// void gtk_table_set_col_spacings (GtkTable *table,  guint spacing);
281 		gtk_table_set_col_spacings(gtkTable, spacing);
282 	}
283 	
284 	/**
285 	 * Changes the homogenous property of table cells, ie. whether all cells are an equal size or not.
286 	 * Params:
287 	 * homogeneous = Set to TRUE to ensure all table cells are the same size. Set
288 	 * to FALSE if this is not your desired behaviour.
289 	 */
290 	public void setHomogeneous(int homogeneous)
291 	{
292 		// void gtk_table_set_homogeneous (GtkTable *table,  gboolean homogeneous);
293 		gtk_table_set_homogeneous(gtkTable, homogeneous);
294 	}
295 	
296 	/**
297 	 * Gets the default row spacing for the table. This is
298 	 * the spacing that will be used for newly added rows.
299 	 * (See gtk_table_set_row_spacings())
300 	 * Returns: the default row spacing
301 	 */
302 	public uint getDefaultRowSpacing()
303 	{
304 		// guint gtk_table_get_default_row_spacing (GtkTable *table);
305 		return gtk_table_get_default_row_spacing(gtkTable);
306 	}
307 	
308 	/**
309 	 * Returns whether the table cells are all constrained to the same
310 	 * width and height. (See gtk_table_set_homogenous())
311 	 * Returns: TRUE if the cells are all constrained to the same size
312 	 */
313 	public int getHomogeneous()
314 	{
315 		// gboolean gtk_table_get_homogeneous (GtkTable *table);
316 		return gtk_table_get_homogeneous(gtkTable);
317 	}
318 	
319 	/**
320 	 * Gets the amount of space between row row, and
321 	 * row row + 1. See gtk_table_set_row_spacing().
322 	 * Params:
323 	 * row = a row in the table, 0 indicates the first row
324 	 * Returns: the row spacing
325 	 */
326 	public uint getRowSpacing(uint row)
327 	{
328 		// guint gtk_table_get_row_spacing (GtkTable *table,  guint row);
329 		return gtk_table_get_row_spacing(gtkTable, row);
330 	}
331 	
332 	/**
333 	 * Gets the amount of space between column col, and
334 	 * column col + 1. See gtk_table_set_col_spacing().
335 	 * Params:
336 	 * column = a column in the table, 0 indicates the first column
337 	 * Returns: the column spacing
338 	 */
339 	public uint getColSpacing(uint column)
340 	{
341 		// guint gtk_table_get_col_spacing (GtkTable *table,  guint column);
342 		return gtk_table_get_col_spacing(gtkTable, column);
343 	}
344 	
345 	/**
346 	 * Gets the default column spacing for the table. This is
347 	 * the spacing that will be used for newly added columns.
348 	 * (See gtk_table_set_col_spacings())
349 	 * Returns: the default column spacing
350 	 */
351 	public uint getDefaultColSpacing()
352 	{
353 		// guint gtk_table_get_default_col_spacing (GtkTable *table);
354 		return gtk_table_get_default_col_spacing(gtkTable);
355 	}
356 	
357 	/**
358 	 * Since 2.22
359 	 * Params:
360 	 * rows = return location for the number of
361 	 * rows, or NULL. [out][allow-none]
362 	 * columns = return location for the number
363 	 * of columns, or NULL. [out][allow-none]
364 	 */
365 	public void getSize(out uint rows, out uint columns)
366 	{
367 		// void gtk_table_get_size (GtkTable *table,  guint *rows,  guint *columns);
368 		gtk_table_get_size(gtkTable, &rows, &columns);
369 	}
370 }