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