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 private import std.algorithm;
36 
37 
38 /**
39  * A `GtkToggleButton` is a button which remains “pressed-in” when
40  * clicked.
41  * 
42  * Clicking again will cause the toggle button to return to its normal state.
43  * 
44  * A toggle button is created by calling either [ctor@Gtk.ToggleButton.new] or
45  * [ctor@Gtk.ToggleButton.new_with_label]. If using the former, it is advisable
46  * to pack a widget, (such as a `GtkLabel` and/or a `GtkImage`), into the toggle
47  * button’s container. (See [class@Gtk.Button] for more information).
48  * 
49  * The state of a `GtkToggleButton` can be set specifically using
50  * [method@Gtk.ToggleButton.set_active], and retrieved using
51  * [method@Gtk.ToggleButton.get_active].
52  * 
53  * To simply switch the state of a toggle button, use
54  * [method@Gtk.ToggleButton.toggled].
55  * 
56  * # Grouping
57  * 
58  * Toggle buttons can be grouped together, to form mutually exclusive
59  * groups - only one of the buttons can be toggled at a time, and toggling
60  * another one will switch the currently toggled one off.
61  * 
62  * To add a `GtkToggleButton` to a group, use [method@Gtk.ToggleButton.set_group].
63  * 
64  * # CSS nodes
65  * 
66  * `GtkToggleButton` has a single CSS node with name button. To differentiate
67  * it from a plain `GtkButton`, it gets the .toggle style class.
68  * 
69  * ## Creating two `GtkToggleButton` widgets.
70  * 
71  * ```c
72  * static void output_state (GtkToggleButton *source, gpointer user_data)
73  * {
74  * printf ("Active: %d\n", gtk_toggle_button_get_active (source));
75  * }
76  * 
77  * void make_toggles (void)
78  * {
79  * GtkWidget *window, *toggle1, *toggle2;
80  * GtkWidget *box;
81  * const char *text;
82  * 
83  * window = gtk_window_new ();
84  * box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
85  * 
86  * text = "Hi, I’m a toggle button.";
87  * toggle1 = gtk_toggle_button_new_with_label (text);
88  * 
89  * g_signal_connect (toggle1, "toggled",
90  * G_CALLBACK (output_state),
91  * NULL);
92  * gtk_box_append (GTK_BOX (box), toggle1);
93  * 
94  * text = "Hi, I’m a toggle button.";
95  * toggle2 = gtk_toggle_button_new_with_label (text);
96  * g_signal_connect (toggle2, "toggled",
97  * G_CALLBACK (output_state),
98  * NULL);
99  * gtk_box_append (GTK_BOX (box), toggle2);
100  * 
101  * gtk_window_set_child (GTK_WINDOW (window), box);
102  * gtk_widget_show (window);
103  * }
104  * ```
105  */
106 public class ToggleButton : Button
107 {
108 	/** the main Gtk struct */
109 	protected GtkToggleButton* gtkToggleButton;
110 
111 	/** Get the main Gtk struct */
112 	public GtkToggleButton* getToggleButtonStruct(bool transferOwnership = false)
113 	{
114 		if (transferOwnership)
115 			ownedRef = false;
116 		return gtkToggleButton;
117 	}
118 
119 	/** the main Gtk struct as a void* */
120 	protected override void* getStruct()
121 	{
122 		return cast(void*)gtkToggleButton;
123 	}
124 
125 	/**
126 	 * Sets our main struct and passes it to the parent class.
127 	 */
128 	public this (GtkToggleButton* gtkToggleButton, bool ownedRef = false)
129 	{
130 		this.gtkToggleButton = gtkToggleButton;
131 		super(cast(GtkButton*)gtkToggleButton, ownedRef);
132 	}
133 
134 
135 	/** */
136 	public static GType getType()
137 	{
138 		return gtk_toggle_button_get_type();
139 	}
140 
141 	/**
142 	 * Creates a new toggle button.
143 	 *
144 	 * A widget should be packed into the button, as in [ctor@Gtk.Button.new].
145 	 *
146 	 * Returns: a new toggle button.
147 	 *
148 	 * Throws: ConstructionException GTK+ fails to create the object.
149 	 */
150 	public this()
151 	{
152 		auto __p = gtk_toggle_button_new();
153 
154 		if(__p is null)
155 		{
156 			throw new ConstructionException("null returned by new");
157 		}
158 
159 		this(cast(GtkToggleButton*) __p);
160 	}
161 
162 	/**
163 	 * Creates a new `GtkToggleButton` containing a label.
164 	 *
165 	 * The label will be created using [ctor@Gtk.Label.new_with_mnemonic],
166 	 * so underscores in @label indicate the mnemonic for the button.
167 	 *
168 	 * Params:
169 	 *     label = the text of the button, with an underscore in front of the
170 	 *         mnemonic character
171 	 *
172 	 * Returns: a new `GtkToggleButton`
173 	 *
174 	 * Throws: ConstructionException GTK+ fails to create the object.
175 	 */
176 	public this(string label)
177 	{
178 		auto __p = gtk_toggle_button_new_with_mnemonic(Str.toStringz(label));
179 
180 		if(__p is null)
181 		{
182 			throw new ConstructionException("null returned by new_with_mnemonic");
183 		}
184 
185 		this(cast(GtkToggleButton*) __p);
186 	}
187 
188 	/**
189 	 * Queries a `GtkToggleButton` and returns its current state.
190 	 *
191 	 * Returns %TRUE if the toggle button is pressed in and %FALSE
192 	 * if it is raised.
193 	 *
194 	 * Returns: whether the button is pressed
195 	 */
196 	public bool getActive()
197 	{
198 		return gtk_toggle_button_get_active(gtkToggleButton) != 0;
199 	}
200 
201 	/**
202 	 * Sets the status of the toggle button.
203 	 *
204 	 * Set to %TRUE if you want the `GtkToggleButton` to be “pressed in”,
205 	 * and %FALSE to raise it.
206 	 *
207 	 * If the status of the button changes, this action causes the
208 	 * [signal@GtkToggleButton::toggled] signal to be emitted.
209 	 *
210 	 * Params:
211 	 *     isActive = %TRUE or %FALSE.
212 	 */
213 	public void setActive(bool isActive)
214 	{
215 		gtk_toggle_button_set_active(gtkToggleButton, isActive);
216 	}
217 
218 	/**
219 	 * Adds @self to the group of @group.
220 	 *
221 	 * In a group of multiple toggle buttons, only one button can be active
222 	 * at a time.
223 	 *
224 	 * Setting up groups in a cycle leads to undefined behavior.
225 	 *
226 	 * Note that the same effect can be achieved via the [interface@Gtk.Actionable]
227 	 * API, by using the same action with parameter type and state type 's'
228 	 * for all buttons in the group, and giving each button its own target
229 	 * value.
230 	 *
231 	 * Params:
232 	 *     group = another `GtkToggleButton` to
233 	 *         form a group with
234 	 */
235 	public void setGroup(ToggleButton group)
236 	{
237 		gtk_toggle_button_set_group(gtkToggleButton, (group is null) ? null : group.getToggleButtonStruct());
238 	}
239 
240 	/**
241 	 * Emits the ::toggled signal on the `GtkToggleButton`.
242 	 *
243 	 * There is no good reason for an application ever to call this function.
244 	 */
245 	public void toggled()
246 	{
247 		gtk_toggle_button_toggled(gtkToggleButton);
248 	}
249 
250 	/**
251 	 * Emitted whenever the `GtkToggleButton`'s state is changed.
252 	 */
253 	gulong addOnToggled(void delegate(ToggleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
254 	{
255 		return Signals.connect(this, "toggled", dlg, connectFlags ^ ConnectFlags.SWAPPED);
256 	}
257 }