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.OrientableIF;
30 private import gtk.OrientableT;
31 private import gtk.Widget;
32 private import gtk.c.functions;
33 public  import gtk.c.types;
34 
35 
36 /**
37  * `GtkGrid` is a container which arranges its child widgets in
38  * rows and columns.
39  * 
40  * ![An example GtkGrid](grid.png)
41  * 
42  * It supports arbitrary positions and horizontal/vertical spans.
43  * 
44  * Children are added using [method@Gtk.Grid.attach]. They can span multiple
45  * rows or columns. It is also possible to add a child next to an existing
46  * child, using [method@Gtk.Grid.attach_next_to]. To remove a child from the
47  * grid, use [method@Gtk.Grid.remove].
48  * 
49  * The behaviour of `GtkGrid` when several children occupy the same grid
50  * cell is undefined.
51  * 
52  * # GtkGrid as GtkBuildable
53  * 
54  * Every child in a `GtkGrid` has access to a custom [iface@Gtk.Buildable]
55  * element, called ´<layout>´. It can by used to specify a position in the
56  * grid and optionally spans. All properties that can be used in the ´<layout>´
57  * element are implemented by [class@Gtk.GridLayoutChild].
58  * 
59  * It is implemented by `GtkWidget` using [class@Gtk.LayoutManager].
60  * 
61  * To showcase it, here is a simple example:
62  * 
63  * ```xml
64  * <object class="GtkGrid" id="my_grid">
65  * <child>
66  * <object class="GtkButton" id="button1">
67  * <property name="label">Button 1</property>
68  * <layout>
69  * <property name="column">0</property>
70  * <property name="row">0</property>
71  * </layout>
72  * </object>
73  * </child>
74  * <child>
75  * <object class="GtkButton" id="button2">
76  * <property name="label">Button 2</property>
77  * <layout>
78  * <property name="column">1</property>
79  * <property name="row">0</property>
80  * </layout>
81  * </object>
82  * </child>
83  * <child>
84  * <object class="GtkButton" id="button3">
85  * <property name="label">Button 3</property>
86  * <layout>
87  * <property name="column">2</property>
88  * <property name="row">0</property>
89  * <property name="row-span">2</property>
90  * </layout>
91  * </object>
92  * </child>
93  * <child>
94  * <object class="GtkButton" id="button4">
95  * <property name="label">Button 4</property>
96  * <layout>
97  * <property name="column">0</property>
98  * <property name="row">1</property>
99  * <property name="column-span">2</property>
100  * </layout>
101  * </object>
102  * </child>
103  * </object>
104  * ```
105  * 
106  * It organizes the first two buttons side-by-side in one cell each.
107  * The third button is in the last column but spans across two rows.
108  * This is defined by the ´row-span´ property. The last button is
109  * located in the second row and spans across two columns, which is
110  * defined by the ´column-span´ property.
111  * 
112  * # CSS nodes
113  * 
114  * `GtkGrid` uses a single CSS node with name `grid`.
115  * 
116  * # Accessibility
117  * 
118  * `GtkGrid` uses the %GTK_ACCESSIBLE_ROLE_GROUP role.
119  */
120 public class Grid : Widget, OrientableIF
121 {
122 	/** the main Gtk struct */
123 	protected GtkGrid* gtkGrid;
124 
125 	/** Get the main Gtk struct */
126 	public GtkGrid* getGridStruct(bool transferOwnership = false)
127 	{
128 		if (transferOwnership)
129 			ownedRef = false;
130 		return gtkGrid;
131 	}
132 
133 	/** the main Gtk struct as a void* */
134 	protected override void* getStruct()
135 	{
136 		return cast(void*)gtkGrid;
137 	}
138 
139 	/**
140 	 * Sets our main struct and passes it to the parent class.
141 	 */
142 	public this (GtkGrid* gtkGrid, bool ownedRef = false)
143 	{
144 		this.gtkGrid = gtkGrid;
145 		super(cast(GtkWidget*)gtkGrid, ownedRef);
146 	}
147 
148 	// add the Orientable capabilities
149 	mixin OrientableT!(GtkGrid);
150 
151 
152 	/** */
153 	public static GType getType()
154 	{
155 		return gtk_grid_get_type();
156 	}
157 
158 	/**
159 	 * Creates a new grid widget.
160 	 *
161 	 * Returns: the new `GtkGrid`
162 	 *
163 	 * Throws: ConstructionException GTK+ fails to create the object.
164 	 */
165 	public this()
166 	{
167 		auto __p = gtk_grid_new();
168 
169 		if(__p is null)
170 		{
171 			throw new ConstructionException("null returned by new");
172 		}
173 
174 		this(cast(GtkGrid*) __p);
175 	}
176 
177 	/**
178 	 * Adds a widget to the grid.
179 	 *
180 	 * The position of @child is determined by @column and @row.
181 	 * The number of “cells” that @child will occupy is determined
182 	 * by @width and @height.
183 	 *
184 	 * Params:
185 	 *     child = the widget to add
186 	 *     column = the column number to attach the left side of @child to
187 	 *     row = the row number to attach the top side of @child to
188 	 *     width = the number of columns that @child will span
189 	 *     height = the number of rows that @child will span
190 	 */
191 	public void attach(Widget child, int column, int row, int width, int height)
192 	{
193 		gtk_grid_attach(gtkGrid, (child is null) ? null : child.getWidgetStruct(), column, row, width, height);
194 	}
195 
196 	/**
197 	 * Adds a widget to the grid.
198 	 *
199 	 * The widget is placed next to @sibling, on the side determined by
200 	 * @side. When @sibling is %NULL, the widget is placed in row (for
201 	 * left or right placement) or column 0 (for top or bottom placement),
202 	 * at the end indicated by @side.
203 	 *
204 	 * Attaching widgets labeled [1], [2], [3] with @sibling == %NULL and
205 	 * @side == %GTK_POS_LEFT yields a layout of [3][2][1].
206 	 *
207 	 * Params:
208 	 *     child = the widget to add
209 	 *     sibling = the child of @grid that @child will be placed
210 	 *         next to, or %NULL to place @child at the beginning or end
211 	 *     side = the side of @sibling that @child is positioned next to
212 	 *     width = the number of columns that @child will span
213 	 *     height = the number of rows that @child will span
214 	 */
215 	public void attachNextTo(Widget child, Widget sibling, GtkPositionType side, int width, int height)
216 	{
217 		gtk_grid_attach_next_to(gtkGrid, (child is null) ? null : child.getWidgetStruct(), (sibling is null) ? null : sibling.getWidgetStruct(), side, width, height);
218 	}
219 
220 	/**
221 	 * Returns which row defines the global baseline of @grid.
222 	 *
223 	 * Returns: the row index defining the global baseline
224 	 */
225 	public int getBaselineRow()
226 	{
227 		return gtk_grid_get_baseline_row(gtkGrid);
228 	}
229 
230 	/**
231 	 * Gets the child of @grid whose area covers the grid
232 	 * cell at @column, @row.
233 	 *
234 	 * Params:
235 	 *     column = the left edge of the cell
236 	 *     row = the top edge of the cell
237 	 *
238 	 * Returns: the child at the given position, or %NULL
239 	 */
240 	public Widget getChildAt(int column, int row)
241 	{
242 		auto __p = gtk_grid_get_child_at(gtkGrid, column, row);
243 
244 		if(__p is null)
245 		{
246 			return null;
247 		}
248 
249 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
250 	}
251 
252 	/**
253 	 * Returns whether all columns of @grid have the same width.
254 	 *
255 	 * Returns: whether all columns of @grid have the same width.
256 	 */
257 	public bool getColumnHomogeneous()
258 	{
259 		return gtk_grid_get_column_homogeneous(gtkGrid) != 0;
260 	}
261 
262 	/**
263 	 * Returns the amount of space between the columns of @grid.
264 	 *
265 	 * Returns: the column spacing of @grid
266 	 */
267 	public uint getColumnSpacing()
268 	{
269 		return gtk_grid_get_column_spacing(gtkGrid);
270 	}
271 
272 	/**
273 	 * Returns the baseline position of @row.
274 	 *
275 	 * See [method@Gtk.Grid.set_row_baseline_position].
276 	 *
277 	 * Params:
278 	 *     row = a row index
279 	 *
280 	 * Returns: the baseline position of @row
281 	 */
282 	public GtkBaselinePosition getRowBaselinePosition(int row)
283 	{
284 		return gtk_grid_get_row_baseline_position(gtkGrid, row);
285 	}
286 
287 	/**
288 	 * Returns whether all rows of @grid have the same height.
289 	 *
290 	 * Returns: whether all rows of @grid have the same height.
291 	 */
292 	public bool getRowHomogeneous()
293 	{
294 		return gtk_grid_get_row_homogeneous(gtkGrid) != 0;
295 	}
296 
297 	/**
298 	 * Returns the amount of space between the rows of @grid.
299 	 *
300 	 * Returns: the row spacing of @grid
301 	 */
302 	public uint getRowSpacing()
303 	{
304 		return gtk_grid_get_row_spacing(gtkGrid);
305 	}
306 
307 	/**
308 	 * Inserts a column at the specified position.
309 	 *
310 	 * Children which are attached at or to the right of this position
311 	 * are moved one column to the right. Children which span across this
312 	 * position are grown to span the new column.
313 	 *
314 	 * Params:
315 	 *     position = the position to insert the column at
316 	 */
317 	public void insertColumn(int position)
318 	{
319 		gtk_grid_insert_column(gtkGrid, position);
320 	}
321 
322 	/**
323 	 * Inserts a row or column at the specified position.
324 	 *
325 	 * The new row or column is placed next to @sibling, on the side
326 	 * determined by @side. If @side is %GTK_POS_TOP or %GTK_POS_BOTTOM,
327 	 * a row is inserted. If @side is %GTK_POS_LEFT of %GTK_POS_RIGHT,
328 	 * a column is inserted.
329 	 *
330 	 * Params:
331 	 *     sibling = the child of @grid that the new row or column will be
332 	 *         placed next to
333 	 *     side = the side of @sibling that @child is positioned next to
334 	 */
335 	public void insertNextTo(Widget sibling, GtkPositionType side)
336 	{
337 		gtk_grid_insert_next_to(gtkGrid, (sibling is null) ? null : sibling.getWidgetStruct(), side);
338 	}
339 
340 	/**
341 	 * Inserts a row at the specified position.
342 	 *
343 	 * Children which are attached at or below this position
344 	 * are moved one row down. Children which span across this
345 	 * position are grown to span the new row.
346 	 *
347 	 * Params:
348 	 *     position = the position to insert the row at
349 	 */
350 	public void insertRow(int position)
351 	{
352 		gtk_grid_insert_row(gtkGrid, position);
353 	}
354 
355 	/**
356 	 * Queries the attach points and spans of @child inside the given `GtkGrid`.
357 	 *
358 	 * Params:
359 	 *     child = a `GtkWidget` child of @grid
360 	 *     column = the column used to attach the left side of @child
361 	 *     row = the row used to attach the top side of @child
362 	 *     width = the number of columns @child spans
363 	 *     height = the number of rows @child spans
364 	 */
365 	public void queryChild(Widget child, out int column, out int row, out int width, out int height)
366 	{
367 		gtk_grid_query_child(gtkGrid, (child is null) ? null : child.getWidgetStruct(), &column, &row, &width, &height);
368 	}
369 
370 	/**
371 	 * Removes a child from @grid.
372 	 *
373 	 * The child must have been added with
374 	 * [method@Gtk.Grid.attach] or [method@Gtk.Grid.attach_next_to].
375 	 *
376 	 * Params:
377 	 *     child = the child widget to remove
378 	 */
379 	public void remove(Widget child)
380 	{
381 		gtk_grid_remove(gtkGrid, (child is null) ? null : child.getWidgetStruct());
382 	}
383 
384 	/**
385 	 * Removes a column from the grid.
386 	 *
387 	 * Children that are placed in this column are removed,
388 	 * spanning children that overlap this column have their
389 	 * width reduced by one, and children after the column
390 	 * are moved to the left.
391 	 *
392 	 * Params:
393 	 *     position = the position of the column to remove
394 	 */
395 	public void removeColumn(int position)
396 	{
397 		gtk_grid_remove_column(gtkGrid, position);
398 	}
399 
400 	/**
401 	 * Removes a row from the grid.
402 	 *
403 	 * Children that are placed in this row are removed,
404 	 * spanning children that overlap this row have their
405 	 * height reduced by one, and children below the row
406 	 * are moved up.
407 	 *
408 	 * Params:
409 	 *     position = the position of the row to remove
410 	 */
411 	public void removeRow(int position)
412 	{
413 		gtk_grid_remove_row(gtkGrid, position);
414 	}
415 
416 	/**
417 	 * Sets which row defines the global baseline for the entire grid.
418 	 *
419 	 * Each row in the grid can have its own local baseline, but only
420 	 * one of those is global, meaning it will be the baseline in the
421 	 * parent of the @grid.
422 	 *
423 	 * Params:
424 	 *     row = the row index
425 	 */
426 	public void setBaselineRow(int row)
427 	{
428 		gtk_grid_set_baseline_row(gtkGrid, row);
429 	}
430 
431 	/**
432 	 * Sets whether all columns of @grid will have the same width.
433 	 *
434 	 * Params:
435 	 *     homogeneous = %TRUE to make columns homogeneous
436 	 */
437 	public void setColumnHomogeneous(bool homogeneous)
438 	{
439 		gtk_grid_set_column_homogeneous(gtkGrid, homogeneous);
440 	}
441 
442 	/**
443 	 * Sets the amount of space between columns of @grid.
444 	 *
445 	 * Params:
446 	 *     spacing = the amount of space to insert between columns
447 	 */
448 	public void setColumnSpacing(uint spacing)
449 	{
450 		gtk_grid_set_column_spacing(gtkGrid, spacing);
451 	}
452 
453 	/**
454 	 * Sets how the baseline should be positioned on @row of the
455 	 * grid, in case that row is assigned more space than is requested.
456 	 *
457 	 * The default baseline position is %GTK_BASELINE_POSITION_CENTER.
458 	 *
459 	 * Params:
460 	 *     row = a row index
461 	 *     pos = a `GtkBaselinePosition`
462 	 */
463 	public void setRowBaselinePosition(int row, GtkBaselinePosition pos)
464 	{
465 		gtk_grid_set_row_baseline_position(gtkGrid, row, pos);
466 	}
467 
468 	/**
469 	 * Sets whether all rows of @grid will have the same height.
470 	 *
471 	 * Params:
472 	 *     homogeneous = %TRUE to make rows homogeneous
473 	 */
474 	public void setRowHomogeneous(bool homogeneous)
475 	{
476 		gtk_grid_set_row_homogeneous(gtkGrid, homogeneous);
477 	}
478 
479 	/**
480 	 * Sets the amount of space between rows of @grid.
481 	 *
482 	 * Params:
483 	 *     spacing = the amount of space to insert between rows
484 	 */
485 	public void setRowSpacing(uint spacing)
486 	{
487 		gtk_grid_set_row_spacing(gtkGrid, spacing);
488 	}
489 }