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 gio.SimpleAction;
26 
27 private import gio.ActionIF;
28 private import gio.ActionT;
29 private import gio.c.functions;
30 public  import gio.c.types;
31 private import glib.ConstructionException;
32 private import glib.Str;
33 private import glib.Variant;
34 private import glib.VariantType;
35 private import gobject.ObjectG;
36 private import gobject.Signals;
37 private import std.algorithm;
38 
39 
40 /**
41  * A #GSimpleAction is the obvious simple implementation of the #GAction
42  * interface. This is the easiest way to create an action for purposes of
43  * adding it to a #GSimpleActionGroup.
44  * 
45  * See also #GtkAction.
46  */
47 public class SimpleAction : ObjectG, ActionIF
48 {
49 	/** the main Gtk struct */
50 	protected GSimpleAction* gSimpleAction;
51 
52 	/** Get the main Gtk struct */
53 	public GSimpleAction* getSimpleActionStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gSimpleAction;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gSimpleAction;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GSimpleAction* gSimpleAction, bool ownedRef = false)
70 	{
71 		this.gSimpleAction = gSimpleAction;
72 		super(cast(GObject*)gSimpleAction, ownedRef);
73 	}
74 
75 	// add the Action capabilities
76 	mixin ActionT!(GSimpleAction);
77 
78 
79 	/** */
80 	public static GType getType()
81 	{
82 		return g_simple_action_get_type();
83 	}
84 
85 	/**
86 	 * Creates a new action.
87 	 *
88 	 * The created action is stateless. See g_simple_action_new_stateful() to create
89 	 * an action that has state.
90 	 *
91 	 * Params:
92 	 *     name = the name of the action
93 	 *     parameterType = the type of parameter that will be passed to
94 	 *         handlers for the #GSimpleAction::activate signal, or %NULL for no parameter
95 	 *
96 	 * Returns: a new #GSimpleAction
97 	 *
98 	 * Since: 2.28
99 	 *
100 	 * Throws: ConstructionException GTK+ fails to create the object.
101 	 */
102 	public this(string name, VariantType parameterType)
103 	{
104 		auto __p = g_simple_action_new(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct());
105 
106 		if(__p is null)
107 		{
108 			throw new ConstructionException("null returned by new");
109 		}
110 
111 		this(cast(GSimpleAction*) __p, true);
112 	}
113 
114 	/**
115 	 * Creates a new stateful action.
116 	 *
117 	 * All future state values must have the same #GVariantType as the initial
118 	 * @state.
119 	 *
120 	 * If the @state #GVariant is floating, it is consumed.
121 	 *
122 	 * Params:
123 	 *     name = the name of the action
124 	 *     parameterType = the type of the parameter that will be passed to
125 	 *         handlers for the #GSimpleAction::activate signal, or %NULL for no parameter
126 	 *     state = the initial state of the action
127 	 *
128 	 * Returns: a new #GSimpleAction
129 	 *
130 	 * Since: 2.28
131 	 *
132 	 * Throws: ConstructionException GTK+ fails to create the object.
133 	 */
134 	public this(string name, VariantType parameterType, Variant state)
135 	{
136 		auto __p = g_simple_action_new_stateful(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct(), (state is null) ? null : state.getVariantStruct());
137 
138 		if(__p is null)
139 		{
140 			throw new ConstructionException("null returned by new_stateful");
141 		}
142 
143 		this(cast(GSimpleAction*) __p, true);
144 	}
145 
146 	/**
147 	 * Sets the action as enabled or not.
148 	 *
149 	 * An action must be enabled in order to be activated or in order to
150 	 * have its state changed from outside callers.
151 	 *
152 	 * This should only be called by the implementor of the action.  Users
153 	 * of the action should not attempt to modify its enabled flag.
154 	 *
155 	 * Params:
156 	 *     enabled = whether the action is enabled
157 	 *
158 	 * Since: 2.28
159 	 */
160 	public void setEnabled(bool enabled)
161 	{
162 		g_simple_action_set_enabled(gSimpleAction, enabled);
163 	}
164 
165 	/**
166 	 * Sets the state of the action.
167 	 *
168 	 * This directly updates the 'state' property to the given value.
169 	 *
170 	 * This should only be called by the implementor of the action.  Users
171 	 * of the action should not attempt to directly modify the 'state'
172 	 * property.  Instead, they should call g_action_change_state() to
173 	 * request the change.
174 	 *
175 	 * If the @value GVariant is floating, it is consumed.
176 	 *
177 	 * Params:
178 	 *     value = the new #GVariant for the state
179 	 *
180 	 * Since: 2.30
181 	 */
182 	public void setState(Variant value)
183 	{
184 		g_simple_action_set_state(gSimpleAction, (value is null) ? null : value.getVariantStruct());
185 	}
186 
187 	/**
188 	 * Sets the state hint for the action.
189 	 *
190 	 * See g_action_get_state_hint() for more information about
191 	 * action state hints.
192 	 *
193 	 * Params:
194 	 *     stateHint = a #GVariant representing the state hint
195 	 *
196 	 * Since: 2.44
197 	 */
198 	public void setStateHint(Variant stateHint)
199 	{
200 		g_simple_action_set_state_hint(gSimpleAction, (stateHint is null) ? null : stateHint.getVariantStruct());
201 	}
202 
203 	/**
204 	 * Indicates that the action was just activated.
205 	 *
206 	 * @parameter will always be of the expected type, i.e. the parameter type
207 	 * specified when the action was created. If an incorrect type is given when
208 	 * activating the action, this signal is not emitted.
209 	 *
210 	 * Since GLib 2.40, if no handler is connected to this signal then the
211 	 * default behaviour for boolean-stated actions with a %NULL parameter
212 	 * type is to toggle them via the #GSimpleAction::change-state signal.
213 	 * For stateful actions where the state type is equal to the parameter
214 	 * type, the default is to forward them directly to
215 	 * #GSimpleAction::change-state.  This should allow almost all users
216 	 * of #GSimpleAction to connect only one handler or the other.
217 	 *
218 	 * Params:
219 	 *     parameter = the parameter to the activation, or %NULL if it has
220 	 *         no parameter
221 	 *
222 	 * Since: 2.28
223 	 */
224 	gulong addOnActivate(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
225 	{
226 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
227 	}
228 
229 	/**
230 	 * Indicates that the action just received a request to change its
231 	 * state.
232 	 *
233 	 * @value will always be of the correct state type, i.e. the type of the
234 	 * initial state passed to g_simple_action_new_stateful(). If an incorrect
235 	 * type is given when requesting to change the state, this signal is not
236 	 * emitted.
237 	 *
238 	 * If no handler is connected to this signal then the default
239 	 * behaviour is to call g_simple_action_set_state() to set the state
240 	 * to the requested value. If you connect a signal handler then no
241 	 * default action is taken. If the state should change then you must
242 	 * call g_simple_action_set_state() from the handler.
243 	 *
244 	 * An example of a 'change-state' handler:
245 	 * |[<!-- language="C" -->
246 	 * static void
247 	 * change_volume_state (GSimpleAction *action,
248 	 * GVariant      *value,
249 	 * gpointer       user_data)
250 	 * {
251 	 * gint requested;
252 	 *
253 	 * requested = g_variant_get_int32 (value);
254 	 *
255 	 * // Volume only goes from 0 to 10
256 	 * if (0 <= requested && requested <= 10)
257 	 * g_simple_action_set_state (action, value);
258 	 * }
259 	 * ]|
260 	 *
261 	 * The handler need not set the state to the requested value.
262 	 * It could set it to any value at all, or take some other action.
263 	 *
264 	 * Params:
265 	 *     value = the requested value for the state
266 	 *
267 	 * Since: 2.30
268 	 */
269 	gulong addOnChangeState(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
270 	{
271 		return Signals.connect(this, "change-state", dlg, connectFlags ^ ConnectFlags.SWAPPED);
272 	}
273 }