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 36 37 /** 38 * `GtkSizeGroup` groups widgets together so they all request the same size. 39 * 40 * This is typically useful when you want a column of widgets to have the 41 * same size, but you can’t use a `GtkGrid`. 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 [method@Gtk.SizeGroup.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. 53 * 54 * `GtkSizeGroup` objects are referenced by each widget in the size group, 55 * so once you have added all widgets to a `GtkSizeGroup`, you can drop 56 * the initial reference to the size group with g_object_unref(). If the 57 * widgets in the size group are subsequently destroyed, then they will 58 * be removed from the size group and drop their references on the size 59 * group; when all widgets have been removed, the size group will be 60 * freed. 61 * 62 * Widgets can be part of multiple size groups; GTK will compute the 63 * horizontal size of a widget from the horizontal requisition of all 64 * widgets that can be reached from the widget by a chain of size groups 65 * of type %GTK_SIZE_GROUP_HORIZONTAL or %GTK_SIZE_GROUP_BOTH, and the 66 * vertical size from the vertical requisition of all widgets that can be 67 * reached from the widget by a chain of size groups of type 68 * %GTK_SIZE_GROUP_VERTICAL or %GTK_SIZE_GROUP_BOTH. 69 * 70 * Note that only non-contextual sizes of every widget are ever consulted 71 * by size groups (since size groups have no knowledge of what size a widget 72 * will be allocated in one dimension, it cannot derive how much height 73 * a widget will receive for a given width). When grouping widgets that 74 * trade height for width in mode %GTK_SIZE_GROUP_VERTICAL or %GTK_SIZE_GROUP_BOTH: 75 * the height for the minimum width will be the requested height for all 76 * widgets in the group. The same is of course true when horizontally grouping 77 * width for height widgets. 78 * 79 * Widgets that trade height-for-width should set a reasonably large minimum 80 * width by way of [property@Gtk.Label:width-chars] for instance. Widgets with 81 * static sizes as well as widgets that grow (such as ellipsizing text) need no 82 * such considerations. 83 * 84 * # GtkSizeGroup as GtkBuildable 85 * 86 * Size groups can be specified in a UI definition by placing an <object> 87 * element with `class="GtkSizeGroup"` somewhere in the UI definition. The 88 * widgets that belong to the size group are specified by a <widgets> element 89 * that may contain multiple <widget> elements, one for each member of the 90 * size group. The ”name” attribute gives the id of the widget. 91 * 92 * An example of a UI definition fragment with `GtkSizeGroup`: 93 * ```xml 94 * <object class="GtkSizeGroup"> 95 * <property name="mode">horizontal</property> 96 * <widgets> 97 * <widget name="radio1"/> 98 * <widget name="radio2"/> 99 * </widgets> 100 * </object> 101 * ``` 102 */ 103 public class SizeGroup : ObjectG, BuildableIF 104 { 105 /** the main Gtk struct */ 106 protected GtkSizeGroup* gtkSizeGroup; 107 108 /** Get the main Gtk struct */ 109 public GtkSizeGroup* getSizeGroupStruct(bool transferOwnership = false) 110 { 111 if (transferOwnership) 112 ownedRef = false; 113 return gtkSizeGroup; 114 } 115 116 /** the main Gtk struct as a void* */ 117 protected override void* getStruct() 118 { 119 return cast(void*)gtkSizeGroup; 120 } 121 122 /** 123 * Sets our main struct and passes it to the parent class. 124 */ 125 public this (GtkSizeGroup* gtkSizeGroup, bool ownedRef = false) 126 { 127 this.gtkSizeGroup = gtkSizeGroup; 128 super(cast(GObject*)gtkSizeGroup, ownedRef); 129 } 130 131 // add the Buildable capabilities 132 mixin BuildableT!(GtkSizeGroup); 133 134 135 /** */ 136 public static GType getType() 137 { 138 return gtk_size_group_get_type(); 139 } 140 141 /** 142 * Create a new `GtkSizeGroup`. 143 * 144 * Params: 145 * mode = the mode for the new size group. 146 * 147 * Returns: a newly created `GtkSizeGroup` 148 * 149 * Throws: ConstructionException GTK+ fails to create the object. 150 */ 151 public this(GtkSizeGroupMode mode) 152 { 153 auto __p = gtk_size_group_new(mode); 154 155 if(__p is null) 156 { 157 throw new ConstructionException("null returned by new"); 158 } 159 160 this(cast(GtkSizeGroup*) __p, true); 161 } 162 163 /** 164 * Adds a widget to a `GtkSizeGroup`. 165 * 166 * 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. 171 * See [method@Gtk.SizeGroup.set_mode]. 172 * 173 * When the widget is destroyed or no longer referenced elsewhere, it 174 * will be removed from the size group. 175 * 176 * Params: 177 * widget = the `GtkWidget` to add 178 */ 179 public void addWidget(Widget widget) 180 { 181 gtk_size_group_add_widget(gtkSizeGroup, (widget is null) ? null : widget.getWidgetStruct()); 182 } 183 184 /** 185 * Gets the current mode of the size group. 186 * 187 * Returns: the current mode of the size group. 188 */ 189 public GtkSizeGroupMode getMode() 190 { 191 return gtk_size_group_get_mode(gtkSizeGroup); 192 } 193 194 /** 195 * Returns the list of widgets associated with @size_group. 196 * 197 * Returns: a `GSList` of 198 * widgets. The list is owned by GTK and should not be modified. 199 */ 200 public ListSG getWidgets() 201 { 202 auto __p = gtk_size_group_get_widgets(gtkSizeGroup); 203 204 if(__p is null) 205 { 206 return null; 207 } 208 209 return new ListSG(cast(GSList*) __p); 210 } 211 212 /** 213 * Removes a widget from a `GtkSizeGroup`. 214 * 215 * Params: 216 * widget = the `GtkWidget` to remove 217 */ 218 public void removeWidget(Widget widget) 219 { 220 gtk_size_group_remove_widget(gtkSizeGroup, (widget is null) ? null : widget.getWidgetStruct()); 221 } 222 223 /** 224 * Sets the `GtkSizeGroupMode` of the size group. 225 * 226 * The mode of the size group determines whether the widgets in the 227 * size group should all have the same horizontal requisition 228 * (%GTK_SIZE_GROUP_HORIZONTAL) all have the same vertical requisition 229 * (%GTK_SIZE_GROUP_VERTICAL), or should all have the same requisition 230 * in both directions (%GTK_SIZE_GROUP_BOTH). 231 * 232 * Params: 233 * mode = the mode to set for the size group. 234 */ 235 public void setMode(GtkSizeGroupMode mode) 236 { 237 gtk_size_group_set_mode(gtkSizeGroup, mode); 238 } 239 }