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 gtk.Switch;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.ActionableIF;
31 private import gtk.ActionableT;
32 private import gtk.ActivatableIF;
33 private import gtk.ActivatableT;
34 private import gtk.Widget;
35 public  import gtkc.gdktypes;
36 private import gtkc.gtk;
37 public  import gtkc.gtktypes;
38 
39 
40 /**
41  * #GtkSwitch is a widget that has two states: on or off. The user can control
42  * which state should be active by clicking the empty area, or by dragging the
43  * handle.
44  * 
45  * GtkSwitch can also handle situations where the underlying state changes with
46  * a delay. See #GtkSwitch::state-set for details.
47  * 
48  * # CSS nodes
49  * 
50  * |[<!-- language="plain" -->
51  * switch
52  * ╰── slider
53  * ]|
54  * 
55  * GtkSwitch has two css nodes, the main node with the name switch and a subnode
56  * named slider. Neither of them is using any style classes.
57  */
58 public class Switch : Widget, ActionableIF, ActivatableIF
59 {
60 	/** the main Gtk struct */
61 	protected GtkSwitch* gtkSwitch;
62 
63 	/** Get the main Gtk struct */
64 	public GtkSwitch* getSwitchStruct()
65 	{
66 		return gtkSwitch;
67 	}
68 
69 	/** the main Gtk struct as a void* */
70 	protected override void* getStruct()
71 	{
72 		return cast(void*)gtkSwitch;
73 	}
74 
75 	protected override void setStruct(GObject* obj)
76 	{
77 		gtkSwitch = cast(GtkSwitch*)obj;
78 		super.setStruct(obj);
79 	}
80 
81 	/**
82 	 * Sets our main struct and passes it to the parent class.
83 	 */
84 	public this (GtkSwitch* gtkSwitch, bool ownedRef = false)
85 	{
86 		this.gtkSwitch = gtkSwitch;
87 		super(cast(GtkWidget*)gtkSwitch, ownedRef);
88 	}
89 
90 	// add the Actionable capabilities
91 	mixin ActionableT!(GtkSwitch);
92 
93 	// add the Activatable capabilities
94 	mixin ActivatableT!(GtkSwitch);
95 
96 
97 	/** */
98 	public static GType getType()
99 	{
100 		return gtk_switch_get_type();
101 	}
102 
103 	/**
104 	 * Creates a new #GtkSwitch widget.
105 	 *
106 	 * Return: the newly created #GtkSwitch instance
107 	 *
108 	 * Since: 3.0
109 	 *
110 	 * Throws: ConstructionException GTK+ fails to create the object.
111 	 */
112 	public this()
113 	{
114 		auto p = gtk_switch_new();
115 		
116 		if(p is null)
117 		{
118 			throw new ConstructionException("null returned by new");
119 		}
120 		
121 		this(cast(GtkSwitch*) p);
122 	}
123 
124 	/**
125 	 * Gets whether the #GtkSwitch is in its “on” or “off” state.
126 	 *
127 	 * Return: %TRUE if the #GtkSwitch is active, and %FALSE otherwise
128 	 *
129 	 * Since: 3.0
130 	 */
131 	public bool getActive()
132 	{
133 		return gtk_switch_get_active(gtkSwitch) != 0;
134 	}
135 
136 	/**
137 	 * Gets the underlying state of the #GtkSwitch.
138 	 *
139 	 * Return: the underlying state
140 	 *
141 	 * Since: 3.14
142 	 */
143 	public bool getState()
144 	{
145 		return gtk_switch_get_state(gtkSwitch) != 0;
146 	}
147 
148 	/**
149 	 * Changes the state of @sw to the desired one.
150 	 *
151 	 * Params:
152 	 *     isActive = %TRUE if @sw should be active, and %FALSE otherwise
153 	 *
154 	 * Since: 3.0
155 	 */
156 	public void setActive(bool isActive)
157 	{
158 		gtk_switch_set_active(gtkSwitch, isActive);
159 	}
160 
161 	/**
162 	 * Sets the underlying state of the #GtkSwitch.
163 	 *
164 	 * Normally, this is the same as #GtkSwitch:active, unless the switch
165 	 * is set up for delayed state changes. This function is typically
166 	 * called from a #GtkSwitch::state-set signal handler.
167 	 *
168 	 * See #GtkSwitch::state-set for details.
169 	 *
170 	 * Params:
171 	 *     state = the new state
172 	 *
173 	 * Since: 3.14
174 	 */
175 	public void setState(bool state)
176 	{
177 		gtk_switch_set_state(gtkSwitch, state);
178 	}
179 
180 	int[string] connectedSignals;
181 
182 	void delegate(Switch)[] onActivateListeners;
183 	/**
184 	 * The ::activate signal on GtkSwitch is an action signal and
185 	 * emitting it causes the switch to animate.
186 	 * Applications should never connect to this signal, but use the
187 	 * notify::active signal.
188 	 */
189 	void addOnActivate(void delegate(Switch) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
190 	{
191 		if ( "activate" !in connectedSignals )
192 		{
193 			Signals.connectData(
194 				this,
195 				"activate",
196 				cast(GCallback)&callBackActivate,
197 				cast(void*)this,
198 				null,
199 				connectFlags);
200 			connectedSignals["activate"] = 1;
201 		}
202 		onActivateListeners ~= dlg;
203 	}
204 	extern(C) static void callBackActivate(GtkSwitch* switchStruct, Switch _switch)
205 	{
206 		foreach ( void delegate(Switch) dlg; _switch.onActivateListeners )
207 		{
208 			dlg(_switch);
209 		}
210 	}
211 
212 	bool delegate(bool, Switch)[] onStateSetListeners;
213 	/**
214 	 * The ::state-set signal on GtkSwitch is emitted to change the underlying
215 	 * state. It is emitted when the user changes the switch position. The
216 	 * default handler keeps the state in sync with the #GtkSwitch:active
217 	 * property.
218 	 *
219 	 * To implement delayed state change, applications can connect to this signal,
220 	 * initiate the change of the underlying state, and call gtk_switch_set_state()
221 	 * when the underlying state change is complete. The signal handler should
222 	 * return %TRUE to prevent the default handler from running.
223 	 *
224 	 * Visually, the underlying state is represented by the trough color of
225 	 * the switch, while the #GtkSwitch:active property is represented by the
226 	 * position of the switch.
227 	 *
228 	 * Params:
229 	 *     state = the new state of the switch
230 	 *
231 	 * Return: %TRUE to stop the signal emission
232 	 *
233 	 * Since: 3.14
234 	 */
235 	void addOnStateSet(bool delegate(bool, Switch) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
236 	{
237 		if ( "state-set" !in connectedSignals )
238 		{
239 			Signals.connectData(
240 				this,
241 				"state-set",
242 				cast(GCallback)&callBackStateSet,
243 				cast(void*)this,
244 				null,
245 				connectFlags);
246 			connectedSignals["state-set"] = 1;
247 		}
248 		onStateSetListeners ~= dlg;
249 	}
250 	extern(C) static int callBackStateSet(GtkSwitch* switchStruct, bool state, Switch _switch)
251 	{
252 		foreach ( bool delegate(bool, Switch) dlg; _switch.onStateSetListeners )
253 		{
254 			if ( dlg(state, _switch) )
255 			{
256 				return 1;
257 			}
258 		}
259 		
260 		return 0;
261 	}
262 }