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.ToggleAction;
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.Action;
32 public  import gtkc.gdktypes;
33 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 
36 
37 /**
38  * A #GtkToggleAction corresponds roughly to a #GtkCheckMenuItem. It has an
39  * “active” state specifying whether the action has been checked or not.
40  */
41 public class ToggleAction : Action
42 {
43 	/** the main Gtk struct */
44 	protected GtkToggleAction* gtkToggleAction;
45 
46 	/** Get the main Gtk struct */
47 	public GtkToggleAction* getToggleActionStruct()
48 	{
49 		return gtkToggleAction;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected override void* getStruct()
54 	{
55 		return cast(void*)gtkToggleAction;
56 	}
57 
58 	protected override void setStruct(GObject* obj)
59 	{
60 		gtkToggleAction = cast(GtkToggleAction*)obj;
61 		super.setStruct(obj);
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GtkToggleAction* gtkToggleAction, bool ownedRef = false)
68 	{
69 		this.gtkToggleAction = gtkToggleAction;
70 		super(cast(GtkAction*)gtkToggleAction, ownedRef);
71 	}
72 
73 	/**
74 	 * Creates a new ToggleAction object. To add the action to
75 	 * a ActionGroup and set the accelerator for the action,
76 	 * call gtk.ActionGroup.ActionGroup.addActionWithAccel().
77 	 *
78 	 * Since: 2.4
79 	 *
80 	 * Params:
81 	 *     name    = A unique name for the action
82 	 *     label   = The label displayed in menu items and on buttons, or null
83 	 *     tooltip = A tooltip for the action, or null
84 	 *     stockId = The stock icon to display in widgets representing the
85 	 *               action, or null
86 	 * Throws: ConstructionException GTK+ fails to create the object.
87 	 */
88 	public this (string name, string label, string tooltip, StockID stockId)
89 	{
90 		this(name, label, tooltip, cast(string)stockId);
91 	}
92 
93 	/**
94 	 */
95 
96 	/** */
97 	public static GType getType()
98 	{
99 		return gtk_toggle_action_get_type();
100 	}
101 
102 	/**
103 	 * Creates a new #GtkToggleAction object. To add the action to
104 	 * a #GtkActionGroup and set the accelerator for the action,
105 	 * call gtk_action_group_add_action_with_accel().
106 	 *
107 	 * Params:
108 	 *     name = A unique name for the action
109 	 *     label = The label displayed in menu items and on buttons,
110 	 *         or %NULL
111 	 *     tooltip = A tooltip for the action, or %NULL
112 	 *     stockId = The stock icon to display in widgets representing
113 	 *         the action, or %NULL
114 	 *
115 	 * Return: a new #GtkToggleAction
116 	 *
117 	 * Since: 2.4
118 	 *
119 	 * Throws: ConstructionException GTK+ fails to create the object.
120 	 */
121 	public this(string name, string label, string tooltip, string stockId)
122 	{
123 		auto p = gtk_toggle_action_new(Str.toStringz(name), Str.toStringz(label), Str.toStringz(tooltip), Str.toStringz(stockId));
124 		
125 		if(p is null)
126 		{
127 			throw new ConstructionException("null returned by new");
128 		}
129 		
130 		this(cast(GtkToggleAction*) p, true);
131 	}
132 
133 	/**
134 	 * Returns the checked state of the toggle action.
135 	 *
136 	 * Return: the checked state of the toggle action
137 	 *
138 	 * Since: 2.4
139 	 */
140 	public bool getActive()
141 	{
142 		return gtk_toggle_action_get_active(gtkToggleAction) != 0;
143 	}
144 
145 	/**
146 	 * Returns whether the action should have proxies like a radio action.
147 	 *
148 	 * Return: whether the action should have proxies like a radio action.
149 	 *
150 	 * Since: 2.4
151 	 */
152 	public bool getDrawAsRadio()
153 	{
154 		return gtk_toggle_action_get_draw_as_radio(gtkToggleAction) != 0;
155 	}
156 
157 	/**
158 	 * Sets the checked state on the toggle action.
159 	 *
160 	 * Params:
161 	 *     isActive = whether the action should be checked or not
162 	 *
163 	 * Since: 2.4
164 	 */
165 	public void setActive(bool isActive)
166 	{
167 		gtk_toggle_action_set_active(gtkToggleAction, isActive);
168 	}
169 
170 	/**
171 	 * Sets whether the action should have proxies like a radio action.
172 	 *
173 	 * Params:
174 	 *     drawAsRadio = whether the action should have proxies like a radio
175 	 *         action
176 	 *
177 	 * Since: 2.4
178 	 */
179 	public void setDrawAsRadio(bool drawAsRadio)
180 	{
181 		gtk_toggle_action_set_draw_as_radio(gtkToggleAction, drawAsRadio);
182 	}
183 
184 	/**
185 	 * Emits the “toggled” signal on the toggle action.
186 	 *
187 	 * Since: 2.4
188 	 */
189 	public void toggled()
190 	{
191 		gtk_toggle_action_toggled(gtkToggleAction);
192 	}
193 
194 	int[string] connectedSignals;
195 
196 	void delegate(ToggleAction)[] onToggledListeners;
197 	/**
198 	 * Should be connected if you wish to perform an action
199 	 * whenever the #GtkToggleAction state is changed.
200 	 */
201 	void addOnToggled(void delegate(ToggleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
202 	{
203 		if ( "toggled" !in connectedSignals )
204 		{
205 			Signals.connectData(
206 				this,
207 				"toggled",
208 				cast(GCallback)&callBackToggled,
209 				cast(void*)this,
210 				null,
211 				connectFlags);
212 			connectedSignals["toggled"] = 1;
213 		}
214 		onToggledListeners ~= dlg;
215 	}
216 	extern(C) static void callBackToggled(GtkToggleAction* toggleactionStruct, ToggleAction _toggleaction)
217 	{
218 		foreach ( void delegate(ToggleAction) dlg; _toggleaction.onToggledListeners )
219 		{
220 			dlg(_toggleaction);
221 		}
222 	}
223 }