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.Grid;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gtk.Container;
30 private import gtk.OrientableIF;
31 private import gtk.OrientableT;
32 private import gtk.Widget;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * GtkGrid is a container which arranges its child widgets in
40  * rows and columns, with arbitrary positions and horizontal/vertical spans.
41  * 
42  * Children are added using gtk_grid_attach(). They can span multiple
43  * rows or columns. It is also possible to add a child next to an
44  * existing child, using gtk_grid_attach_next_to(). The behaviour of
45  * GtkGrid when several children occupy the same grid cell is undefined.
46  * 
47  * GtkGrid can be used like a #GtkBox by just using gtk_container_add(),
48  * which will place children next to each other in the direction determined
49  * by the #GtkOrientable:orientation property. However, if all you want is a
50  * single row or column, then #GtkBox is the preferred widget.
51  * 
52  * # CSS nodes
53  * 
54  * GtkGrid uses a single CSS node with name grid.
55  */
56 public class Grid : Container, OrientableIF
57 {
58 	/** the main Gtk struct */
59 	protected GtkGrid* gtkGrid;
60 
61 	/** Get the main Gtk struct */
62 	public GtkGrid* getGridStruct(bool transferOwnership = false)
63 	{
64 		if (transferOwnership)
65 			ownedRef = false;
66 		return gtkGrid;
67 	}
68 
69 	/** the main Gtk struct as a void* */
70 	protected override void* getStruct()
71 	{
72 		return cast(void*)gtkGrid;
73 	}
74 
75 	/**
76 	 * Sets our main struct and passes it to the parent class.
77 	 */
78 	public this (GtkGrid* gtkGrid, bool ownedRef = false)
79 	{
80 		this.gtkGrid = gtkGrid;
81 		super(cast(GtkContainer*)gtkGrid, ownedRef);
82 	}
83 
84 	// add the Orientable capabilities
85 	mixin OrientableT!(GtkGrid);
86 
87 
88 	/** */
89 	public static GType getType()
90 	{
91 		return gtk_grid_get_type();
92 	}
93 
94 	/**
95 	 * Creates a new grid widget.
96 	 *
97 	 * Returns: the new #GtkGrid
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this()
102 	{
103 		auto p = gtk_grid_new();
104 
105 		if(p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 
110 		this(cast(GtkGrid*) p);
111 	}
112 
113 	/**
114 	 * Adds a widget to the grid.
115 	 *
116 	 * The position of @child is determined by @left and @top. The
117 	 * number of “cells” that @child will occupy is determined by
118 	 * @width and @height.
119 	 *
120 	 * Params:
121 	 *     child = the widget to add
122 	 *     left = the column number to attach the left side of @child to
123 	 *     top = the row number to attach the top side of @child to
124 	 *     width = the number of columns that @child will span
125 	 *     height = the number of rows that @child will span
126 	 */
127 	public void attach(Widget child, int left, int top, int width, int height)
128 	{
129 		gtk_grid_attach(gtkGrid, (child is null) ? null : child.getWidgetStruct(), left, top, width, height);
130 	}
131 
132 	/**
133 	 * Adds a widget to the grid.
134 	 *
135 	 * The widget is placed next to @sibling, on the side determined by
136 	 * @side. When @sibling is %NULL, the widget is placed in row (for
137 	 * left or right placement) or column 0 (for top or bottom placement),
138 	 * at the end indicated by @side.
139 	 *
140 	 * Attaching widgets labeled [1], [2], [3] with @sibling == %NULL and
141 	 * @side == %GTK_POS_LEFT yields a layout of [3][2][1].
142 	 *
143 	 * Params:
144 	 *     child = the widget to add
145 	 *     sibling = the child of @grid that @child will be placed
146 	 *         next to, or %NULL to place @child at the beginning or end
147 	 *     side = the side of @sibling that @child is positioned next to
148 	 *     width = the number of columns that @child will span
149 	 *     height = the number of rows that @child will span
150 	 */
151 	public void attachNextTo(Widget child, Widget sibling, GtkPositionType side, int width, int height)
152 	{
153 		gtk_grid_attach_next_to(gtkGrid, (child is null) ? null : child.getWidgetStruct(), (sibling is null) ? null : sibling.getWidgetStruct(), side, width, height);
154 	}
155 
156 	/**
157 	 * Returns which row defines the global baseline of @grid.
158 	 *
159 	 * Returns: the row index defining the global baseline
160 	 *
161 	 * Since: 3.10
162 	 */
163 	public int getBaselineRow()
164 	{
165 		return gtk_grid_get_baseline_row(gtkGrid);
166 	}
167 
168 	/**
169 	 * Gets the child of @grid whose area covers the grid
170 	 * cell whose upper left corner is at @left, @top.
171 	 *
172 	 * Params:
173 	 *     left = the left edge of the cell
174 	 *     top = the top edge of the cell
175 	 *
176 	 * Returns: the child at the given position, or %NULL
177 	 *
178 	 * Since: 3.2
179 	 */
180 	public Widget getChildAt(int left, int top)
181 	{
182 		auto p = gtk_grid_get_child_at(gtkGrid, left, top);
183 
184 		if(p is null)
185 		{
186 			return null;
187 		}
188 
189 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
190 	}
191 
192 	/**
193 	 * Returns whether all columns of @grid have the same width.
194 	 *
195 	 * Returns: whether all columns of @grid have the same width.
196 	 */
197 	public bool getColumnHomogeneous()
198 	{
199 		return gtk_grid_get_column_homogeneous(gtkGrid) != 0;
200 	}
201 
202 	/**
203 	 * Returns the amount of space between the columns of @grid.
204 	 *
205 	 * Returns: the column spacing of @grid
206 	 */
207 	public uint getColumnSpacing()
208 	{
209 		return gtk_grid_get_column_spacing(gtkGrid);
210 	}
211 
212 	/**
213 	 * Returns the baseline position of @row as set
214 	 * by gtk_grid_set_row_baseline_position() or the default value
215 	 * %GTK_BASELINE_POSITION_CENTER.
216 	 *
217 	 * Params:
218 	 *     row = a row index
219 	 *
220 	 * Returns: the baseline position of @row
221 	 *
222 	 * Since: 3.10
223 	 */
224 	public GtkBaselinePosition getRowBaselinePosition(int row)
225 	{
226 		return gtk_grid_get_row_baseline_position(gtkGrid, row);
227 	}
228 
229 	/**
230 	 * Returns whether all rows of @grid have the same height.
231 	 *
232 	 * Returns: whether all rows of @grid have the same height.
233 	 */
234 	public bool getRowHomogeneous()
235 	{
236 		return gtk_grid_get_row_homogeneous(gtkGrid) != 0;
237 	}
238 
239 	/**
240 	 * Returns the amount of space between the rows of @grid.
241 	 *
242 	 * Returns: the row spacing of @grid
243 	 */
244 	public uint getRowSpacing()
245 	{
246 		return gtk_grid_get_row_spacing(gtkGrid);
247 	}
248 
249 	/**
250 	 * Inserts a column at the specified position.
251 	 *
252 	 * Children which are attached at or to the right of this position
253 	 * are moved one column to the right. Children which span across this
254 	 * position are grown to span the new column.
255 	 *
256 	 * Params:
257 	 *     position = the position to insert the column at
258 	 *
259 	 * Since: 3.2
260 	 */
261 	public void insertColumn(int position)
262 	{
263 		gtk_grid_insert_column(gtkGrid, position);
264 	}
265 
266 	/**
267 	 * Inserts a row or column at the specified position.
268 	 *
269 	 * The new row or column is placed next to @sibling, on the side
270 	 * determined by @side. If @side is %GTK_POS_TOP or %GTK_POS_BOTTOM,
271 	 * a row is inserted. If @side is %GTK_POS_LEFT of %GTK_POS_RIGHT,
272 	 * a column is inserted.
273 	 *
274 	 * Params:
275 	 *     sibling = the child of @grid that the new row or column will be
276 	 *         placed next to
277 	 *     side = the side of @sibling that @child is positioned next to
278 	 *
279 	 * Since: 3.2
280 	 */
281 	public void insertNextTo(Widget sibling, GtkPositionType side)
282 	{
283 		gtk_grid_insert_next_to(gtkGrid, (sibling is null) ? null : sibling.getWidgetStruct(), side);
284 	}
285 
286 	/**
287 	 * Inserts a row at the specified position.
288 	 *
289 	 * Children which are attached at or below this position
290 	 * are moved one row down. Children which span across this
291 	 * position are grown to span the new row.
292 	 *
293 	 * Params:
294 	 *     position = the position to insert the row at
295 	 *
296 	 * Since: 3.2
297 	 */
298 	public void insertRow(int position)
299 	{
300 		gtk_grid_insert_row(gtkGrid, position);
301 	}
302 
303 	/**
304 	 * Removes a column from the grid.
305 	 *
306 	 * Children that are placed in this column are removed,
307 	 * spanning children that overlap this column have their
308 	 * width reduced by one, and children after the column
309 	 * are moved to the left.
310 	 *
311 	 * Params:
312 	 *     position = the position of the column to remove
313 	 *
314 	 * Since: 3.10
315 	 */
316 	public void removeColumn(int position)
317 	{
318 		gtk_grid_remove_column(gtkGrid, position);
319 	}
320 
321 	/**
322 	 * Removes a row from the grid.
323 	 *
324 	 * Children that are placed in this row are removed,
325 	 * spanning children that overlap this row have their
326 	 * height reduced by one, and children below the row
327 	 * are moved up.
328 	 *
329 	 * Params:
330 	 *     position = the position of the row to remove
331 	 *
332 	 * Since: 3.10
333 	 */
334 	public void removeRow(int position)
335 	{
336 		gtk_grid_remove_row(gtkGrid, position);
337 	}
338 
339 	/**
340 	 * Sets which row defines the global baseline for the entire grid.
341 	 * Each row in the grid can have its own local baseline, but only
342 	 * one of those is global, meaning it will be the baseline in the
343 	 * parent of the @grid.
344 	 *
345 	 * Params:
346 	 *     row = the row index
347 	 *
348 	 * Since: 3.10
349 	 */
350 	public void setBaselineRow(int row)
351 	{
352 		gtk_grid_set_baseline_row(gtkGrid, row);
353 	}
354 
355 	/**
356 	 * Sets whether all columns of @grid will have the same width.
357 	 *
358 	 * Params:
359 	 *     homogeneous = %TRUE to make columns homogeneous
360 	 */
361 	public void setColumnHomogeneous(bool homogeneous)
362 	{
363 		gtk_grid_set_column_homogeneous(gtkGrid, homogeneous);
364 	}
365 
366 	/**
367 	 * Sets the amount of space between columns of @grid.
368 	 *
369 	 * Params:
370 	 *     spacing = the amount of space to insert between columns
371 	 */
372 	public void setColumnSpacing(uint spacing)
373 	{
374 		gtk_grid_set_column_spacing(gtkGrid, spacing);
375 	}
376 
377 	/**
378 	 * Sets how the baseline should be positioned on @row of the
379 	 * grid, in case that row is assigned more space than is requested.
380 	 *
381 	 * Params:
382 	 *     row = a row index
383 	 *     pos = a #GtkBaselinePosition
384 	 *
385 	 * Since: 3.10
386 	 */
387 	public void setRowBaselinePosition(int row, GtkBaselinePosition pos)
388 	{
389 		gtk_grid_set_row_baseline_position(gtkGrid, row, pos);
390 	}
391 
392 	/**
393 	 * Sets whether all rows of @grid will have the same height.
394 	 *
395 	 * Params:
396 	 *     homogeneous = %TRUE to make rows homogeneous
397 	 */
398 	public void setRowHomogeneous(bool homogeneous)
399 	{
400 		gtk_grid_set_row_homogeneous(gtkGrid, homogeneous);
401 	}
402 
403 	/**
404 	 * Sets the amount of space between rows of @grid.
405 	 *
406 	 * Params:
407 	 *     spacing = the amount of space to insert between rows
408 	 */
409 	public void setRowSpacing(uint spacing)
410 	{
411 		gtk_grid_set_row_spacing(gtkGrid, spacing);
412 	}
413 }