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