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