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().
90 	 *
91 	 * Params:
92 	 *     name = the name of the action
93 	 *     parameterType = the type of parameter to the activate function
94 	 *
95 	 * Returns: a new #GSimpleAction
96 	 *
97 	 * Since: 2.28
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this(string name, VariantType parameterType)
102 	{
103 		auto p = g_simple_action_new(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct());
104 
105 		if(p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 
110 		this(cast(GSimpleAction*) p, true);
111 	}
112 
113 	/**
114 	 * Creates a new stateful action.
115 	 *
116 	 * @state is the initial state of the action.  All future state values
117 	 * must have the same #GVariantType as the initial state.
118 	 *
119 	 * If the @state GVariant is floating, it is consumed.
120 	 *
121 	 * Params:
122 	 *     name = the name of the action
123 	 *     parameterType = the type of the parameter to the activate function
124 	 *     state = the initial state of the action
125 	 *
126 	 * Returns: a new #GSimpleAction
127 	 *
128 	 * Since: 2.28
129 	 *
130 	 * Throws: ConstructionException GTK+ fails to create the object.
131 	 */
132 	public this(string name, VariantType parameterType, Variant state)
133 	{
134 		auto p = g_simple_action_new_stateful(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct(), (state is null) ? null : state.getVariantStruct());
135 
136 		if(p is null)
137 		{
138 			throw new ConstructionException("null returned by new_stateful");
139 		}
140 
141 		this(cast(GSimpleAction*) p, true);
142 	}
143 
144 	/**
145 	 * Sets the action as enabled or not.
146 	 *
147 	 * An action must be enabled in order to be activated or in order to
148 	 * have its state changed from outside callers.
149 	 *
150 	 * This should only be called by the implementor of the action.  Users
151 	 * of the action should not attempt to modify its enabled flag.
152 	 *
153 	 * Params:
154 	 *     enabled = whether the action is enabled
155 	 *
156 	 * Since: 2.28
157 	 */
158 	public void setEnabled(bool enabled)
159 	{
160 		g_simple_action_set_enabled(gSimpleAction, enabled);
161 	}
162 
163 	/**
164 	 * Sets the state of the action.
165 	 *
166 	 * This directly updates the 'state' property to the given value.
167 	 *
168 	 * This should only be called by the implementor of the action.  Users
169 	 * of the action should not attempt to directly modify the 'state'
170 	 * property.  Instead, they should call g_action_change_state() to
171 	 * request the change.
172 	 *
173 	 * If the @value GVariant is floating, it is consumed.
174 	 *
175 	 * Params:
176 	 *     value = the new #GVariant for the state
177 	 *
178 	 * Since: 2.30
179 	 */
180 	public void setState(Variant value)
181 	{
182 		g_simple_action_set_state(gSimpleAction, (value is null) ? null : value.getVariantStruct());
183 	}
184 
185 	/**
186 	 * Sets the state hint for the action.
187 	 *
188 	 * See g_action_get_state_hint() for more information about
189 	 * action state hints.
190 	 *
191 	 * Params:
192 	 *     stateHint = a #GVariant representing the state hint
193 	 *
194 	 * Since: 2.44
195 	 */
196 	public void setStateHint(Variant stateHint)
197 	{
198 		g_simple_action_set_state_hint(gSimpleAction, (stateHint is null) ? null : stateHint.getVariantStruct());
199 	}
200 
201 	/**
202 	 * Indicates that the action was just activated.
203 	 *
204 	 * @parameter will always be of the expected type.  In the event that
205 	 * an incorrect type was given, no signal will be emitted.
206 	 *
207 	 * Since GLib 2.40, if no handler is connected to this signal then the
208 	 * default behaviour for boolean-stated actions with a %NULL parameter
209 	 * type is to toggle them via the #GSimpleAction::change-state signal.
210 	 * For stateful actions where the state type is equal to the parameter
211 	 * type, the default is to forward them directly to
212 	 * #GSimpleAction::change-state.  This should allow almost all users
213 	 * of #GSimpleAction to connect only one handler or the other.
214 	 *
215 	 * Params:
216 	 *     parameter = the parameter to the activation
217 	 *
218 	 * Since: 2.28
219 	 */
220 	gulong addOnActivate(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
221 	{
222 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
223 	}
224 
225 	/**
226 	 * Indicates that the action just received a request to change its
227 	 * state.
228 	 *
229 	 * @value will always be of the correct state type.  In the event that
230 	 * an incorrect type was given, no signal will be emitted.
231 	 *
232 	 * If no handler is connected to this signal then the default
233 	 * behaviour is to call g_simple_action_set_state() to set the state
234 	 * to the requested value. If you connect a signal handler then no
235 	 * default action is taken. If the state should change then you must
236 	 * call g_simple_action_set_state() from the handler.
237 	 *
238 	 * An example of a 'change-state' handler:
239 	 * |[<!-- language="C" -->
240 	 * static void
241 	 * change_volume_state (GSimpleAction *action,
242 	 * GVariant      *value,
243 	 * gpointer       user_data)
244 	 * {
245 	 * gint requested;
246 	 *
247 	 * requested = g_variant_get_int32 (value);
248 	 *
249 	 * // Volume only goes from 0 to 10
250 	 * if (0 <= requested && requested <= 10)
251 	 * g_simple_action_set_state (action, value);
252 	 * }
253 	 * ]|
254 	 *
255 	 * The handler need not set the state to the requested value.
256 	 * It could set it to any value at all, or take some other action.
257 	 *
258 	 * Params:
259 	 *     value = the requested value for the state
260 	 *
261 	 * Since: 2.30
262 	 */
263 	gulong addOnChangeState(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
264 	{
265 		return Signals.connect(this, "change-state", dlg, connectFlags ^ ConnectFlags.SWAPPED);
266 	}
267 }