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