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