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