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