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