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