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  * Conversion parameters:
26  * inFile  = GtkToggleButton.html
27  * outPack = gtk
28  * outFile = ToggleButton
29  * strct   = GtkToggleButton
30  * realStrct=
31  * ctorStrct=
32  * clss    = ToggleButton
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_toggle_button_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- gtk_toggle_button_new_with_label
45  * 	- gtk_toggle_button_new_with_mnemonic
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * structWrap:
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module gtk.ToggleButton;
56 
57 public  import gtkc.gtktypes;
58 
59 private import gtkc.gtk;
60 private import glib.ConstructionException;
61 private import gobject.ObjectG;
62 
63 private import gobject.Signals;
64 public  import gtkc.gdktypes;
65 
66 private import glib.Str;
67 
68 
69 
70 private import gtk.Button;
71 
72 /**
73  * A GtkToggleButton is a GtkButton which will remain 'pressed-in' when
74  * clicked. Clicking again will cause the toggle button to return to its
75  * normal state.
76  *
77  * A toggle button is created by calling either gtk_toggle_button_new() or
78  * gtk_toggle_button_new_with_label(). If using the former, it is advisable to
79  * pack a widget, (such as a GtkLabel and/or a GtkImage), into the toggle
80  * button's container. (See GtkButton for more information).
81  *
82  * The state of a GtkToggleButton can be set specifically using
83  * gtk_toggle_button_set_active(), and retrieved using
84  * gtk_toggle_button_get_active().
85  *
86  * To simply switch the state of a toggle button, use gtk_toggle_button_toggled().
87  *
88  * $(DDOC_COMMENT example)
89  */
90 public class ToggleButton : Button
91 {
92 	
93 	/** the main Gtk struct */
94 	protected GtkToggleButton* gtkToggleButton;
95 	
96 	
97 	public GtkToggleButton* getToggleButtonStruct()
98 	{
99 		return gtkToggleButton;
100 	}
101 	
102 	
103 	/** the main Gtk struct as a void* */
104 	protected override void* getStruct()
105 	{
106 		return cast(void*)gtkToggleButton;
107 	}
108 	
109 	/**
110 	 * Sets our main struct and passes it to the parent class
111 	 */
112 	public this (GtkToggleButton* gtkToggleButton)
113 	{
114 		super(cast(GtkButton*)gtkToggleButton);
115 		this.gtkToggleButton = gtkToggleButton;
116 	}
117 	
118 	protected override void setStruct(GObject* obj)
119 	{
120 		super.setStruct(obj);
121 		gtkToggleButton = cast(GtkToggleButton*)obj;
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 	int[string] connectedSignals;
159 	
160 	void delegate(ToggleButton)[] onToggledListeners;
161 	/**
162 	 * Should be connected if you wish to perform an action whenever the
163 	 * GtkToggleButton's state is changed.
164 	 * See Also
165 	 * GtkButton, GtkCheckButton, GtkCheckMenuItem
166 	 */
167 	void addOnToggled(void delegate(ToggleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
168 	{
169 		if ( !("toggled" in connectedSignals) )
170 		{
171 			Signals.connectData(
172 			getStruct(),
173 			"toggled",
174 			cast(GCallback)&callBackToggled,
175 			cast(void*)this,
176 			null,
177 			connectFlags);
178 			connectedSignals["toggled"] = 1;
179 		}
180 		onToggledListeners ~= dlg;
181 	}
182 	extern(C) static void callBackToggled(GtkToggleButton* togglebuttonStruct, ToggleButton _toggleButton)
183 	{
184 		foreach ( void delegate(ToggleButton) dlg ; _toggleButton.onToggledListeners )
185 		{
186 			dlg(_toggleButton);
187 		}
188 	}
189 	
190 	
191 	/**
192 	 * Creates a new toggle button. A widget should be packed into the button, as in gtk_button_new().
193 	 * Throws: ConstructionException GTK+ fails to create the object.
194 	 */
195 	public this ()
196 	{
197 		// GtkWidget * gtk_toggle_button_new (void);
198 		auto p = gtk_toggle_button_new();
199 		if(p is null)
200 		{
201 			throw new ConstructionException("null returned by gtk_toggle_button_new()");
202 		}
203 		this(cast(GtkToggleButton*) p);
204 	}
205 	
206 	/**
207 	 * Sets whether the button is displayed as a separate indicator and label.
208 	 * You can call this function on a checkbutton or a radiobutton with
209 	 * draw_indicator = FALSE to make the button look like a normal button
210 	 * This function only affects instances of classes like GtkCheckButton
211 	 * and GtkRadioButton that derive from GtkToggleButton,
212 	 * not instances of GtkToggleButton itself.
213 	 * Params:
214 	 * drawIndicator = if TRUE, draw the button as a separate indicator
215 	 * and label; if FALSE, draw the button like a normal button
216 	 */
217 	public void setMode(int drawIndicator)
218 	{
219 		// void gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,  gboolean draw_indicator);
220 		gtk_toggle_button_set_mode(gtkToggleButton, drawIndicator);
221 	}
222 	
223 	/**
224 	 * Retrieves whether the button is displayed as a separate indicator
225 	 * and label. See gtk_toggle_button_set_mode().
226 	 * Returns: TRUE if the togglebutton is drawn as a separate indicator and label.
227 	 */
228 	public int getMode()
229 	{
230 		// gboolean gtk_toggle_button_get_mode (GtkToggleButton *toggle_button);
231 		return gtk_toggle_button_get_mode(gtkToggleButton);
232 	}
233 	
234 	/**
235 	 * Emits the "toggled" signal on the
236 	 * GtkToggleButton. There is no good reason for an
237 	 * application ever to call this function.
238 	 */
239 	public void toggled()
240 	{
241 		// void gtk_toggle_button_toggled (GtkToggleButton *toggle_button);
242 		gtk_toggle_button_toggled(gtkToggleButton);
243 	}
244 	
245 	/**
246 	 * Queries a GtkToggleButton and returns its current state. Returns TRUE if
247 	 * the toggle button is pressed in and FALSE if it is raised.
248 	 * Returns: a gboolean value.
249 	 */
250 	public int getActive()
251 	{
252 		// gboolean gtk_toggle_button_get_active (GtkToggleButton *toggle_button);
253 		return gtk_toggle_button_get_active(gtkToggleButton);
254 	}
255 	
256 	/**
257 	 * Sets the status of the toggle button. Set to TRUE if you want the
258 	 * GtkToggleButton to be 'pressed in', and FALSE to raise it.
259 	 * This action causes the "toggled" signal and the
260 	 * "clicked" signal to be emitted.
261 	 * Params:
262 	 * isActive = TRUE or FALSE.
263 	 */
264 	public void setActive(int isActive)
265 	{
266 		// void gtk_toggle_button_set_active (GtkToggleButton *toggle_button,  gboolean is_active);
267 		gtk_toggle_button_set_active(gtkToggleButton, isActive);
268 	}
269 	
270 	/**
271 	 * Gets the value set by gtk_toggle_button_set_inconsistent().
272 	 * Returns: TRUE if the button is displayed as inconsistent, FALSE otherwise
273 	 */
274 	public int getInconsistent()
275 	{
276 		// gboolean gtk_toggle_button_get_inconsistent (GtkToggleButton *toggle_button);
277 		return gtk_toggle_button_get_inconsistent(gtkToggleButton);
278 	}
279 	
280 	/**
281 	 * If the user has selected a range of elements (such as some text or
282 	 * spreadsheet cells) that are affected by a toggle button, and the
283 	 * current values in that range are inconsistent, you may want to
284 	 * display the toggle in an "in between" state. This function turns on
285 	 * "in between" display. Normally you would turn off the inconsistent
286 	 * state again if the user toggles the toggle button. This has to be
287 	 * done manually, gtk_toggle_button_set_inconsistent() only affects
288 	 * visual appearance, it doesn't affect the semantics of the button.
289 	 * Params:
290 	 * setting = TRUE if state is inconsistent
291 	 */
292 	public void setInconsistent(int setting)
293 	{
294 		// void gtk_toggle_button_set_inconsistent (GtkToggleButton *toggle_button,  gboolean setting);
295 		gtk_toggle_button_set_inconsistent(gtkToggleButton, setting);
296 	}
297 }