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 	/**
125 	 * Sets our main struct and passes it to the parent class.
126 	 */
127 	public this (GtkSizeGroup* gtkSizeGroup, bool ownedRef = false)
128 	{
129 		this.gtkSizeGroup = gtkSizeGroup;
130 		super(cast(GObject*)gtkSizeGroup, ownedRef);
131 	}
132 
133 	// add the Buildable capabilities
134 	mixin BuildableT!(GtkSizeGroup);
135 
136 
137 	/** */
138 	public static GType getType()
139 	{
140 		return gtk_size_group_get_type();
141 	}
142 
143 	/**
144 	 * Create a new #GtkSizeGroup.
145 	 *
146 	 * Params:
147 	 *     mode = the mode for the new size group.
148 	 *
149 	 * Returns: a newly created #GtkSizeGroup
150 	 *
151 	 * Throws: ConstructionException GTK+ fails to create the object.
152 	 */
153 	public this(GtkSizeGroupMode mode)
154 	{
155 		auto p = gtk_size_group_new(mode);
156 
157 		if(p is null)
158 		{
159 			throw new ConstructionException("null returned by new");
160 		}
161 
162 		this(cast(GtkSizeGroup*) p, true);
163 	}
164 
165 	/**
166 	 * Adds a widget to a #GtkSizeGroup. In the future, the requisition
167 	 * of the widget will be determined as the maximum of its requisition
168 	 * and the requisition of the other widgets in the size group.
169 	 * Whether this applies horizontally, vertically, or in both directions
170 	 * depends on the mode of the size group. See gtk_size_group_set_mode().
171 	 *
172 	 * When the widget is destroyed or no longer referenced elsewhere, it will
173 	 * be removed from the size group.
174 	 *
175 	 * Params:
176 	 *     widget = the #GtkWidget to add
177 	 */
178 	public void addWidget(Widget widget)
179 	{
180 		gtk_size_group_add_widget(gtkSizeGroup, (widget is null) ? null : widget.getWidgetStruct());
181 	}
182 
183 	/**
184 	 * Returns if invisible widgets are ignored when calculating the size.
185 	 *
186 	 * Deprecated: Measuring the size of hidden widgets has not worked
187 	 * reliably for a long time. In most cases, they will report a size
188 	 * of 0 nowadays, and thus, their size will not affect the other
189 	 * size group members. In effect, size groups will always operate
190 	 * as if this property was %TRUE. Use a #GtkStack instead to hide
191 	 * widgets while still having their size taken into account.
192 	 *
193 	 * Returns: %TRUE if invisible widgets are ignored.
194 	 *
195 	 * Since: 2.8
196 	 */
197 	public bool getIgnoreHidden()
198 	{
199 		return gtk_size_group_get_ignore_hidden(gtkSizeGroup) != 0;
200 	}
201 
202 	/**
203 	 * Gets the current mode of the size group. See gtk_size_group_set_mode().
204 	 *
205 	 * Returns: the current mode of the size group.
206 	 */
207 	public GtkSizeGroupMode getMode()
208 	{
209 		return gtk_size_group_get_mode(gtkSizeGroup);
210 	}
211 
212 	/**
213 	 * Returns the list of widgets associated with @size_group.
214 	 *
215 	 * Returns: a #GSList of
216 	 *     widgets. The list is owned by GTK+ and should not be modified.
217 	 *
218 	 * Since: 2.10
219 	 */
220 	public ListSG getWidgets()
221 	{
222 		auto p = gtk_size_group_get_widgets(gtkSizeGroup);
223 
224 		if(p is null)
225 		{
226 			return null;
227 		}
228 
229 		return new ListSG(cast(GSList*) p);
230 	}
231 
232 	/**
233 	 * Removes a widget from a #GtkSizeGroup.
234 	 *
235 	 * Params:
236 	 *     widget = the #GtkWidget to remove
237 	 */
238 	public void removeWidget(Widget widget)
239 	{
240 		gtk_size_group_remove_widget(gtkSizeGroup, (widget is null) ? null : widget.getWidgetStruct());
241 	}
242 
243 	/**
244 	 * Sets whether unmapped widgets should be ignored when
245 	 * calculating the size.
246 	 *
247 	 * Deprecated: Measuring the size of hidden widgets has not worked
248 	 * reliably for a long time. In most cases, they will report a size
249 	 * of 0 nowadays, and thus, their size will not affect the other
250 	 * size group members. In effect, size groups will always operate
251 	 * as if this property was %TRUE. Use a #GtkStack instead to hide
252 	 * widgets while still having their size taken into account.
253 	 *
254 	 * Params:
255 	 *     ignoreHidden = whether unmapped widgets should be ignored
256 	 *         when calculating the size
257 	 *
258 	 * Since: 2.8
259 	 */
260 	public void setIgnoreHidden(bool ignoreHidden)
261 	{
262 		gtk_size_group_set_ignore_hidden(gtkSizeGroup, ignoreHidden);
263 	}
264 
265 	/**
266 	 * Sets the #GtkSizeGroupMode of the size group. The mode of the size
267 	 * group determines whether the widgets in the size group should
268 	 * all have the same horizontal requisition (%GTK_SIZE_GROUP_HORIZONTAL)
269 	 * all have the same vertical requisition (%GTK_SIZE_GROUP_VERTICAL),
270 	 * or should all have the same requisition in both directions
271 	 * (%GTK_SIZE_GROUP_BOTH).
272 	 *
273 	 * Params:
274 	 *     mode = the mode to set for the size group.
275 	 */
276 	public void setMode(GtkSizeGroupMode mode)
277 	{
278 		gtk_size_group_set_mode(gtkSizeGroup, mode);
279 	}
280 }