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