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