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.CheckButton;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import glib.c.functions;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gtk.ActionableIF;
33 private import gtk.ActionableT;
34 private import gtk.Widget;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 private import std.algorithm;
38 
39 
40 /**
41  * A `GtkCheckButton` places a label next to an indicator.
42  * 
43  * ![Example GtkCheckButtons](check-button.png)
44  * 
45  * A `GtkCheckButton` is created by calling either [ctor@Gtk.CheckButton.new]
46  * or [ctor@Gtk.CheckButton.new_with_label].
47  * 
48  * The state of a `GtkCheckButton` can be set specifically using
49  * [method@Gtk.CheckButton.set_active], and retrieved using
50  * [method@Gtk.CheckButton.get_active].
51  * 
52  * # Inconsistent state
53  * 
54  * In addition to "on" and "off", check buttons can be an
55  * "in between" state that is neither on nor off. This can be used
56  * e.g. when the user has selected a range of elements (such as some
57  * text or spreadsheet cells) that are affected by a check button,
58  * and the current values in that range are inconsistent.
59  * 
60  * To set a `GtkCheckButton` to inconsistent state, use
61  * [method@Gtk.CheckButton.set_inconsistent].
62  * 
63  * # Grouping
64  * 
65  * Check buttons can be grouped together, to form mutually exclusive
66  * groups - only one of the buttons can be toggled at a time, and toggling
67  * another one will switch the currently toggled one off.
68  * 
69  * Grouped check buttons use a different indicator, and are commonly referred
70  * to as *radio buttons*.
71  * 
72  * ![Example GtkCheckButtons](radio-button.png)
73  * 
74  * To add a `GtkCheckButton` to a group, use [method@Gtk.CheckButton.set_group].
75  * 
76  * # CSS nodes
77  * 
78  * ```
79  * checkbutton[.text-button]
80  * ├── check
81  * ╰── [label]
82  * ```
83  * 
84  * A `GtkCheckButton` has a main node with name checkbutton. If the
85  * [property@Gtk.CheckButton:label] property is set, it contains a label
86  * child. The indicator node is named check when no group is set, and
87  * radio if the checkbutton is grouped together with other checkbuttons.
88  * 
89  * # Accessibility
90  * 
91  * `GtkCheckButton` uses the %GTK_ACCESSIBLE_ROLE_CHECKBOX role.
92  */
93 public class CheckButton : Widget, ActionableIF
94 {
95 	/** the main Gtk struct */
96 	protected GtkCheckButton* gtkCheckButton;
97 
98 	/** Get the main Gtk struct */
99 	public GtkCheckButton* getCheckButtonStruct(bool transferOwnership = false)
100 	{
101 		if (transferOwnership)
102 			ownedRef = false;
103 		return gtkCheckButton;
104 	}
105 
106 	/** the main Gtk struct as a void* */
107 	protected override void* getStruct()
108 	{
109 		return cast(void*)gtkCheckButton;
110 	}
111 
112 	/**
113 	 * Sets our main struct and passes it to the parent class.
114 	 */
115 	public this (GtkCheckButton* gtkCheckButton, bool ownedRef = false)
116 	{
117 		this.gtkCheckButton = gtkCheckButton;
118 		super(cast(GtkWidget*)gtkCheckButton, ownedRef);
119 	}
120 
121 	// add the Actionable capabilities
122 	mixin ActionableT!(GtkCheckButton);
123 
124 
125 	/** */
126 	public static GType getType()
127 	{
128 		return gtk_check_button_get_type();
129 	}
130 
131 	/**
132 	 * Creates a new `GtkCheckButton`.
133 	 *
134 	 * Returns: a new `GtkCheckButton`
135 	 *
136 	 * Throws: ConstructionException GTK+ fails to create the object.
137 	 */
138 	public this()
139 	{
140 		auto __p = gtk_check_button_new();
141 
142 		if(__p is null)
143 		{
144 			throw new ConstructionException("null returned by new");
145 		}
146 
147 		this(cast(GtkCheckButton*) __p);
148 	}
149 
150 	/**
151 	 * Creates a new `GtkCheckButton` with the given text and a mnemonic.
152 	 *
153 	 * Params:
154 	 *     label = The text of the button, with an underscore
155 	 *         in front of the mnemonic character
156 	 *
157 	 * Returns: a new `GtkCheckButton`
158 	 *
159 	 * Throws: ConstructionException GTK+ fails to create the object.
160 	 */
161 	public this(string label)
162 	{
163 		auto __p = gtk_check_button_new_with_mnemonic(Str.toStringz(label));
164 
165 		if(__p is null)
166 		{
167 			throw new ConstructionException("null returned by new_with_mnemonic");
168 		}
169 
170 		this(cast(GtkCheckButton*) __p);
171 	}
172 
173 	/**
174 	 * Returns whether the check button is active.
175 	 *
176 	 * Returns: whether the check button is active
177 	 */
178 	public bool getActive()
179 	{
180 		return gtk_check_button_get_active(gtkCheckButton) != 0;
181 	}
182 
183 	/**
184 	 * Returns whether the check button is in an inconsistent state.
185 	 *
186 	 * Returns: %TRUE if @check_button is currently in an inconsistent state
187 	 */
188 	public bool getInconsistent()
189 	{
190 		return gtk_check_button_get_inconsistent(gtkCheckButton) != 0;
191 	}
192 
193 	/**
194 	 * Returns the label of the check button.
195 	 *
196 	 * Returns: The label @self shows next
197 	 *     to the indicator. If no label is shown, %NULL will be returned.
198 	 */
199 	public string getLabel()
200 	{
201 		return Str.toString(gtk_check_button_get_label(gtkCheckButton));
202 	}
203 
204 	/**
205 	 * Returns whether underlines in the label indicate mnemonics.
206 	 *
207 	 * Returns: The value of the [property@Gtk.CheckButton:use-underline] property.
208 	 *     See [method@Gtk.CheckButton.set_use_underline] for details on how to set
209 	 *     a new value.
210 	 */
211 	public bool getUseUnderline()
212 	{
213 		return gtk_check_button_get_use_underline(gtkCheckButton) != 0;
214 	}
215 
216 	/**
217 	 * Changes the check buttons active state.
218 	 *
219 	 * Params:
220 	 *     setting = the new value to set
221 	 */
222 	public void setActive(bool setting)
223 	{
224 		gtk_check_button_set_active(gtkCheckButton, setting);
225 	}
226 
227 	/**
228 	 * Adds @self to the group of @group.
229 	 *
230 	 * In a group of multiple check buttons, only one button can be active
231 	 * at a time. The behavior of a checkbutton in a group is also commonly
232 	 * known as a *radio button*.
233 	 *
234 	 * Setting the group of a check button also changes the css name of the
235 	 * indicator widget's CSS node to 'radio'.
236 	 *
237 	 * Setting up groups in a cycle leads to undefined behavior.
238 	 *
239 	 * Note that the same effect can be achieved via the [interface@Gtk.Actionable]
240 	 * API, by using the same action with parameter type and state type 's'
241 	 * for all buttons in the group, and giving each button its own target
242 	 * value.
243 	 *
244 	 * Params:
245 	 *     group = another `GtkCheckButton` to
246 	 *         form a group with
247 	 */
248 	public void setGroup(CheckButton group)
249 	{
250 		gtk_check_button_set_group(gtkCheckButton, (group is null) ? null : group.getCheckButtonStruct());
251 	}
252 
253 	/**
254 	 * Sets the `GtkCheckButton` to inconsistent state.
255 	 *
256 	 * You shoud turn off the inconsistent state again if the user checks
257 	 * the check button. This has to be done manually.
258 	 *
259 	 * Params:
260 	 *     inconsistent = %TRUE if state is inconsistent
261 	 */
262 	public void setInconsistent(bool inconsistent)
263 	{
264 		gtk_check_button_set_inconsistent(gtkCheckButton, inconsistent);
265 	}
266 
267 	/**
268 	 * Sets the text of @self.
269 	 *
270 	 * If [property@Gtk.CheckButton:use-underline] is %TRUE, an underscore
271 	 * in @label is interpreted as mnemonic indicator, see
272 	 * [method@Gtk.CheckButton.set_use_underline] for details on this behavior.
273 	 *
274 	 * Params:
275 	 *     label = The text shown next to the indicator, or %NULL
276 	 *         to show no text
277 	 */
278 	public void setLabel(string label)
279 	{
280 		gtk_check_button_set_label(gtkCheckButton, Str.toStringz(label));
281 	}
282 
283 	/**
284 	 * Sets whether underlines in the label indicate mnemonics.
285 	 *
286 	 * If @setting is %TRUE, an underscore character in @self's label
287 	 * indicates a mnemonic accelerator key. This behavior is similar
288 	 * to [property@Gtk.Label:use-underline].
289 	 *
290 	 * Params:
291 	 *     setting = the new value to set
292 	 */
293 	public void setUseUnderline(bool setting)
294 	{
295 		gtk_check_button_set_use_underline(gtkCheckButton, setting);
296 	}
297 
298 	/**
299 	 * Emitted to when the check button is activated.
300 	 *
301 	 * The `::activate` signal on `GtkCheckButton` is an action signal and
302 	 * emitting it causes the button to animate press then release.
303 	 *
304 	 * Applications should never connect to this signal, but use the
305 	 * [signal@Gtk.CheckButton::toggled] signal.
306 	 *
307 	 * Since: 4.2
308 	 */
309 	gulong addOnActivate(void delegate(CheckButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
310 	{
311 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
312 	}
313 
314 	/**
315 	 * Emitted when the buttons's [property@Gtk.CheckButton:active]
316 	 * property changes.
317 	 */
318 	gulong addOnToggled(void delegate(CheckButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
319 	{
320 		return Signals.connect(this, "toggled", dlg, connectFlags ^ ConnectFlags.SWAPPED);
321 	}
322 }