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.RadioAction;
26 
27 private import glib.ConstructionException;
28 private import glib.ListSG;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gtk.ToggleAction;
33 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * A #GtkRadioAction is similar to #GtkRadioMenuItem. A number of radio
40  * actions can be linked together so that only one may be active at any
41  * one time.
42  */
43 public class RadioAction : ToggleAction
44 {
45 	/** the main Gtk struct */
46 	protected GtkRadioAction* gtkRadioAction;
47 
48 	/** Get the main Gtk struct */
49 	public GtkRadioAction* getRadioActionStruct()
50 	{
51 		return gtkRadioAction;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected override void* getStruct()
56 	{
57 		return cast(void*)gtkRadioAction;
58 	}
59 
60 	protected override void setStruct(GObject* obj)
61 	{
62 		gtkRadioAction = cast(GtkRadioAction*)obj;
63 		super.setStruct(obj);
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GtkRadioAction* gtkRadioAction, bool ownedRef = false)
70 	{
71 		this.gtkRadioAction = gtkRadioAction;
72 		super(cast(GtkToggleAction*)gtkRadioAction, ownedRef);
73 	}
74 
75 	/**
76 	 * Creates a new RadioAction object. To add the action to
77 	 * a ActionGroup and set the accelerator for the action,
78 	 * call gtk.ActionGroup.ActionGroup.addActionWithAccel().
79 	 *
80 	 * Since: 2.4
81 	 *
82 	 * Params:
83 	 *     name    = A unique name for the action
84 	 *     label   = The label displayed in menu items and on buttons, or null
85 	 *     tooltip = A tooltip for this action, or null
86 	 *     stockId = The stock icon to display in widgets representing this
87 	 *               action, or null
88 	 *     value   = The value which getCurrentValue() should
89 	 *               return if this action is selected.
90 	 * Throws: ConstructionException GTK+ fails to create the object.
91 	 */
92 	public this (string name, string label, string tooltip, StockID stockId, int value)
93 	{
94 		this(name, label, tooltip, cast(string)stockId, value);
95 	}
96 
97 	/**
98 	 */
99 
100 	public static GType getType()
101 	{
102 		return gtk_radio_action_get_type();
103 	}
104 
105 	/**
106 	 * Creates a new #GtkRadioAction object. To add the action to
107 	 * a #GtkActionGroup and set the accelerator for the action,
108 	 * call gtk_action_group_add_action_with_accel().
109 	 *
110 	 * Params:
111 	 *     name = A unique name for the action
112 	 *     label = The label displayed in menu items and on buttons,
113 	 *         or %NULL
114 	 *     tooltip = A tooltip for this action, or %NULL
115 	 *     stockId = The stock icon to display in widgets representing
116 	 *         this action, or %NULL
117 	 *     value = The value which gtk_radio_action_get_current_value() should
118 	 *         return if this action is selected.
119 	 *
120 	 * Return: a new #GtkRadioAction
121 	 *
122 	 * Since: 2.4
123 	 *
124 	 * Throws: ConstructionException GTK+ fails to create the object.
125 	 */
126 	public this(string name, string label, string tooltip, string stockId, int value)
127 	{
128 		auto p = gtk_radio_action_new(Str.toStringz(name), Str.toStringz(label), Str.toStringz(tooltip), Str.toStringz(stockId), value);
129 		
130 		if(p is null)
131 		{
132 			throw new ConstructionException("null returned by new");
133 		}
134 		
135 		this(cast(GtkRadioAction*) p, true);
136 	}
137 
138 	/**
139 	 * Obtains the value property of the currently active member of
140 	 * the group to which @action belongs.
141 	 *
142 	 * Return: The value of the currently active group member
143 	 *
144 	 * Since: 2.4
145 	 */
146 	public int getCurrentValue()
147 	{
148 		return gtk_radio_action_get_current_value(gtkRadioAction);
149 	}
150 
151 	/**
152 	 * Returns the list representing the radio group for this object.
153 	 * Note that the returned list is only valid until the next change
154 	 * to the group.
155 	 *
156 	 * A common way to set up a group of radio group is the following:
157 	 * |[<!-- language="C" -->
158 	 * GSList *group = NULL;
159 	 * GtkRadioAction *action;
160 	 *
161 	 * while ( ...more actions to add... /)
162 	 * {
163 	 * action = gtk_radio_action_new (...);
164 	 *
165 	 * gtk_radio_action_set_group (action, group);
166 	 * group = gtk_radio_action_get_group (action);
167 	 * }
168 	 * ]|
169 	 *
170 	 * Return: the list representing the radio group for this object
171 	 *
172 	 * Since: 2.4
173 	 */
174 	public ListSG getGroup()
175 	{
176 		auto p = gtk_radio_action_get_group(gtkRadioAction);
177 		
178 		if(p is null)
179 		{
180 			return null;
181 		}
182 		
183 		return new ListSG(cast(GSList*) p);
184 	}
185 
186 	/**
187 	 * Joins a radio action object to the group of another radio action object.
188 	 *
189 	 * Use this in language bindings instead of the gtk_radio_action_get_group()
190 	 * and gtk_radio_action_set_group() methods
191 	 *
192 	 * A common way to set up a group of radio actions is the following:
193 	 * |[<!-- language="C" -->
194 	 * GtkRadioAction *action;
195 	 * GtkRadioAction *last_action;
196 	 *
197 	 * while ( ...more actions to add... /)
198 	 * {
199 	 * action = gtk_radio_action_new (...);
200 	 *
201 	 * gtk_radio_action_join_group (action, last_action);
202 	 * last_action = action;
203 	 * }
204 	 * ]|
205 	 *
206 	 * Params:
207 	 *     groupSource = a radio action object whos group we are
208 	 *         joining, or %NULL to remove the radio action from its group
209 	 *
210 	 * Since: 3.0
211 	 */
212 	public void joinGroup(RadioAction groupSource)
213 	{
214 		gtk_radio_action_join_group(gtkRadioAction, (groupSource is null) ? null : groupSource.getRadioActionStruct());
215 	}
216 
217 	/**
218 	 * Sets the currently active group member to the member with value
219 	 * property @current_value.
220 	 *
221 	 * Params:
222 	 *     currentValue = the new value
223 	 *
224 	 * Since: 2.10
225 	 */
226 	public void setCurrentValue(int currentValue)
227 	{
228 		gtk_radio_action_set_current_value(gtkRadioAction, currentValue);
229 	}
230 
231 	/**
232 	 * Sets the radio group for the radio action object.
233 	 *
234 	 * Params:
235 	 *     group = a list representing a radio group, or %NULL
236 	 *
237 	 * Since: 2.4
238 	 */
239 	public void setGroup(ListSG group)
240 	{
241 		gtk_radio_action_set_group(gtkRadioAction, (group is null) ? null : group.getListSGStruct());
242 	}
243 
244 	int[string] connectedSignals;
245 
246 	void delegate(RadioAction, RadioAction)[] onChangedListeners;
247 	/**
248 	 * The ::changed signal is emitted on every member of a radio group when the
249 	 * active member is changed. The signal gets emitted after the ::activate signals
250 	 * for the previous and current active members.
251 	 *
252 	 * Params:
253 	 *     current = the member of @action's group which has just been activated
254 	 *
255 	 * Since: 2.4
256 	 */
257 	void addOnChanged(void delegate(RadioAction, RadioAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
258 	{
259 		if ( "changed" !in connectedSignals )
260 		{
261 			Signals.connectData(
262 				this,
263 				"changed",
264 				cast(GCallback)&callBackChanged,
265 				cast(void*)this,
266 				null,
267 				connectFlags);
268 			connectedSignals["changed"] = 1;
269 		}
270 		onChangedListeners ~= dlg;
271 	}
272 	extern(C) static void callBackChanged(GtkRadioAction* radioactionStruct, GtkRadioAction* current, RadioAction _radioaction)
273 	{
274 		foreach ( void delegate(RadioAction, RadioAction) dlg; _radioaction.onChangedListeners )
275 		{
276 			dlg(ObjectG.getDObject!(RadioAction)(current), _radioaction);
277 		}
278 	}
279 }