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.Box;
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  * The GtkBox widget arranges child widgets into a single row or column,
40  * depending upon the value of its #GtkOrientable:orientation property. Within
41  * the other dimension, all children are allocated the same size. Of course,
42  * the #GtkWidget:halign and #GtkWidget:valign properties can be used on
43  * the children to influence their allocation.
44  * 
45  * GtkBox uses a notion of packing. Packing refers
46  * to adding widgets with reference to a particular position in a
47  * #GtkContainer. For a GtkBox, there are two reference positions: the
48  * start and the end of the box.
49  * For a vertical #GtkBox, the start is defined as the top of the box and
50  * the end is defined as the bottom. For a horizontal #GtkBox the start
51  * is defined as the left side and the end is defined as the right side.
52  * 
53  * Use repeated calls to gtk_box_pack_start() to pack widgets into a
54  * GtkBox from start to end. Use gtk_box_pack_end() to add widgets from
55  * end to start. You may intersperse these calls and add widgets from
56  * both ends of the same GtkBox.
57  * 
58  * Because GtkBox is a #GtkContainer, you may also use gtk_container_add()
59  * to insert widgets into the box, and they will be packed with the default
60  * values for expand and fill child properties. Use gtk_container_remove()
61  * to remove widgets from the GtkBox.
62  * 
63  * Use gtk_box_set_homogeneous() to specify whether or not all children
64  * of the GtkBox are forced to get the same amount of space.
65  * 
66  * Use gtk_box_set_spacing() to determine how much space will be
67  * minimally placed between all children in the GtkBox. Note that
68  * spacing is added between the children, while
69  * padding added by gtk_box_pack_start() or gtk_box_pack_end() is added
70  * on either side of the widget it belongs to.
71  * 
72  * Use gtk_box_reorder_child() to move a GtkBox child to a different
73  * place in the box.
74  * 
75  * Use gtk_box_set_child_packing() to reset the expand,
76  * fill and padding child properties.
77  * Use gtk_box_query_child_packing() to query these fields.
78  * 
79  * # CSS nodes
80  * 
81  * GtkBox uses a single CSS node with name box.
82  * 
83  * In horizontal orientation, the nodes of the children are always arranged
84  * from left to right. So :first-child will always select the leftmost child,
85  * regardless of text direction.
86  */
87 public class Box : Container, OrientableIF
88 {
89 	/** the main Gtk struct */
90 	protected GtkBox* gtkBox;
91 
92 	/** Get the main Gtk struct */
93 	public GtkBox* getBoxStruct(bool transferOwnership = false)
94 	{
95 		if (transferOwnership)
96 			ownedRef = false;
97 		return gtkBox;
98 	}
99 
100 	/** the main Gtk struct as a void* */
101 	protected override void* getStruct()
102 	{
103 		return cast(void*)gtkBox;
104 	}
105 
106 	/**
107 	 * Sets our main struct and passes it to the parent class.
108 	 */
109 	public this (GtkBox* gtkBox, bool ownedRef = false)
110 	{
111 		this.gtkBox = gtkBox;
112 		super(cast(GtkContainer*)gtkBox, ownedRef);
113 	}
114 
115 	// add the Orientable capabilities
116 	mixin OrientableT!(GtkBox);
117 
118 
119 	/** */
120 	public static GType getType()
121 	{
122 		return gtk_box_get_type();
123 	}
124 
125 	/**
126 	 * Creates a new #GtkBox.
127 	 *
128 	 * Params:
129 	 *     orientation = the box’s orientation.
130 	 *     spacing = the number of pixels to place by default between children.
131 	 *
132 	 * Returns: a new #GtkBox.
133 	 *
134 	 * Since: 3.0
135 	 *
136 	 * Throws: ConstructionException GTK+ fails to create the object.
137 	 */
138 	public this(GtkOrientation orientation, int spacing)
139 	{
140 		auto p = gtk_box_new(orientation, spacing);
141 
142 		if(p is null)
143 		{
144 			throw new ConstructionException("null returned by new");
145 		}
146 
147 		this(cast(GtkBox*) p);
148 	}
149 
150 	/**
151 	 * Gets the value set by gtk_box_set_baseline_position().
152 	 *
153 	 * Returns: the baseline position
154 	 *
155 	 * Since: 3.10
156 	 */
157 	public GtkBaselinePosition getBaselinePosition()
158 	{
159 		return gtk_box_get_baseline_position(gtkBox);
160 	}
161 
162 	/**
163 	 * Retrieves the center widget of the box.
164 	 *
165 	 * Returns: the center widget
166 	 *     or %NULL in case no center widget is set.
167 	 *
168 	 * Since: 3.12
169 	 */
170 	public Widget getCenterWidget()
171 	{
172 		auto p = gtk_box_get_center_widget(gtkBox);
173 
174 		if(p is null)
175 		{
176 			return null;
177 		}
178 
179 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
180 	}
181 
182 	/**
183 	 * Returns whether the box is homogeneous (all children are the
184 	 * same size). See gtk_box_set_homogeneous().
185 	 *
186 	 * Returns: %TRUE if the box is homogeneous.
187 	 */
188 	public bool getHomogeneous()
189 	{
190 		return gtk_box_get_homogeneous(gtkBox) != 0;
191 	}
192 
193 	/**
194 	 * Gets the value set by gtk_box_set_spacing().
195 	 *
196 	 * Returns: spacing between children
197 	 */
198 	public int getSpacing()
199 	{
200 		return gtk_box_get_spacing(gtkBox);
201 	}
202 
203 	/**
204 	 * Adds @child to @box, packed with reference to the end of @box.
205 	 * The @child is packed after (away from end of) any other child
206 	 * packed with reference to the end of @box.
207 	 *
208 	 * Params:
209 	 *     child = the #GtkWidget to be added to @box
210 	 *     expand = %TRUE if the new child is to be given extra space allocated
211 	 *         to @box. The extra space will be divided evenly between all children
212 	 *         of @box that use this option
213 	 *     fill = %TRUE if space given to @child by the @expand option is
214 	 *         actually allocated to @child, rather than just padding it.  This
215 	 *         parameter has no effect if @expand is set to %FALSE.  A child is
216 	 *         always allocated the full height of a horizontal #GtkBox and the full width
217 	 *         of a vertical #GtkBox.  This option affects the other dimension
218 	 *     padding = extra space in pixels to put between this child and its
219 	 *         neighbors, over and above the global amount specified by
220 	 *         #GtkBox:spacing property.  If @child is a widget at one of the
221 	 *         reference ends of @box, then @padding pixels are also put between
222 	 *         @child and the reference edge of @box
223 	 */
224 	public void packEnd(Widget child, bool expand, bool fill, uint padding)
225 	{
226 		gtk_box_pack_end(gtkBox, (child is null) ? null : child.getWidgetStruct(), expand, fill, padding);
227 	}
228 
229 	/**
230 	 * Adds @child to @box, packed with reference to the start of @box.
231 	 * The @child is packed after any other child packed with reference
232 	 * to the start of @box.
233 	 *
234 	 * Params:
235 	 *     child = the #GtkWidget to be added to @box
236 	 *     expand = %TRUE if the new child is to be given extra space allocated
237 	 *         to @box. The extra space will be divided evenly between all children
238 	 *         that use this option
239 	 *     fill = %TRUE if space given to @child by the @expand option is
240 	 *         actually allocated to @child, rather than just padding it.  This
241 	 *         parameter has no effect if @expand is set to %FALSE.  A child is
242 	 *         always allocated the full height of a horizontal #GtkBox and the full width
243 	 *         of a vertical #GtkBox. This option affects the other dimension
244 	 *     padding = extra space in pixels to put between this child and its
245 	 *         neighbors, over and above the global amount specified by
246 	 *         #GtkBox:spacing property.  If @child is a widget at one of the
247 	 *         reference ends of @box, then @padding pixels are also put between
248 	 *         @child and the reference edge of @box
249 	 */
250 	public void packStart(Widget child, bool expand, bool fill, uint padding)
251 	{
252 		gtk_box_pack_start(gtkBox, (child is null) ? null : child.getWidgetStruct(), expand, fill, padding);
253 	}
254 
255 	/**
256 	 * Obtains information about how @child is packed into @box.
257 	 *
258 	 * Params:
259 	 *     child = the #GtkWidget of the child to query
260 	 *     expand = pointer to return location for expand child
261 	 *         property
262 	 *     fill = pointer to return location for fill child
263 	 *         property
264 	 *     padding = pointer to return location for padding
265 	 *         child property
266 	 *     packType = pointer to return location for pack-type
267 	 *         child property
268 	 */
269 	public void queryChildPacking(Widget child, out bool expand, out bool fill, out uint padding, out GtkPackType packType)
270 	{
271 		int outexpand;
272 		int outfill;
273 
274 		gtk_box_query_child_packing(gtkBox, (child is null) ? null : child.getWidgetStruct(), &outexpand, &outfill, &padding, &packType);
275 
276 		expand = (outexpand == 1);
277 		fill = (outfill == 1);
278 	}
279 
280 	/**
281 	 * Moves @child to a new @position in the list of @box children.
282 	 * The list contains widgets packed #GTK_PACK_START
283 	 * as well as widgets packed #GTK_PACK_END, in the order that these
284 	 * widgets were added to @box.
285 	 *
286 	 * A widget’s position in the @box children list determines where
287 	 * the widget is packed into @box.  A child widget at some position
288 	 * in the list will be packed just after all other widgets of the
289 	 * same packing type that appear earlier in the list.
290 	 *
291 	 * Params:
292 	 *     child = the #GtkWidget to move
293 	 *     position = the new position for @child in the list of children
294 	 *         of @box, starting from 0. If negative, indicates the end of
295 	 *         the list
296 	 */
297 	public void reorderChild(Widget child, int position)
298 	{
299 		gtk_box_reorder_child(gtkBox, (child is null) ? null : child.getWidgetStruct(), position);
300 	}
301 
302 	/**
303 	 * Sets the baseline position of a box. This affects
304 	 * only horizontal boxes with at least one baseline aligned
305 	 * child. If there is more vertical space available than requested,
306 	 * and the baseline is not allocated by the parent then
307 	 * @position is used to allocate the baseline wrt the
308 	 * extra space available.
309 	 *
310 	 * Params:
311 	 *     position = a #GtkBaselinePosition
312 	 *
313 	 * Since: 3.10
314 	 */
315 	public void setBaselinePosition(GtkBaselinePosition position)
316 	{
317 		gtk_box_set_baseline_position(gtkBox, position);
318 	}
319 
320 	/**
321 	 * Sets a center widget; that is a child widget that will be
322 	 * centered with respect to the full width of the box, even
323 	 * if the children at either side take up different amounts
324 	 * of space.
325 	 *
326 	 * Params:
327 	 *     widget = the widget to center
328 	 *
329 	 * Since: 3.12
330 	 */
331 	public void setCenterWidget(Widget widget)
332 	{
333 		gtk_box_set_center_widget(gtkBox, (widget is null) ? null : widget.getWidgetStruct());
334 	}
335 
336 	/**
337 	 * Sets the way @child is packed into @box.
338 	 *
339 	 * Params:
340 	 *     child = the #GtkWidget of the child to set
341 	 *     expand = the new value of the expand child property
342 	 *     fill = the new value of the fill child property
343 	 *     padding = the new value of the padding child property
344 	 *     packType = the new value of the pack-type child property
345 	 */
346 	public void setChildPacking(Widget child, bool expand, bool fill, uint padding, GtkPackType packType)
347 	{
348 		gtk_box_set_child_packing(gtkBox, (child is null) ? null : child.getWidgetStruct(), expand, fill, padding, packType);
349 	}
350 
351 	/**
352 	 * Sets the #GtkBox:homogeneous property of @box, controlling
353 	 * whether or not all children of @box are given equal space
354 	 * in the box.
355 	 *
356 	 * Params:
357 	 *     homogeneous = a boolean value, %TRUE to create equal allotments,
358 	 *         %FALSE for variable allotments
359 	 */
360 	public void setHomogeneous(bool homogeneous)
361 	{
362 		gtk_box_set_homogeneous(gtkBox, homogeneous);
363 	}
364 
365 	/**
366 	 * Sets the #GtkBox:spacing property of @box, which is the
367 	 * number of pixels to place between children of @box.
368 	 *
369 	 * Params:
370 	 *     spacing = the number of pixels to put between children
371 	 */
372 	public void setSpacing(int spacing)
373 	{
374 		gtk_box_set_spacing(gtkBox, spacing);
375 	}
376 }