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