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.SizeGroup;
26 
27 private import glib.ConstructionException;
28 private import glib.ListSG;
29 private import gobject.ObjectG;
30 private import gtk.BuildableIF;
31 private import gtk.BuildableT;
32 private import gtk.Widget;
33 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 
36 
37 /**
38  * #GtkSizeGroup provides a mechanism for grouping a number of widgets
39  * together so they all request the same amount of space.  This is
40  * typically useful when you want a column of widgets to have the same
41  * size, but you can’t use a #GtkGrid widget.
42  * 
43  * In detail, the size requested for each widget in a #GtkSizeGroup is
44  * the maximum of the sizes that would have been requested for each
45  * widget in the size group if they were not in the size group. The mode
46  * of the size group (see gtk_size_group_set_mode()) determines whether
47  * this applies to the horizontal size, the vertical size, or both sizes.
48  * 
49  * Note that size groups only affect the amount of space requested, not
50  * the size that the widgets finally receive. If you want the widgets in
51  * a #GtkSizeGroup to actually be the same size, you need to pack them in
52  * such a way that they get the size they request and not more. For
53  * example, if you are packing your widgets into a table, you would not
54  * include the %GTK_FILL flag.
55  * 
56  * #GtkSizeGroup objects are referenced by each widget in the size group,
57  * so once you have added all widgets to a #GtkSizeGroup, you can drop
58  * the initial reference to the size group with g_object_unref(). If the
59  * widgets in the size group are subsequently destroyed, then they will
60  * be removed from the size group and drop their references on the size
61  * group; when all widgets have been removed, the size group will be
62  * freed.
63  * 
64  * Widgets can be part of multiple size groups; GTK+ will compute the
65  * horizontal size of a widget from the horizontal requisition of all
66  * widgets that can be reached from the widget by a chain of size groups
67  * of type %GTK_SIZE_GROUP_HORIZONTAL or %GTK_SIZE_GROUP_BOTH, and the
68  * vertical size from the vertical requisition of all widgets that can be
69  * reached from the widget by a chain of size groups of type
70  * %GTK_SIZE_GROUP_VERTICAL or %GTK_SIZE_GROUP_BOTH.
71  * 
72  * Note that only non-contextual sizes of every widget are ever consulted
73  * by size groups (since size groups have no knowledge of what size a widget
74  * will be allocated in one dimension, it cannot derive how much height
75  * a widget will receive for a given width). When grouping widgets that
76  * trade height for width in mode %GTK_SIZE_GROUP_VERTICAL or %GTK_SIZE_GROUP_BOTH:
77  * the height for the minimum width will be the requested height for all
78  * widgets in the group. The same is of course true when horizontally grouping
79  * width for height widgets.
80  * 
81  * Widgets that trade height-for-width should set a reasonably large minimum width
82  * by way of #GtkLabel:width-chars for instance. Widgets with static sizes as well
83  * as widgets that grow (such as ellipsizing text) need no such considerations.
84  * 
85  * # GtkSizeGroup as GtkBuildable
86  * 
87  * Size groups can be specified in a UI definition by placing an <object>
88  * element with `class="GtkSizeGroup"` somewhere in the UI definition. The
89  * widgets that belong to the size group are specified by a <widgets> element
90  * that may contain multiple <widget> elements, one for each member of the
91  * size group. The ”name” attribute gives the id of the widget.
92  * 
93  * An example of a UI definition fragment with GtkSizeGroup:
94  * |[
95  * <object class="GtkSizeGroup">
96  * <property name="mode">GTK_SIZE_GROUP_HORIZONTAL</property>
97  * <widgets>
98  * <widget name="radio1"/>
99  * <widget name="radio2"/>
100  * </widgets>
101  * </object>
102  * ]|
103  */
104 public class SizeGroup : ObjectG, BuildableIF
105 {
106 	/** the main Gtk struct */
107 	protected GtkSizeGroup* gtkSizeGroup;
108 
109 	/** Get the main Gtk struct */
110 	public GtkSizeGroup* getSizeGroupStruct()
111 	{
112 		return gtkSizeGroup;
113 	}
114 
115 	/** the main Gtk struct as a void* */
116 	protected override void* getStruct()
117 	{
118 		return cast(void*)gtkSizeGroup;
119 	}
120 
121 	protected override void setStruct(GObject* obj)
122 	{
123 		gtkSizeGroup = cast(GtkSizeGroup*)obj;
124 		super.setStruct(obj);
125 	}
126 
127 	/**
128 	 * Sets our main struct and passes it to the parent class.
129 	 */
130 	public this (GtkSizeGroup* gtkSizeGroup, bool ownedRef = false)
131 	{
132 		this.gtkSizeGroup = gtkSizeGroup;
133 		super(cast(GObject*)gtkSizeGroup, ownedRef);
134 	}
135 
136 	// add the Buildable capabilities
137 	mixin BuildableT!(GtkSizeGroup);
138 
139 	/**
140 	 */
141 
142 	public static GType getType()
143 	{
144 		return gtk_size_group_get_type();
145 	}
146 
147 	/**
148 	 * Create a new #GtkSizeGroup.
149 	 *
150 	 * Params:
151 	 *     mode = the mode for the new size group.
152 	 *
153 	 * Return: a newly created #GtkSizeGroup
154 	 *
155 	 * Throws: ConstructionException GTK+ fails to create the object.
156 	 */
157 	public this(GtkSizeGroupMode mode)
158 	{
159 		auto p = gtk_size_group_new(mode);
160 		
161 		if(p is null)
162 		{
163 			throw new ConstructionException("null returned by new");
164 		}
165 		
166 		this(cast(GtkSizeGroup*) p, true);
167 	}
168 
169 	/**
170 	 * Adds a widget to a #GtkSizeGroup. In the future, the requisition
171 	 * of the widget will be determined as the maximum of its requisition
172 	 * and the requisition of the other widgets in the size group.
173 	 * Whether this applies horizontally, vertically, or in both directions
174 	 * depends on the mode of the size group. See gtk_size_group_set_mode().
175 	 *
176 	 * When the widget is destroyed or no longer referenced elsewhere, it will
177 	 * be removed from the size group.
178 	 *
179 	 * Params:
180 	 *     widget = the #GtkWidget to add
181 	 */
182 	public void addWidget(Widget widget)
183 	{
184 		gtk_size_group_add_widget(gtkSizeGroup, (widget is null) ? null : widget.getWidgetStruct());
185 	}
186 
187 	/**
188 	 * Returns if invisible widgets are ignored when calculating the size.
189 	 *
190 	 * Return: %TRUE if invisible widgets are ignored.
191 	 *
192 	 * Since: 2.8
193 	 */
194 	public bool getIgnoreHidden()
195 	{
196 		return gtk_size_group_get_ignore_hidden(gtkSizeGroup) != 0;
197 	}
198 
199 	/**
200 	 * Gets the current mode of the size group. See gtk_size_group_set_mode().
201 	 *
202 	 * Return: the current mode of the size group.
203 	 */
204 	public GtkSizeGroupMode getMode()
205 	{
206 		return gtk_size_group_get_mode(gtkSizeGroup);
207 	}
208 
209 	/**
210 	 * Returns the list of widgets associated with @size_group.
211 	 *
212 	 * Return: a #GSList of
213 	 *     widgets. The list is owned by GTK+ and should not be modified.
214 	 *
215 	 * Since: 2.10
216 	 */
217 	public ListSG getWidgets()
218 	{
219 		auto p = gtk_size_group_get_widgets(gtkSizeGroup);
220 		
221 		if(p is null)
222 		{
223 			return null;
224 		}
225 		
226 		return new ListSG(cast(GSList*) p);
227 	}
228 
229 	/**
230 	 * Removes a widget from a #GtkSizeGroup.
231 	 *
232 	 * Params:
233 	 *     widget = the #GtkWidget to remove
234 	 */
235 	public void removeWidget(Widget widget)
236 	{
237 		gtk_size_group_remove_widget(gtkSizeGroup, (widget is null) ? null : widget.getWidgetStruct());
238 	}
239 
240 	/**
241 	 * Sets whether unmapped widgets should be ignored when
242 	 * calculating the size.
243 	 *
244 	 * Params:
245 	 *     ignoreHidden = whether unmapped widgets should be ignored
246 	 *         when calculating the size
247 	 *
248 	 * Since: 2.8
249 	 */
250 	public void setIgnoreHidden(bool ignoreHidden)
251 	{
252 		gtk_size_group_set_ignore_hidden(gtkSizeGroup, ignoreHidden);
253 	}
254 
255 	/**
256 	 * Sets the #GtkSizeGroupMode of the size group. The mode of the size
257 	 * group determines whether the widgets in the size group should
258 	 * all have the same horizontal requisition (%GTK_SIZE_GROUP_HORIZONTAL)
259 	 * all have the same vertical requisition (%GTK_SIZE_GROUP_VERTICAL),
260 	 * or should all have the same requisition in both directions
261 	 * (%GTK_SIZE_GROUP_BOTH).
262 	 *
263 	 * Params:
264 	 *     mode = the mode to set for the size group.
265 	 */
266 	public void setMode(GtkSizeGroupMode mode)
267 	{
268 		gtk_size_group_set_mode(gtkSizeGroup, mode);
269 	}
270 }