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