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