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  * Conversion parameters:
26  * inFile  = GSimpleAction.html
27  * outPack = gio
28  * outFile = SimpleAction
29  * strct   = GSimpleAction
30  * realStrct=
31  * ctorStrct=
32  * clss    = SimpleAction
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * 	- ActionIF
40  * prefixes:
41  * 	- g_simple_action_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.Variant
49  * 	- glib.VariantType
50  * 	- gio.ActionIF
51  * 	- gio.ActionT
52  * structWrap:
53  * 	- GVariant* -> Variant
54  * 	- GVariantType* -> VariantType
55  * module aliases:
56  * local aliases:
57  * overrides:
58  */
59 
60 module gio.SimpleAction;
61 
62 public  import gtkc.giotypes;
63 
64 private import gtkc.gio;
65 private import glib.ConstructionException;
66 private import gobject.ObjectG;
67 
68 private import gobject.Signals;
69 public  import gtkc.gdktypes;
70 private import glib.Str;
71 private import glib.Variant;
72 private import glib.VariantType;
73 private import gio.ActionIF;
74 private import gio.ActionT;
75 
76 
77 private import gobject.ObjectG;
78 
79 /**
80  * A GSimpleAction is the obvious simple implementation of the GAction
81  * interface. This is the easiest way to create an action for purposes of
82  * adding it to a GSimpleActionGroup.
83  *
84  * See also GtkAction.
85  */
86 public class SimpleAction : ObjectG, ActionIF
87 {
88 	
89 	/** the main Gtk struct */
90 	protected GSimpleAction* gSimpleAction;
91 	
92 	
93 	/** Get the main Gtk struct */
94 	public GSimpleAction* getSimpleActionStruct()
95 	{
96 		return gSimpleAction;
97 	}
98 	
99 	
100 	/** the main Gtk struct as a void* */
101 	protected override void* getStruct()
102 	{
103 		return cast(void*)gSimpleAction;
104 	}
105 	
106 	/**
107 	 * Sets our main struct and passes it to the parent class
108 	 */
109 	public this (GSimpleAction* gSimpleAction)
110 	{
111 		super(cast(GObject*)gSimpleAction);
112 		this.gSimpleAction = gSimpleAction;
113 	}
114 	
115 	protected override void setStruct(GObject* obj)
116 	{
117 		super.setStruct(obj);
118 		gSimpleAction = cast(GSimpleAction*)obj;
119 	}
120 	
121 	// add the Action capabilities
122 	mixin ActionT!(GSimpleAction);
123 	
124 	/**
125 	 */
126 	int[string] connectedSignals;
127 	
128 	void delegate(Variant, SimpleAction)[] onActivateListeners;
129 	/**
130 	 * Indicates that the action was just activated.
131 	 * parameter will always be of the expected type. In the event that
132 	 * an incorrect type was given, no signal will be emitted.
133 	 * Since 2.28
134 	 */
135 	void addOnActivate(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
136 	{
137 		if ( !("activate" in connectedSignals) )
138 		{
139 			Signals.connectData(
140 			getStruct(),
141 			"activate",
142 			cast(GCallback)&callBackActivate,
143 			cast(void*)this,
144 			null,
145 			connectFlags);
146 			connectedSignals["activate"] = 1;
147 		}
148 		onActivateListeners ~= dlg;
149 	}
150 	extern(C) static void callBackActivate(GSimpleAction* simpleStruct, GVariant* parameter, SimpleAction _simpleAction)
151 	{
152 		foreach ( void delegate(Variant, SimpleAction) dlg ; _simpleAction.onActivateListeners )
153 		{
154 			dlg(ObjectG.getDObject!(Variant)(parameter), _simpleAction);
155 		}
156 	}
157 	
158 	void delegate(Variant, SimpleAction)[] onChangeStateListeners;
159 	/**
160 	 * Indicates that the action just received a request to change its
161 	 * state.
162 	 * value will always be of the correct state type. In the event that
163 	 * an incorrect type was given, no signal will be emitted.
164 	 * If no handler is connected to this signal then the default
165 	 * behaviour is to call g_simple_action_set_state() to set the state
166 	 * to the requested value. If you connect a signal handler then no
167 	 * default action is taken. If the state should change then you must
168 	 * call g_simple_action_set_state() from the handler.
169 	 * $(DDOC_COMMENT example)
170 	 *
171 	 * The handler need not set the state to the requested value. It
172 	 * could set it to any value at all, or take some other action.
173 	 * Since 2.30
174 	 */
175 	void addOnChangeState(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
176 	{
177 		if ( !("change-state" in connectedSignals) )
178 		{
179 			Signals.connectData(
180 			getStruct(),
181 			"change-state",
182 			cast(GCallback)&callBackChangeState,
183 			cast(void*)this,
184 			null,
185 			connectFlags);
186 			connectedSignals["change-state"] = 1;
187 		}
188 		onChangeStateListeners ~= dlg;
189 	}
190 	extern(C) static void callBackChangeState(GSimpleAction* simpleStruct, GVariant* value, SimpleAction _simpleAction)
191 	{
192 		foreach ( void delegate(Variant, SimpleAction) dlg ; _simpleAction.onChangeStateListeners )
193 		{
194 			dlg(ObjectG.getDObject!(Variant)(value), _simpleAction);
195 		}
196 	}
197 	
198 	
199 	/**
200 	 * Creates a new action.
201 	 * The created action is stateless. See g_simple_action_new_stateful().
202 	 * Since 2.28
203 	 * Params:
204 	 * name = the name of the action
205 	 * parameterType = the type of parameter to the activate function. [allow-none]
206 	 * Throws: ConstructionException GTK+ fails to create the object.
207 	 */
208 	public this (string name, VariantType parameterType)
209 	{
210 		// GSimpleAction * g_simple_action_new (const gchar *name,  const GVariantType *parameter_type);
211 		auto p = g_simple_action_new(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct());
212 		if(p is null)
213 		{
214 			throw new ConstructionException("null returned by g_simple_action_new(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct())");
215 		}
216 		this(cast(GSimpleAction*) p);
217 	}
218 	
219 	/**
220 	 * Creates a new stateful action.
221 	 * state is the initial state of the action. All future state values
222 	 * must have the same GVariantType as the initial state.
223 	 * If the state GVariant is floating, it is consumed.
224 	 * Since 2.28
225 	 * Params:
226 	 * name = the name of the action
227 	 * parameterType = the type of the parameter to the activate function. [allow-none]
228 	 * state = the initial state of the action
229 	 * Throws: ConstructionException GTK+ fails to create the object.
230 	 */
231 	public this (string name, VariantType parameterType, Variant state)
232 	{
233 		// GSimpleAction * g_simple_action_new_stateful (const gchar *name,  const GVariantType *parameter_type,  GVariant *state);
234 		auto p = g_simple_action_new_stateful(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct(), (state is null) ? null : state.getVariantStruct());
235 		if(p is null)
236 		{
237 			throw new ConstructionException("null returned by g_simple_action_new_stateful(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct(), (state is null) ? null : state.getVariantStruct())");
238 		}
239 		this(cast(GSimpleAction*) p);
240 	}
241 	
242 	/**
243 	 * Sets the action as enabled or not.
244 	 * An action must be enabled in order to be activated or in order to
245 	 * have its state changed from outside callers.
246 	 * This should only be called by the implementor of the action. Users
247 	 * of the action should not attempt to modify its enabled flag.
248 	 * Since 2.28
249 	 * Params:
250 	 * enabled = whether the action is enabled
251 	 */
252 	public void setEnabled(int enabled)
253 	{
254 		// void g_simple_action_set_enabled (GSimpleAction *simple,  gboolean enabled);
255 		g_simple_action_set_enabled(gSimpleAction, enabled);
256 	}
257 	
258 	/**
259 	 * Sets the state of the action.
260 	 * This directly updates the 'state' property to the given value.
261 	 * This should only be called by the implementor of the action. Users
262 	 * of the action should not attempt to directly modify the 'state'
263 	 * property. Instead, they should call g_action_change_state() to
264 	 * request the change.
265 	 * If the value GVariant is floating, it is consumed.
266 	 * Since 2.30
267 	 * Params:
268 	 * value = the new GVariant for the state
269 	 */
270 	public void setState(Variant value)
271 	{
272 		// void g_simple_action_set_state (GSimpleAction *simple,  GVariant *value);
273 		g_simple_action_set_state(gSimpleAction, (value is null) ? null : value.getVariantStruct());
274 	}
275 }