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 * Conversion parameters: 26 * inFile = GtkRadioButton.html 27 * outPack = gtk 28 * outFile = RadioButton 29 * strct = GtkRadioButton 30 * realStrct= 31 * ctorStrct= 32 * clss = RadioButton 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_radio_button_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * - gtk_radio_button_new_with_label 45 * - gtk_radio_button_new_with_mnemonic 46 * - gtk_radio_button_new_with_label_from_widget 47 * - gtk_radio_button_new_with_mnemonic_from_widget 48 * omit signals: 49 * imports: 50 * - glib.Str 51 * - glib.ListSG 52 * structWrap: 53 * - GSList* -> ListSG 54 * - GtkRadioButton* -> RadioButton 55 * module aliases: 56 * local aliases: 57 * overrides: 58 */ 59 60 module gtk.RadioButton; 61 62 public import gtkc.gtktypes; 63 64 private import gtkc.gtk; 65 private import glib.ConstructionException; 66 private import gobject.ObjectG; 67 68 private import gobject.Signals; 69 public import gtkc.gdktypes; 70 private import glib.Str; 71 private import glib.ListSG; 72 73 74 private import gtk.CheckButton; 75 76 /** 77 * A single radio button performs the same basic function as a GtkCheckButton, 78 * as its position in the object hierarchy reflects. It is only when multiple 79 * radio buttons are grouped together that they become a different user 80 * interface component in their own right. 81 * 82 * Every radio button is a member of some group of radio buttons. When one is 83 * selected, all other radio buttons in the same group are deselected. A 84 * GtkRadioButton is one way of giving the user a choice from many options. 85 * 86 * Radio button widgets are created with gtk_radio_button_new(), passing NULL 87 * as the argument if this is the first radio button in a group. In subsequent 88 * calls, the group you wish to add this button to should be passed as an 89 * argument. Optionally, gtk_radio_button_new_with_label() can be used if you 90 * want a text label on the radio button. 91 * 92 * Alternatively, when adding widgets to an existing group of radio buttons, 93 * use gtk_radio_button_new_from_widget() with a GtkRadioButton that already 94 * has a group assigned to it. The convenience function 95 * gtk_radio_button_new_with_label_from_widget() is also provided. 96 * 97 * To retrieve the group a GtkRadioButton is assigned to, use 98 * gtk_radio_button_get_group(). 99 * 100 * To remove a GtkRadioButton from one group and make it part of a new one, 101 * use gtk_radio_button_set_group(). 102 * 103 * The group list does not need to be freed, as each GtkRadioButton will remove 104 * itself and its list item when it is destroyed. 105 * 106 * $(DDOC_COMMENT example) 107 * 108 * When an unselected button in the group is clicked the clicked button 109 * receives the "toggled" signal, as does the previously 110 * selected button. 111 * Inside the "toggled" handler, gtk_toggle_button_get_active() 112 * can be used to determine if the button has been selected or deselected. 113 */ 114 public class RadioButton : CheckButton 115 { 116 117 /** the main Gtk struct */ 118 protected GtkRadioButton* gtkRadioButton; 119 120 121 /** Get the main Gtk struct */ 122 public GtkRadioButton* getRadioButtonStruct() 123 { 124 return gtkRadioButton; 125 } 126 127 128 /** the main Gtk struct as a void* */ 129 protected override void* getStruct() 130 { 131 return cast(void*)gtkRadioButton; 132 } 133 134 /** 135 * Sets our main struct and passes it to the parent class 136 */ 137 public this (GtkRadioButton* gtkRadioButton) 138 { 139 super(cast(GtkCheckButton*)gtkRadioButton); 140 this.gtkRadioButton = gtkRadioButton; 141 } 142 143 protected override void setStruct(GObject* obj) 144 { 145 super.setStruct(obj); 146 gtkRadioButton = cast(GtkRadioButton*)obj; 147 } 148 149 /** 150 * Creates a new RadioButton with a text label. 151 * Params: 152 * group = an existing radio button group. 153 * label = the text label to display next to the radio button. 154 * mnemonic = if true the label will be created using 155 * gtk_label_new_with_mnemonic(), so underscores in label indicate the 156 * mnemonic for the button. 157 * Throws: ConstructionException GTK+ fails to create the object. 158 */ 159 public this (ListSG group, string label, bool mnemonic=true) 160 { 161 GtkRadioButton* p; 162 163 if ( mnemonic ) 164 { 165 // GtkWidget* gtk_radio_button_new_with_mnemonic (GSList *group, const gchar *label); 166 p = cast(GtkRadioButton*)gtk_radio_button_new_with_mnemonic( 167 group is null ? null : group.getListSGStruct(), 168 Str.toStringz(label)); 169 } 170 else 171 { 172 // GtkWidget* gtk_radio_button_new_with_label (GSList *group, const gchar *label); 173 p = cast(GtkRadioButton*)gtk_radio_button_new_with_label( 174 group is null ? null : group.getListSGStruct(), 175 Str.toStringz(label)); 176 } 177 178 if(p is null) 179 { 180 throw new ConstructionException("null returned by gtk_radio_button_new_"); 181 } 182 183 this(p); 184 } 185 186 /** 187 * Creates a new RadioButton with a text label, adding it to the same group 188 * as group. 189 * Params: 190 * radioButton = an existing RadioButton. 191 * label = a text string to display next to the radio button. 192 * mnemonic = if true the label 193 * will be created using gtk_label_new_with_mnemonic(), so underscores 194 * in label indicate the mnemonic for the button. 195 * Throws: ConstructionException GTK+ fails to create the object. 196 */ 197 public this (RadioButton radioButton, string label, bool mnemonic=true) 198 { 199 GtkRadioButton* p; 200 201 if ( mnemonic ) 202 { 203 // GtkWidget* gtk_radio_button_new_with_mnemonic_from_widget (GtkRadioButton *group, const gchar *label); 204 p = cast(GtkRadioButton*)gtk_radio_button_new_with_mnemonic_from_widget( 205 radioButton.getRadioButtonStruct(), 206 Str.toStringz(label)); 207 } 208 else 209 { 210 // GtkWidget* gtk_radio_button_new_with_label_from_widget (GtkRadioButton *group, const gchar *label); 211 p = cast(GtkRadioButton*)gtk_radio_button_new_with_label_from_widget( 212 radioButton.getRadioButtonStruct(), 213 Str.toStringz(label)); 214 } 215 216 if(p is null) 217 { 218 throw new ConstructionException("null returned by gtk_radio_button_new_"); 219 } 220 221 this(p); 222 } 223 224 /** 225 * Creates a new RadioButton with a text label, 226 * and creates a new group. 227 * Params: 228 * label = a text string to display next to the radio button. 229 * mnemonic = if true the label 230 * will be created using gtk_label_new_with_mnemonic(), so underscores 231 * in label indicate the mnemonic for the button. 232 * Throws: ConstructionException GTK+ fails to create the object. 233 */ 234 public this (string label, bool mnemonic=true) 235 { 236 this(cast(ListSG)null, label, mnemonic); 237 } 238 239 /** 240 */ 241 int[string] connectedSignals; 242 243 void delegate(RadioButton)[] onGroupChangedListeners; 244 /** 245 * Emitted when the group of radio buttons that a radio button belongs 246 * to changes. This is emitted when a radio button switches from 247 * being alone to being part of a group of 2 or more buttons, or 248 * vice-versa, and when a button is moved from one group of 2 or 249 * more buttons to a different one, but not when the composition 250 * of the group that a button belongs to changes. 251 * Since 2.4 252 * See Also 253 * GtkComboBox 254 */ 255 void addOnGroupChanged(void delegate(RadioButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 256 { 257 if ( !("group-changed" in connectedSignals) ) 258 { 259 Signals.connectData( 260 getStruct(), 261 "group-changed", 262 cast(GCallback)&callBackGroupChanged, 263 cast(void*)this, 264 null, 265 connectFlags); 266 connectedSignals["group-changed"] = 1; 267 } 268 onGroupChangedListeners ~= dlg; 269 } 270 extern(C) static void callBackGroupChanged(GtkRadioButton* buttonStruct, RadioButton _radioButton) 271 { 272 foreach ( void delegate(RadioButton) dlg ; _radioButton.onGroupChangedListeners ) 273 { 274 dlg(_radioButton); 275 } 276 } 277 278 279 /** 280 * Creates a new GtkRadioButton. To be of any practical value, a widget should 281 * then be packed into the radio button. 282 * Params: 283 * group = an existing 284 * radio button group, or NULL if you are creating a new group. [element-type GtkRadioButton][allow-none] 285 * Throws: ConstructionException GTK+ fails to create the object. 286 */ 287 public this (ListSG group) 288 { 289 // GtkWidget * gtk_radio_button_new (GSList *group); 290 auto p = gtk_radio_button_new((group is null) ? null : group.getListSGStruct()); 291 if(p is null) 292 { 293 throw new ConstructionException("null returned by gtk_radio_button_new((group is null) ? null : group.getListSGStruct())"); 294 } 295 this(cast(GtkRadioButton*) p); 296 } 297 298 /** 299 * Creates a new GtkRadioButton, adding it to the same group as 300 * radio_group_member. As with gtk_radio_button_new(), a widget 301 * should be packed into the radio button. 302 * Params: 303 * radioGroupMember = an existing GtkRadioButton. [allow-none] 304 * Throws: ConstructionException GTK+ fails to create the object. 305 */ 306 public this (RadioButton radioGroupMember) 307 { 308 // GtkWidget * gtk_radio_button_new_from_widget (GtkRadioButton *radio_group_member); 309 auto p = gtk_radio_button_new_from_widget((radioGroupMember is null) ? null : radioGroupMember.getRadioButtonStruct()); 310 if(p is null) 311 { 312 throw new ConstructionException("null returned by gtk_radio_button_new_from_widget((radioGroupMember is null) ? null : radioGroupMember.getRadioButtonStruct())"); 313 } 314 this(cast(GtkRadioButton*) p); 315 } 316 317 /** 318 * Sets a GtkRadioButton's group. It should be noted that this does not change 319 * the layout of your interface in any way, so if you are changing the group, 320 * it is likely you will need to re-arrange the user interface to reflect these 321 * changes. 322 * Params: 323 * group = an existing radio 324 * button group, such as one returned from gtk_radio_button_get_group(). [transfer none][element-type GtkRadioButton] 325 */ 326 public void setGroup(ListSG group) 327 { 328 // void gtk_radio_button_set_group (GtkRadioButton *radio_button, GSList *group); 329 gtk_radio_button_set_group(gtkRadioButton, (group is null) ? null : group.getListSGStruct()); 330 } 331 332 /** 333 * Retrieves the group assigned to a radio button. 334 * Returns: a linked list containing all the radio buttons in the same group as radio_button. The returned list is owned by the radio button and must not be modified or freed. [element-type GtkRadioButton][transfer none] 335 */ 336 public ListSG getGroup() 337 { 338 // GSList * gtk_radio_button_get_group (GtkRadioButton *radio_button); 339 auto p = gtk_radio_button_get_group(gtkRadioButton); 340 341 if(p is null) 342 { 343 return null; 344 } 345 346 return ObjectG.getDObject!(ListSG)(cast(GSList*) p); 347 } 348 349 /** 350 * Joins a GtkRadioButton object to the group of another GtkRadioButton object 351 * Use this in language bindings instead of the gtk_radio_button_get_group() 352 * and gtk_radio_button_set_group() methods 353 * Params: 354 * groupSource = a radio button object whos group we are 355 * joining, or NULL to remove the radio button from its group. [allow-none] 356 * Since 3.0 357 */ 358 public void joinGroup(RadioButton groupSource) 359 { 360 // void gtk_radio_button_join_group (GtkRadioButton *radio_button, GtkRadioButton *group_source); 361 gtk_radio_button_join_group(gtkRadioButton, (groupSource is null) ? null : groupSource.getRadioButtonStruct()); 362 } 363 }