alternative to assert
[gtkD.git] / gtkD / src / gtk / RadioButton.d
blob236e2d5fccf9b78f6254794f04c2a47b42dea6e6
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkRadioButton.html
26 * outPack = gtk
27 * outFile = RadioButton
28 * strct = GtkRadioButton
29 * realStrct=
30 * ctorStrct=
31 * clss = RadioButton
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_radio_button_
40 * - gtk_
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 * imports:
49 * - glib.Str
50 * - glib.ListSG
51 * structWrap:
52 * - GSList* -> ListSG
53 * module aliases:
54 * local aliases:
57 module gtk.RadioButton;
59 version(noAssert)
61 version(Tango)
63 import tango.io.Stdout; // use the tango loging?
67 private import gtkc.gtktypes;
69 private import gtkc.gtk;
72 private import glib.Str;
73 private import glib.ListSG;
78 /**
79 * Description
80 * A single radio button performs the same basic function as a GtkCheckButton,
81 * as its position in the object hierarchy reflects. It is only when multiple
82 * radio buttons are grouped together that they become a different user
83 * interface component in their own right.
84 * Every radio button is a member of some group of radio buttons. When one is selected, all other
85 * radio buttons in the same group are deselected. A GtkRadioButton is one way
86 * of giving the user a choice from many options.
87 * Radio button widgets are created with gtk_radio_button_new(), passing NULL
88 * as the argument if this is the first radio button in a group. In subsequent
89 * calls, the group you wish to add this button to should be passed as an
90 * argument. Optionally, gtk_radio_button_new_with_label() can be used if you
91 * want a text label on the radio button.
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 * To retrieve the group a GtkRadioButton is assigned to, use
97 * gtk_radio_button_get_group().
98 * To remove a GtkRadioButton from one group and make it part of a new one, use gtk_radio_button_set_group().
99 * The group list does not need to be freed, as each GtkRadioButton will remove
100 * itself and its list item when it is destroyed.
101 * Example1.How to create a group of two radio buttons.
102 * void create_radio_buttons (void) {
103 * GtkWidget *window, *radio1, *radio2, *box, *entry;
104 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
105 * box = gtk_vbox_new (TRUE, 2);
106 * /+* Create a radio button with a GtkEntry widget +/
107 * radio1 = gtk_radio_button_new (NULL);
108 * entry = gtk_entry_new ();
109 * gtk_container_add (GTK_CONTAINER (radio1), entry);
110 * /+* Create a radio button with a label +/
111 * radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio1),
112 * "I'm the second radio button.");
113 * /+* Pack them into a box, then show all the widgets +/
114 * gtk_box_pack_start (GTK_BOX (box), radio1, TRUE, TRUE, 2);
115 * gtk_box_pack_start (GTK_BOX (box), radio2, TRUE, TRUE, 2);
116 * gtk_container_add (GTK_CONTAINER (window), box);
117 * gtk_widget_show_all (window);
118 * return;
120 * When an unselected button in the group is clicked the clicked button
121 * receives the "toggled" signal, as does the previously selected button.
122 * Inside the "toggled" handler, gtk_toggle_button_get_active() can be used
123 * to determine if the button has been selected or deselected.
125 private import gtk.CheckButton;
126 public class RadioButton : CheckButton
129 /** the main Gtk struct */
130 protected GtkRadioButton* gtkRadioButton;
133 public GtkRadioButton* getRadioButtonStruct()
135 return gtkRadioButton;
139 /** the main Gtk struct as a void* */
140 protected void* getStruct()
142 return cast(void*)gtkRadioButton;
146 * Sets our main struct and passes it to the parent class
148 public this (GtkRadioButton* gtkRadioButton)
150 version(noAssert)
152 if ( gtkRadioButton is null )
154 int zero = 0;
155 version(Tango)
157 Stdout("struct gtkRadioButton is null on constructor").newline;
159 else
161 printf("struct gtkRadioButton is null on constructor");
163 zero = zero / zero;
166 else
168 assert(gtkRadioButton !is null, "struct gtkRadioButton is null on constructor");
170 super(cast(GtkCheckButton*)gtkRadioButton);
171 this.gtkRadioButton = gtkRadioButton;
175 * Creates a new GtkRadioButton with a text label.
176 * If mnemonic if true the label will be created using
177 * gtk_label_new_with_mnemonic(), so underscores in label indicate the
178 * mnemonic for the button.
179 * an existing radio button group, or NULL if you are creating a new
180 * group.
181 * label:
182 * the text label to display next to the radio button.
183 * Returns:
184 * a new radio button.
186 public this (ListSG group, char[] label, bool mnemonic=true)
188 if ( mnemonic )
190 // GtkWidget* gtk_radio_button_new_with_mnemonic (GSList *group, const gchar *label);
191 this(cast(GtkRadioButton*)gtk_radio_button_new_with_mnemonic(
192 group is null ? null : group.getListSGStruct(),
193 Str.toStringz(label))
196 else
198 // GtkWidget* gtk_radio_button_new_with_label (GSList *group, const gchar *label);
199 this(cast(GtkRadioButton*)gtk_radio_button_new_with_label(
200 group is null ? null : group.getListSGStruct(),
201 Str.toStringz(label))
207 * Creates a new GtkRadioButton with a text label, adding it to the same group
208 * as group.
209 * It mnemonic it true the label
210 * will be created using gtk_label_new_with_mnemonic(), so underscores
211 * in label indicate the mnemonic for the button.
212 * group:
213 * an existing GtkRadioButton.
214 * label:
215 * a text string to display next to the radio button.
216 * Returns:
217 * a new radio button.
219 public this (RadioButton radioButton, char[] label, bool mnemonic=true)
221 if ( mnemonic )
223 // GtkWidget* gtk_radio_button_new_with_mnemonic_from_widget (GtkRadioButton *group, const gchar *label);
224 this(cast(GtkRadioButton*)gtk_radio_button_new_with_mnemonic_from_widget(
225 radioButton.getRadioButtonStruct(),
226 Str.toStringz(label))
229 else
231 // GtkWidget* gtk_radio_button_new_with_label_from_widget (GtkRadioButton *group, const gchar *label);
232 this(cast(GtkRadioButton*)gtk_radio_button_new_with_label_from_widget(
233 radioButton.getRadioButtonStruct(),
234 Str.toStringz(label))
242 // imports for the signal processing
243 private import gobject.Signals;
244 private import gtkc.gdktypes;
245 int[char[]] connectedSignals;
247 void delegate(RadioButton)[] onGroupChangedListeners;
248 void addOnGroupChanged(void delegate(RadioButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
250 if ( !("group-changed" in connectedSignals) )
252 Signals.connectData(
253 getStruct(),
254 "group-changed",
255 cast(GCallback)&callBackGroupChanged,
256 cast(void*)this,
257 null,
258 connectFlags);
259 connectedSignals["group-changed"] = 1;
261 onGroupChangedListeners ~= dlg;
263 extern(C) static void callBackGroupChanged(GtkRadioButton* styleStruct, RadioButton radioButton)
265 bool consumed = false;
267 foreach ( void delegate(RadioButton) dlg ; radioButton.onGroupChangedListeners )
269 dlg(radioButton);
272 return consumed;
278 * Creates a new GtkRadioButton. To be of any practical value, a widget should
279 * then be packed into the radio button.
280 * group:
281 * an existing radio button group, or NULL if you are creating a new group.
282 * Returns:
283 * a new radio button.
285 public this (ListSG group)
287 // GtkWidget* gtk_radio_button_new (GSList *group);
288 this(cast(GtkRadioButton*)gtk_radio_button_new((group is null) ? null : group.getListSGStruct()) );
292 * Creates a new GtkRadioButton, adding it to the same group as group. As
293 * with gtk_radio_button_new(), a widget should be packed into the radio button.
294 * group:
295 * an existing GtkRadioButton.
296 * Returns:
297 * a new radio button.
299 public this ()
301 // GtkWidget* gtk_radio_button_new_from_widget (GtkRadioButton *group);
302 this(cast(GtkRadioButton*)gtk_radio_button_new_from_widget(gtkRadioButton) );
311 * Sets a GtkRadioButton's group. It should be noted that this does not change
312 * the layout of your interface in any way, so if you are changing the group,
313 * it is likely you will need to re-arrange the user interface to reflect these
314 * changes.
315 * radio_button:
316 * a GtkRadioButton.
317 * group:
318 * an existing radio button group, such as one returned from
319 * gtk_radio_button_get_group().
321 public void setGroup(ListSG group)
323 // void gtk_radio_button_set_group (GtkRadioButton *radio_button, GSList *group);
324 gtk_radio_button_set_group(gtkRadioButton, (group is null) ? null : group.getListSGStruct());
328 * Retrieves the group assigned to a radio button.
329 * radio_button:
330 * a GtkRadioButton.
331 * Returns:
332 * a linked list containing all the radio buttons in the same group
333 * as radio_button.
334 * Property Details
335 * The "group" property
336 * "group" GtkRadioButton : Write
337 * Sets a new group for a radio button.
338 * Signal Details
339 * The "group-changed" signal
340 * void user_function (GtkRadioButton *style,
341 * gpointer user_data) : Run First
342 * Emitted when the group of radio buttons that a radio button belongs
343 * to changes. This is emitted when a radio button switches from
344 * being alone to being part of a group of 2 or more buttons, or
345 * vice-versa, and when a buttton is moved from one group of 2 or
346 * more buttons to a different one, but not when the composition
347 * of the group that a button belongs to changes.
348 * style:
349 * the object which received the signal
350 * user_data:
351 * user data set when the signal handler was connected.
352 * Since 2.4
353 * See Also
354 * GtkOptionMenu
355 * Another way of offering the user a single choice from
356 * many.
358 public ListSG getGroup()
360 // GSList* gtk_radio_button_get_group (GtkRadioButton *radio_button);
361 return new ListSG( gtk_radio_button_get_group(gtkRadioButton) );