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  * Description
83  * A GSimpleAction is the obvious simple implementation of the GSimpleAction
84  * interface. This is the easiest way to create an action for purposes of
85  * adding it to a GSimpleActionGroup.
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 	
160 	/**
161 	 * Creates a new action.
162 	 * The created action is stateless. See g_simple_action_new_stateful().
163 	 * Since 2.28
164 	 * Params:
165 	 * name = the name of the action
166 	 * parameterType = the type of parameter to the activate function. [allow-none]
167 	 * Throws: ConstructionException GTK+ fails to create the object.
168 	 */
169 	public this (string name, VariantType parameterType)
170 	{
171 		// GSimpleAction * g_simple_action_new (const gchar *name,  const GVariantType *parameter_type);
172 		auto p = g_simple_action_new(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct());
173 		if(p is null)
174 		{
175 			throw new ConstructionException("null returned by g_simple_action_new(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct())");
176 		}
177 		this(cast(GSimpleAction*) p);
178 	}
179 	
180 	/**
181 	 * Creates a new stateful action.
182 	 * state is the initial state of the action. All future state values
183 	 * must have the same GVariantType as the initial state.
184 	 * If the state GVariant is floating, it is consumed.
185 	 * Since 2.28
186 	 * Params:
187 	 * name = the name of the action
188 	 * parameterType = the type of the parameter to the activate function. [allow-none]
189 	 * state = the initial state of the action
190 	 * Throws: ConstructionException GTK+ fails to create the object.
191 	 */
192 	public this (string name, VariantType parameterType, Variant state)
193 	{
194 		// GSimpleAction * g_simple_action_new_stateful (const gchar *name,  const GVariantType *parameter_type,  GVariant *state);
195 		auto p = g_simple_action_new_stateful(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct(), (state is null) ? null : state.getVariantStruct());
196 		if(p is null)
197 		{
198 			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())");
199 		}
200 		this(cast(GSimpleAction*) p);
201 	}
202 	
203 	/**
204 	 * Sets the action as enabled or not.
205 	 * An action must be enabled in order to be activated or in order to
206 	 * have its state changed from outside callers.
207 	 * Since 2.28
208 	 * Params:
209 	 * enabled = whether the action is enabled
210 	 */
211 	public void setEnabled(int enabled)
212 	{
213 		// void g_simple_action_set_enabled (GSimpleAction *simple,  gboolean enabled);
214 		g_simple_action_set_enabled(gSimpleAction, enabled);
215 	}
216 }