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 	/** */
101 	public static GType getType()
102 	{
103 		return gtk_radio_action_get_type();
104 	}
105 
106 	/**
107 	 * Creates a new #GtkRadioAction object. To add the action to
108 	 * a #GtkActionGroup and set the accelerator for the action,
109 	 * call gtk_action_group_add_action_with_accel().
110 	 *
111 	 * Params:
112 	 *     name = A unique name for the action
113 	 *     label = The label displayed in menu items and on buttons,
114 	 *         or %NULL
115 	 *     tooltip = A tooltip for this action, or %NULL
116 	 *     stockId = The stock icon to display in widgets representing
117 	 *         this action, or %NULL
118 	 *     value = The value which gtk_radio_action_get_current_value() should
119 	 *         return if this action is selected.
120 	 *
121 	 * Return: a new #GtkRadioAction
122 	 *
123 	 * Since: 2.4
124 	 *
125 	 * Throws: ConstructionException GTK+ fails to create the object.
126 	 */
127 	public this(string name, string label, string tooltip, string stockId, int value)
128 	{
129 		auto p = gtk_radio_action_new(Str.toStringz(name), Str.toStringz(label), Str.toStringz(tooltip), Str.toStringz(stockId), value);
130 		
131 		if(p is null)
132 		{
133 			throw new ConstructionException("null returned by new");
134 		}
135 		
136 		this(cast(GtkRadioAction*) p, true);
137 	}
138 
139 	/**
140 	 * Obtains the value property of the currently active member of
141 	 * the group to which @action belongs.
142 	 *
143 	 * Return: The value of the currently active group member
144 	 *
145 	 * Since: 2.4
146 	 */
147 	public int getCurrentValue()
148 	{
149 		return gtk_radio_action_get_current_value(gtkRadioAction);
150 	}
151 
152 	/**
153 	 * Returns the list representing the radio group for this object.
154 	 * Note that the returned list is only valid until the next change
155 	 * to the group.
156 	 *
157 	 * A common way to set up a group of radio group is the following:
158 	 * |[<!-- language="C" -->
159 	 * GSList *group = NULL;
160 	 * GtkRadioAction *action;
161 	 *
162 	 * while ( ...more actions to add... /)
163 	 * {
164 	 * action = gtk_radio_action_new (...);
165 	 *
166 	 * gtk_radio_action_set_group (action, group);
167 	 * group = gtk_radio_action_get_group (action);
168 	 * }
169 	 * ]|
170 	 *
171 	 * Return: the list representing the radio group for this object
172 	 *
173 	 * Since: 2.4
174 	 */
175 	public ListSG getGroup()
176 	{
177 		auto p = gtk_radio_action_get_group(gtkRadioAction);
178 		
179 		if(p is null)
180 		{
181 			return null;
182 		}
183 		
184 		return new ListSG(cast(GSList*) p);
185 	}
186 
187 	/**
188 	 * Joins a radio action object to the group of another radio action object.
189 	 *
190 	 * Use this in language bindings instead of the gtk_radio_action_get_group()
191 	 * and gtk_radio_action_set_group() methods
192 	 *
193 	 * A common way to set up a group of radio actions is the following:
194 	 * |[<!-- language="C" -->
195 	 * GtkRadioAction *action;
196 	 * GtkRadioAction *last_action;
197 	 *
198 	 * while ( ...more actions to add... /)
199 	 * {
200 	 * action = gtk_radio_action_new (...);
201 	 *
202 	 * gtk_radio_action_join_group (action, last_action);
203 	 * last_action = action;
204 	 * }
205 	 * ]|
206 	 *
207 	 * Params:
208 	 *     groupSource = a radio action object whos group we are
209 	 *         joining, or %NULL to remove the radio action from its group
210 	 *
211 	 * Since: 3.0
212 	 */
213 	public void joinGroup(RadioAction groupSource)
214 	{
215 		gtk_radio_action_join_group(gtkRadioAction, (groupSource is null) ? null : groupSource.getRadioActionStruct());
216 	}
217 
218 	/**
219 	 * Sets the currently active group member to the member with value
220 	 * property @current_value.
221 	 *
222 	 * Params:
223 	 *     currentValue = the new value
224 	 *
225 	 * Since: 2.10
226 	 */
227 	public void setCurrentValue(int currentValue)
228 	{
229 		gtk_radio_action_set_current_value(gtkRadioAction, currentValue);
230 	}
231 
232 	/**
233 	 * Sets the radio group for the radio action object.
234 	 *
235 	 * Params:
236 	 *     group = a list representing a radio group, or %NULL
237 	 *
238 	 * Since: 2.4
239 	 */
240 	public void setGroup(ListSG group)
241 	{
242 		gtk_radio_action_set_group(gtkRadioAction, (group is null) ? null : group.getListSGStruct());
243 	}
244 
245 	int[string] connectedSignals;
246 
247 	void delegate(RadioAction, RadioAction)[] onChangedListeners;
248 	/**
249 	 * The ::changed signal is emitted on every member of a radio group when the
250 	 * active member is changed. The signal gets emitted after the ::activate signals
251 	 * for the previous and current active members.
252 	 *
253 	 * Params:
254 	 *     current = the member of @action's group which has just been activated
255 	 *
256 	 * Since: 2.4
257 	 */
258 	void addOnChanged(void delegate(RadioAction, RadioAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
259 	{
260 		if ( "changed" !in connectedSignals )
261 		{
262 			Signals.connectData(
263 				this,
264 				"changed",
265 				cast(GCallback)&callBackChanged,
266 				cast(void*)this,
267 				null,
268 				connectFlags);
269 			connectedSignals["changed"] = 1;
270 		}
271 		onChangedListeners ~= dlg;
272 	}
273 	extern(C) static void callBackChanged(GtkRadioAction* radioactionStruct, GtkRadioAction* current, RadioAction _radioaction)
274 	{
275 		foreach ( void delegate(RadioAction, RadioAction) dlg; _radioaction.onChangedListeners )
276 		{
277 			dlg(ObjectG.getDObject!(RadioAction)(current), _radioaction);
278 		}
279 	}
280 }