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.ToggleButton;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.Button;
32 private import gtk.Widget;
33 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * A #GtkToggleButton is a #GtkButton which will remain “pressed-in” when
40  * clicked. Clicking again will cause the toggle button to return to its
41  * normal state.
42  * 
43  * A toggle button is created by calling either gtk_toggle_button_new() or
44  * gtk_toggle_button_new_with_label(). If using the former, it is advisable to
45  * pack a widget, (such as a #GtkLabel and/or a #GtkImage), into the toggle
46  * button’s container. (See #GtkButton for more information).
47  * 
48  * The state of a #GtkToggleButton can be set specifically using
49  * gtk_toggle_button_set_active(), and retrieved using
50  * gtk_toggle_button_get_active().
51  * 
52  * To simply switch the state of a toggle button, use gtk_toggle_button_toggled().
53  * 
54  * ## Creating two #GtkToggleButton widgets.
55  * 
56  * |[<!-- language="C" -->
57  * void make_toggles (void) {
58  * GtkWidget *dialog, *toggle1, *toggle2;
59  * GtkWidget *content_area;
60  * const char *text;
61  * 
62  * dialog = gtk_dialog_new (text);
63  * content_area = gtk_dialog_get_content_area ();
64  * 
65  * text = "Hi, i’m a toggle button.";
66  * toggle1 = gtk_toggle_button_new_with_label (text);
67  * 
68  * // Makes this toggle button invisible
69  * gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle1),
70  * TRUE);
71  * 
72  * g_signal_connect (toggle1, "toggled",
73  * G_CALLBACK (output_state),
74  * NULL);
75  * gtk_box_pack_start (GTK_BOX (content_area),
76  * toggle1, FALSE, FALSE, 2);
77  * 
78  * text = "Hi, i’m a toggle button.";
79  * toggle2 = gtk_toggle_button_new_with_label (text);
80  * gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle2),
81  * FALSE);
82  * g_signal_connect (toggle2, "toggled",
83  * G_CALLBACK (output_state),
84  * NULL);
85  * gtk_box_pack_start (GTK_BOX (content_area),
86  * toggle2, FALSE, FALSE, 2);
87  * 
88  * gtk_widget_show_all (dialog);
89  * }
90  * ]|
91  */
92 public class ToggleButton : Button
93 {
94 	/** the main Gtk struct */
95 	protected GtkToggleButton* gtkToggleButton;
96 
97 	/** Get the main Gtk struct */
98 	public GtkToggleButton* getToggleButtonStruct()
99 	{
100 		return gtkToggleButton;
101 	}
102 
103 	/** the main Gtk struct as a void* */
104 	protected override void* getStruct()
105 	{
106 		return cast(void*)gtkToggleButton;
107 	}
108 
109 	protected override void setStruct(GObject* obj)
110 	{
111 		gtkToggleButton = cast(GtkToggleButton*)obj;
112 		super.setStruct(obj);
113 	}
114 
115 	/**
116 	 * Sets our main struct and passes it to the parent class.
117 	 */
118 	public this (GtkToggleButton* gtkToggleButton, bool ownedRef = false)
119 	{
120 		this.gtkToggleButton = gtkToggleButton;
121 		super(cast(GtkButton*)gtkToggleButton, ownedRef);
122 	}
123 
124 	/**
125 	 * Creates a new toggle button with a text label.
126 	 * Params:
127 	 *  label = a string containing the message to be placed in the toggle button.
128 	 *  mnemonic =  if true the label
129 	 *  will be created using gtk_label_new_with_mnemonic(), so underscores
130 	 *  in label indicate the mnemonic for the button.
131 	 * Throws: ConstructionException GTK+ fails to create the object.
132 	 */
133 	public this (string label, bool mnemonic=true)
134 	{
135 		GtkToggleButton* p;
136 		
137 		if ( mnemonic )
138 		{
139 			// GtkWidget* gtk_toggle_button_new_with_mnemonic  (const gchar *label);
140 			p = cast(GtkToggleButton*)gtk_toggle_button_new_with_mnemonic(Str.toStringz(label));
141 		}
142 		else
143 		{
144 			// GtkWidget* gtk_toggle_button_new_with_label  (const gchar *label);
145 			p = cast(GtkToggleButton*)gtk_toggle_button_new_with_label(Str.toStringz(label));
146 		}
147 		
148 		if(p is null)
149 		{
150 			throw new ConstructionException("null returned by gtk_toggle_button_new_");
151 		}
152 		
153 		this(p);
154 	}
155 
156 	/**
157 	 */
158 
159 	/** */
160 	public static GType getType()
161 	{
162 		return gtk_toggle_button_get_type();
163 	}
164 
165 	/**
166 	 * Creates a new toggle button. A widget should be packed into the button, as in gtk_button_new().
167 	 *
168 	 * Return: a new toggle button.
169 	 *
170 	 * Throws: ConstructionException GTK+ fails to create the object.
171 	 */
172 	public this()
173 	{
174 		auto p = gtk_toggle_button_new();
175 		
176 		if(p is null)
177 		{
178 			throw new ConstructionException("null returned by new");
179 		}
180 		
181 		this(cast(GtkToggleButton*) p);
182 	}
183 
184 	/**
185 	 * Queries a #GtkToggleButton and returns its current state. Returns %TRUE if
186 	 * the toggle button is pressed in and %FALSE if it is raised.
187 	 *
188 	 * Return: a #gboolean value.
189 	 */
190 	public bool getActive()
191 	{
192 		return gtk_toggle_button_get_active(gtkToggleButton) != 0;
193 	}
194 
195 	/**
196 	 * Gets the value set by gtk_toggle_button_set_inconsistent().
197 	 *
198 	 * Return: %TRUE if the button is displayed as inconsistent, %FALSE otherwise
199 	 */
200 	public bool getInconsistent()
201 	{
202 		return gtk_toggle_button_get_inconsistent(gtkToggleButton) != 0;
203 	}
204 
205 	/**
206 	 * Retrieves whether the button is displayed as a separate indicator
207 	 * and label. See gtk_toggle_button_set_mode().
208 	 *
209 	 * Return: %TRUE if the togglebutton is drawn as a separate indicator
210 	 *     and label.
211 	 */
212 	public bool getMode()
213 	{
214 		return gtk_toggle_button_get_mode(gtkToggleButton) != 0;
215 	}
216 
217 	/**
218 	 * Sets the status of the toggle button. Set to %TRUE if you want the
219 	 * GtkToggleButton to be “pressed in”, and %FALSE to raise it.
220 	 * This action causes the #GtkToggleButton::toggled signal and the
221 	 * #GtkButton::clicked signal to be emitted.
222 	 *
223 	 * Params:
224 	 *     isActive = %TRUE or %FALSE.
225 	 */
226 	public void setActive(bool isActive)
227 	{
228 		gtk_toggle_button_set_active(gtkToggleButton, isActive);
229 	}
230 
231 	/**
232 	 * If the user has selected a range of elements (such as some text or
233 	 * spreadsheet cells) that are affected by a toggle button, and the
234 	 * current values in that range are inconsistent, you may want to
235 	 * display the toggle in an “in between” state. This function turns on
236 	 * “in between” display.  Normally you would turn off the inconsistent
237 	 * state again if the user toggles the toggle button. This has to be
238 	 * done manually, gtk_toggle_button_set_inconsistent() only affects
239 	 * visual appearance, it doesn’t affect the semantics of the button.
240 	 *
241 	 * Params:
242 	 *     setting = %TRUE if state is inconsistent
243 	 */
244 	public void setInconsistent(bool setting)
245 	{
246 		gtk_toggle_button_set_inconsistent(gtkToggleButton, setting);
247 	}
248 
249 	/**
250 	 * Sets whether the button is displayed as a separate indicator and label.
251 	 * You can call this function on a checkbutton or a radiobutton with
252 	 * @draw_indicator = %FALSE to make the button look like a normal button
253 	 *
254 	 * This function only affects instances of classes like #GtkCheckButton
255 	 * and #GtkRadioButton that derive from #GtkToggleButton,
256 	 * not instances of #GtkToggleButton itself.
257 	 *
258 	 * Params:
259 	 *     drawIndicator = if %TRUE, draw the button as a separate indicator
260 	 *         and label; if %FALSE, draw the button like a normal button
261 	 */
262 	public void setMode(bool drawIndicator)
263 	{
264 		gtk_toggle_button_set_mode(gtkToggleButton, drawIndicator);
265 	}
266 
267 	/**
268 	 * Emits the #GtkToggleButton::toggled signal on the
269 	 * #GtkToggleButton. There is no good reason for an
270 	 * application ever to call this function.
271 	 */
272 	public void toggled()
273 	{
274 		gtk_toggle_button_toggled(gtkToggleButton);
275 	}
276 
277 	int[string] connectedSignals;
278 
279 	void delegate(ToggleButton)[] onToggledListeners;
280 	/**
281 	 * Should be connected if you wish to perform an action whenever the
282 	 * #GtkToggleButton's state is changed.
283 	 */
284 	void addOnToggled(void delegate(ToggleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
285 	{
286 		if ( "toggled" !in connectedSignals )
287 		{
288 			Signals.connectData(
289 				this,
290 				"toggled",
291 				cast(GCallback)&callBackToggled,
292 				cast(void*)this,
293 				null,
294 				connectFlags);
295 			connectedSignals["toggled"] = 1;
296 		}
297 		onToggledListeners ~= dlg;
298 	}
299 	extern(C) static void callBackToggled(GtkToggleButton* togglebuttonStruct, ToggleButton _togglebutton)
300 	{
301 		foreach ( void delegate(ToggleButton) dlg; _togglebutton.onToggledListeners )
302 		{
303 			dlg(_togglebutton);
304 		}
305 	}
306 }