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 	public static GType getType()
142 	{
143 		return gtk_size_group_get_type();
144 	}
145 
146 	/**
147 	 * Create a new #GtkSizeGroup.
148 	 *
149 	 * Params:
150 	 *     mode = the mode for the new size group.
151 	 *
152 	 * Return: a newly created #GtkSizeGroup
153 	 *
154 	 * Throws: ConstructionException GTK+ fails to create the object.
155 	 */
156 	public this(GtkSizeGroupMode mode)
157 	{
158 		auto p = gtk_size_group_new(mode);
159 		
160 		if(p is null)
161 		{
162 			throw new ConstructionException("null returned by new");
163 		}
164 		
165 		this(cast(GtkSizeGroup*) p, true);
166 	}
167 
168 	/**
169 	 * Adds a widget to a #GtkSizeGroup. In the future, the requisition
170 	 * of the widget will be determined as the maximum of its requisition
171 	 * and the requisition of the other widgets in the size group.
172 	 * Whether this applies horizontally, vertically, or in both directions
173 	 * depends on the mode of the size group. See gtk_size_group_set_mode().
174 	 *
175 	 * When the widget is destroyed or no longer referenced elsewhere, it will
176 	 * be removed from the size group.
177 	 *
178 	 * Params:
179 	 *     widget = the #GtkWidget to add
180 	 */
181 	public void addWidget(Widget widget)
182 	{
183 		gtk_size_group_add_widget(gtkSizeGroup, (widget is null) ? null : widget.getWidgetStruct());
184 	}
185 
186 	/**
187 	 * Returns if invisible widgets are ignored when calculating the size.
188 	 *
189 	 * Return: %TRUE if invisible widgets are ignored.
190 	 *
191 	 * Since: 2.8
192 	 */
193 	public bool getIgnoreHidden()
194 	{
195 		return gtk_size_group_get_ignore_hidden(gtkSizeGroup) != 0;
196 	}
197 
198 	/**
199 	 * Gets the current mode of the size group. See gtk_size_group_set_mode().
200 	 *
201 	 * Return: the current mode of the size group.
202 	 */
203 	public GtkSizeGroupMode getMode()
204 	{
205 		return gtk_size_group_get_mode(gtkSizeGroup);
206 	}
207 
208 	/**
209 	 * Returns the list of widgets associated with @size_group.
210 	 *
211 	 * Return: a #GSList of
212 	 *     widgets. The list is owned by GTK+ and should not be modified.
213 	 *
214 	 * Since: 2.10
215 	 */
216 	public ListSG getWidgets()
217 	{
218 		auto p = gtk_size_group_get_widgets(gtkSizeGroup);
219 		
220 		if(p is null)
221 		{
222 			return null;
223 		}
224 		
225 		return new ListSG(cast(GSList*) p);
226 	}
227 
228 	/**
229 	 * Removes a widget from a #GtkSizeGroup.
230 	 *
231 	 * Params:
232 	 *     widget = the #GtkWidget to remove
233 	 */
234 	public void removeWidget(Widget widget)
235 	{
236 		gtk_size_group_remove_widget(gtkSizeGroup, (widget is null) ? null : widget.getWidgetStruct());
237 	}
238 
239 	/**
240 	 * Sets whether unmapped widgets should be ignored when
241 	 * calculating the size.
242 	 *
243 	 * Params:
244 	 *     ignoreHidden = whether unmapped widgets should be ignored
245 	 *         when calculating the size
246 	 *
247 	 * Since: 2.8
248 	 */
249 	public void setIgnoreHidden(bool ignoreHidden)
250 	{
251 		gtk_size_group_set_ignore_hidden(gtkSizeGroup, ignoreHidden);
252 	}
253 
254 	/**
255 	 * Sets the #GtkSizeGroupMode of the size group. The mode of the size
256 	 * group determines whether the widgets in the size group should
257 	 * all have the same horizontal requisition (%GTK_SIZE_GROUP_HORIZONTAL)
258 	 * all have the same vertical requisition (%GTK_SIZE_GROUP_VERTICAL),
259 	 * or should all have the same requisition in both directions
260 	 * (%GTK_SIZE_GROUP_BOTH).
261 	 *
262 	 * Params:
263 	 *     mode = the mode to set for the size group.
264 	 */
265 	public void setMode(GtkSizeGroupMode mode)
266 	{
267 		gtk_size_group_set_mode(gtkSizeGroup, mode);
268 	}
269 }